How to Get Matching records from both F1 & F2 in output file1 and Non-Matching Records from F2 in output File 2 using Sort

1k Views Asked by At

Hi I am trying to Find Matching and Un Matching records from 2 file, one file is a Error file with 181 LRECL, second file F2 is valid records file with same 181 LRECL.

Example ERROR File

12345678901
11111111111
11111111111
22222222222

VALID File has

33333333333
11111111111
11111111111
44444444444

I implemented the Left Outer join

//F1       -> ERROR FILE
//F2       -> VALID FILE
//SYSOUT   DD SYSOUT=*                                                       
//SYSIN    DD *                                                       
  JOINKEYS F1=MAIN,FIELDS=(43,11,A)                            
  JOINKEYS F2=LOOKUP,FIELDS=(10,11,A)                               
  JOIN UNPAIRED,F2 ONLY                                                
  SORT FIEDLS=COPY
/*   

           

so using this I was able to get the valid records that were not present in Error file in sysout

SYSOUT:

33333333333
44444444444

but I don't want lose the Match Records from both File and want to Write the Matching Records from Both file in Second Output file.

I tried Implementing

the FULL OUTER Join, but was unable to get the result

//F1 -> Error File
//F2 -> Valid File
//MATCH    DD DSN=MYDATA.URMI.SAMPLE.MATCH,DISP=OLD
//NOMATCH1 DD DSN=MYDATA.URMI.SAMPLE.NOMATCH1,DISP=OLD
//NOMATCH2 DD DSN=MYDATA.URMI.SAMPLE.NOMATCH2,DISP=OLD 
//SYSOUT   DD SYSOUT=*                                                       
//SYSIN    DD *                                                       
  JOINKEYS F1=MAIN,FIELDS=(43,11,A)                            
  JOINKEYS F2=LOOKUP,FIELDS=(10,11,A)                               
  JOIN UNPAIRED,F1,F2                                                 
  REFORMAT FIELDS=(?,F1:1,181,F2:1,181)                                
  OPTION COPY                                                         
  OUTFIL FNAMES=MATCH,INCLUDE=(1,1,CH,EQ,C'B'),BUILD=(1:2,181)                                                
  OUTFIL FNAMES=NOMATCH1,INCLUDE=(1,1,CH,EQ,C'1'),BUILD=(1:2,181) 
  OUTFIL FNAMES=NOMATCH2,INCLUDE=(1,1,CH,EQ,C'2'),BUILD=(1:2,181) 
/*     

         
2

There are 2 best solutions below

1
On BEST ANSWER

According to the above snapshot, you were reformatting 181 bytes of Error file first followed by 181 bytes of VALID file. So, while writing the NOMATCH2 file, you should build as BUILD=(1:183,181) instead of BUILD=(1:2,181). Hope this will solve your problem and please update here if you still not able to overcome the issue.

Regards, Anbu.

0
On

For completeness, I am posting the updated script and the resulting output files:

 JOINKEYS F1=MAIN,FIELDS=(43,11,A)
 JOINKEYS F2=LOOKUP,FIELDS=(10,11,A)
 JOIN UNPAIRED,F1,F2
 REFORMAT FIELDS=(?,F1:1,181,F2:1,181)
 OPTION COPY
 OUTFIL FNAMES=MATCH,INCLUDE=(1,1,CH,EQ,C'B'),BUILD=(1:2,181)
 OUTFIL FNAMES=NOMATCH1,INCLUDE=(1,1,CH,EQ,C'1'),BUILD=(1:2,181)
 OUTFIL FNAMES=NOMATCH2,INCLUDE=(1,1,CH,EQ,C'2'),BUILD=(1:183,181)

The output file MATCH should contain:

11111111111
11111111111
11111111111
11111111111

The output file NOMATCH1 should contain:

12345678901
22222222222

The output file NOMATCH2 should contain:

33333333333
44444444444

This was verified using AHLSORT for Windows v14r3-117-ge2d0a249 but the results should be the same with DFSORT for z/OS.