Comparing two files

Ask/Clarify the questions on EASYTRIEVE

Moderators: DikDude, Moderator Group

Post Reply
Sukamm
Member
Posts: 2
Joined: Wed Sep 02, 2009 4:41 pm

Comparing two files

Post by Sukamm » Wed Sep 02, 2009 5:33 pm

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

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

IF MATCHED, FIRST-DUP, DUPLICATE, LAST-DUPLICATE

Post by Natarajan » Thu Sep 03, 2009 2:20 pm

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

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

Sukamm
Member
Posts: 2
Joined: Wed Sep 02, 2009 4:41 pm

Comparing two files <thanks>

Post by Sukamm » Fri Sep 04, 2009 5:12 pm

It worked and got expected results. Thanks Natarajan for your timely help!

Hope to get more doubts clarified through this website...

Regards,
Malathy K.

Post Reply

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



Other References
Mainframe Tools and others