Search code examples
mainframejcl

How to get the Matching and Non-matching records from two input files in one step using SYNCSORT?


I have a requirement like below.

-> I have 2 input files FILE1 and FILE2.

-> Write the matching records into a FILE3.

-> Write the Non matching records from FILE1 into FILE4.

-> Write the Non matching records from FILE2 into FILE5.

The key position in both the Input Files is (1,10).

Can anybody please let me know the SORTCARD, how Can I get this in single step in SyncSort??

Thanks in Advance, Rajasekhar Jannu.


Solution

  • JOINKEYS FILE=F1,FIELDS=(01,10,A)
    JOINKEYS FILE=F2,FIELDS=(01,10,A)
    UNPAIRED F1,F2   <== This results in cartesian product
    REFORM FIELDS=(F1:01,10,F2:01,10),FILL=C'$'
    SORT FIELDS=(01,10,CH,A)
    OUTFIL FNAMES=03,
    INCLUDE=(01,01,CH,NE,C'$',AND,11,01,CH,NE,C'$')  <== Matched Records
    OUTFIL FNAMES=04,
    INCLUDE=(01,01,CH,NE,C'$',AND,11,01,CH,EQ,C'$')  <== Non-Matched Records from File1
    OUTFIL FNAMES=03,
    INCLUDE=(01,01,CH,EQ,C'$',AND,11,01,CH,NE,C'$')  <== Non-Matched Records from File2
    

    Also, note that only 10bytes have been considered from both the files as you didnt mention the lengths of each file.

    Also suggest you to search known mainframe forums and post it here if you dont get the working solution. Hope this helps

    Refer this: Joinkeys Guide