Page 1 of 1

passing similar records of two files into third file.

PostPosted: Sun Oct 21, 2012 4:24 pm
by VIJAY1
I am a beginner in mainframes.I have started learning just a month back.I was asked to compare two files and pass the similar records into the third file.
I have sorted the files using jcl. The records in my file contain a single field. The field contains numbers.
HERE FILE-STAT11 AND FILE-STAT2 ARE FILE STATUS DATANAMES.
NUM1 ,NUM2,NUM3 ARE THE

PARA2.
 PERFORM UNTILL FILE-STAT1 NOT =10 OR FILE-STAT2 NOT=10
IF NUM1=NUM2
MOVE NUM1 TO NUM3
WRITE NUM3
END IF.
IF NUM1>NUM2
PERFORM UNTIL FILE-STAT2 NOT = 10
READ FILE2
IF NUM1 = NUM2
WRITE NUM3 FROM NUM1
GOTO PARA2
END IF.
END PERFORM
END IF
IF NUM1<NUM2
PERFORM UNTIL FILE-STAT1 NOT =10
READ FILE1
IF NUM1 = NUM2
WRITE NUM3 FROM NUM1
GOTO PARA2
END IF.
END PERFORM.
END IF.
END PERFORM.

Re: passing similar records of two files into third file.

PostPosted: Sun Oct 21, 2012 4:43 pm
by NicC
Welcome to the forum. There are a number of points to raise about your posts:
1) why the duplicate (which has been deleted)?
2) You did not sort the files using JCL. You used a sort program. Admittedly tou used to JCL to get the mainframe to execute the sort but you use JCL to execute any program
3) Please post your code and use the code tags. Your code has been coded for you this time. If you do not know how to use the code tags then search the forum for 'code tags'.
4) So what? - you have not actually asked a question and we do not do proof-reading - the compiler can do that much quicker.
5) at the top of the COBOL forum is a sticky on doing a 2 file match which is what you are doing.
6) Is this required to be done in COBOL or by any means? Your sort product can do this for you. Search the sort manuals and forum for JOINKEYS.

Re: passing similar records of two files into third file.

PostPosted: Sun Oct 21, 2012 4:51 pm
by VIJAY1
Thank you Nic.
The query has been posted before completion due to some problem with my internet connection.
Thanks for the suggestion anyway.

Re: passing similar records of two files into third file.

PostPosted: Sun Oct 21, 2012 9:22 pm
by dick scherrer
Hello and welcome to the forum,

Suggest you download and review the "sticky" that Nic mentioned. It has been thoroughy tested and does what you want to do. The posted code will not.

Thank you for using the code tags (unless someone else later did this). However; it you intend to work with COBOL you need to learn to properly indent your code. The style you used is not maintainable / promotable.

Re: passing similar records of two files into third file.

PostPosted: Sun Oct 21, 2012 9:37 pm
by VIJAY1
Thanks Dick.Its been just a week ,I started working on cobol. Looking forward to learning more from the forum..

Re: passing similar records of two files into third file.

PostPosted: Mon Oct 22, 2012 4:32 am
by BillyBoyo
PARA2.
 PERFORM UNTILL FILE-STAT1 NOT =10 OR FILE-STAT2 NOT=10
  IF NUM1=NUM2
    MOVE NUM1 TO NUM3
    WRITE NUM3
  END IF.
  IF NUM1>NUM2
    PERFORM UNTIL FILE-STAT2 NOT = 10
      READ FILE2
      IF NUM1 = NUM2
        WRITE NUM3 FROM NUM1
        GOTO PARA2
      END IF.
    END PERFORM
  END IF
  IF NUM1<NUM2
    PERFORM UNTIL FILE-STAT1 NOT =10
      READ FILE1
      IF NUM1 = NUM2
        WRITE NUM3 FROM NUM1
        GOTO PARA2
      END IF.
    END PERFORM.
  END IF.
END PERFORM.


I have attempted to "indent" you code.

There are many things wrong. This code will not compile. There are also mistakes which will not cause compile errors but which would make you program probably not work and certainly be difficult to understand.

When posting code here, we need to see the actual code you have attempted, unless you tell us it is "pseudo code".

You are missing hyphens in all your "end" constructs. Your fist UNTILL is not spelled correctly.

You are using full-stops/periods after your "end" constructs. It is best to leave them off.

You are using GO TO to leave your inline PERFORMs to restart from the top. This is a bad idea. If the code just naturally reaches the END-PERFORM, it will start at the top again all on its own with no extra code from you.

Study the program in the "sticky". As your mentor/trainer for some simple working programs to look at, to get an idea how code is used. Spend time thinking and writing out how you think something will work. Then go through it, on the paper, with test data. Have some columns for "variables" and note down the new values they have as you "go through" the code.

If you work out how to get the "simple" things going. then you'll have a technique to apply to more complex things. At some point, you won't need to write it out on paper, but you'll have trained yourself to "think" how it is working. You'll "think" as you are writing the code. You'll think "what will this loop do with the minimum value it can have? What will it do with the maxiumum value? What will it do with an "invalid" value?" and you'll code for all of those (even go back to the spec-writer, if they haven't covered something).

We can't train you here, but there is a lot of material for you to look at, and if you get stuck with something there'll be someone around.