Hi all,
I'm trying to compare INFILE1 with INFILE2 with a field as key. INFILE1 contains only the key field, whereas INFILE2 contains many other fields including the key field. My requirement is to find the first 20 occurrences of the each record of INFILE1 from INFILE2. Following exhibit might help you to understand my requirement.
INFILE1 would read like below:
DD
AA
BB
CC
INFILE2 would read like below:
00198475 AA 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
00198475 AA 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
00198475 DD 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
00198475 AA 88888
999A8853 DD 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
00198475 AA 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA DD 98798
7897SDFA CC 87678
00198475 AA 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
00198475 AA 88888
999A8853 CC 88888
97SF9877 AA 89898
LJL345KLA BB 98798
7897SDFA CC 87678
Expected output:
00198475 AA 88888
97SF9877 AA 89898
00198475 AA 88888
97SF9877 AA 89898
97SF9877 AA 89898
00198475 AA 88888
97SF9877 AA 89898
00198475 AA 88888
97SF9877 AA 89898
00198475 AA 88888
97SF9877 AA 89898
00198475 AA 88888
97SF9877 AA 89898
LJL345KLA BB 98798
LJL345KLA BB 98798
LJL345KLA BB 98798
LJL345KLA BB 98798
LJL345KLA BB 98798
LJL345KLA BB 98798
999A8853 CC 88888
7897SDFA CC 87678
999A8853 CC 88888
7897SDFA CC 87678
999A8853 CC 88888
7897SDFA CC 87678
7897SDFA CC 87678
999A8853 CC 88888
7897SDFA CC 87678
999A8853 CC 88888
7897SDFA CC 87678
999A8853 CC 88888
7897SDFA CC 87678
00198475 DD 88888
999A8853 DD 88888
LJL345KLA DD 98798
The following easytrieve code is used to perform this process.
FILE INFILE1
IN1-STATE-CD 01 02 A
FILE INFILE2
IN2-STATE-CD 10 02 A
FILE OUTFILE
****
JOB INPUT NULL
*
GET INFILE1
DO WHILE NOT EOF INFILE1
GET INFILE2
WS-COUNTER = 1
DO WHILE WS-COUNTER LT 20 AND NOT EOF INFILE2
IF IN2-STATE-CD = IN1-STATE-CD
PUT OUTFILE
WS-COUNTER = WS-COUNTER + 1
END-IF
GET INFILE2
END-DO
GET INFILE1
END-DO
STOP
on executing this program, it fails with error message "*A010 INVALID FILE REFERENCE - INFILE2 ". I could understand that this error is because, while searching for the first record of INFILE1, it couldn't reach the counter value 20 and EOF of INFILE2 is reached. When it tries to search for the first occurrence of second record of INFILE1, it fails with this error message.
Alteratively, I tried to use "IF MATCHED" condition after virtually sorting the input files. But how to fetch only the first 20 matched INFILE2 record for each INFILE1 record?
I would appreciate your help on avoiding this error and get my expected output.
Thanks,
Malathy
Comparing two files
Moderators: DikDude, Moderator Group
IF MATCHED, FIRST-DUP, DUPLICATE, LAST-DUPLICATE
My suggestion is to use IF MATCHED
& use IF DUP FILE2 to get how many record you want from FILE2.
SAMPLE.... CODE.. MIGHT..BE... AS FOLLOWS
& use IF DUP FILE2 to get how many record you want from FILE2.
SAMPLE.... CODE.. MIGHT..BE... AS FOLLOWS
Code: Select all
IF MATCHED FILE1 FILE2
IF DUPLICATE FILE2
COUNT = COUNT + 1
IF COUNT <=20
WRITE RECORD... TO OUTPUT
END-IF
END-IF
IF LAST-DUP FILE2
COUNT = 0
END-IF
END-IF
Natarajan
Chennai
Chennai
Comparing two files <thanks>
It worked and got expected results. Thanks Natarajan for your timely help!
Hope to get more doubts clarified through this website...
Regards,
Malathy K.
Hope to get more doubts clarified through this website...
Regards,
Malathy K.
FREE TUTORIALS
Tutorials
Free tutorials from mainframegurukul
- JCL Tutorial
Covers all important JCL concepts. - Cobol Tutorial
This tutorials covers all Cobol Topics from STRING to COMP-3. - DB2 Tutorial
DB2 Tutorial focuses on DB2 COBOL Programming. - SORT Tutorial
This Tutorial covers all important aspects of DFSORT with examples - CICS Tutorial
This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page