Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

COBOL : Matching Records 2

Status
Not open for further replies.

objectcodeonly

Programmer
Mar 29, 2003
2
0
0
US

I have two sequential files that I am reading. One is 170 bytes (LRECL) and the other is 38 bytes (LRECL) They are both sorted in part number order.

I want to compare the two and if I find a record that I get a match on part number, I write that out.

Now remember, the matched part number on one file could be at record count number 43 while that part number on the other file could be at record count number 74.

What is the best , most efficient code in COBOL that I should use that will do the job for me ? Is it "EVALUATE" ?

Respond soon. Thanks.

 
If all you need to find is the matching ones, I would just use an IF. If you're looking for 3 options, (file 1 less than file 2, file 2 less than file 1, file 1 = file 2), then I would use an EVALUATE.
 
A lot of the logic depends if there are duplicates in just one file or if there are duplicates in both files or if there are duplicates in no files. If you do not like my post feel free to point out your opinion or my errors.
 
A good tip for this type of problem to deal with when one file ends before the next is, when one of the files ends to set the variable that you're reading the Part Number into to HIGH-VALUES. i.e.

AT END
MOVE HIGH-VALUES TO FILE1-PARTNUM

Then keep going through the files until both variables reach HIGH-VALUES

i.e.

PERFORM SOMESECTION UNTIL
FILE1-PARTNUM = HIGH-VALUES
AND
FILE2-PARTNUM = HIGH-VALUES

For info: HIGH-VALUES is the the largest value in the computers collating sequence so that if FILE1-PARTNUM = HIGH-VALUES then FILE2-PARTNUM will ALWAYS be less than FILE1-PARTNUM.

Hope you find that useful
 
Actually heres a bit of code from a program I've written that does what you want to do. Hope this helps

PERFORM B-LOANNO UNTIL END-OF-MASTFILE AND END-OF-TRANSFILE

........


B-LOANNO SECTION.
IF (IN-MASTLOANNO2 > IN-VALIDLOANNO2) AND
IN-VALIDLOANNO2 NOT = HIGH-VALUES
PERFORM BA-ONLYONTRANS
ELSE
IF (IN-MASTLOANNO2 = IN-VALIDLOANNO2) AND
IN-MASTLOANNO2 NOT = HIGH-VALUES
PERFORM BB-ONBOTH
ELSE
IF IN-MASTLOANNO2 NOT = HIGH-VALUES
PERFORM BC-ONLYONMASTER
END-IF
END-IF
PERFORM BD-OVERDUECHECK
PERFORM X-READMASTER.
 
Hi , Following logic should address your problem.

1) Sort the files

2) Read both the files sequentially at end move HIGH-VALUE to the corresponding key. You should handle EOF condition for both of the files because I beleive you want to go through the other file even if one file has reached the end condition.

3) Compare the keys
If file1 < file2
read file1
else if file1 > file2
read file2
else
write the record and read file1 & file2

Loop (3) until both the keys are equal to HIGH-VALUES.

Hope this helps,
Selva.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top