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

你说的曾经没有我的故事 提交于 2019-12-24 10:35:29

问题


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.


回答1:


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




回答2:


enter code here
//JOIN EXEC PGM=SORT 
//SORTJNF1 DD * 
1234567890 FILEB 
1234678901 FILE1 
/* 
//SORTJNF2 DD * 
1234567890 FILEB 
1234789012 FILE2 
/* 
//JNF1CNTL DD DUMMY             <=== not necessary(informatory)
//JNF2CNTL DD DUMMY             <=== not necessary(informatory)
//BOTH     DD DSN=<FILENAME>
//FILE1 DD DSN=<file name> 
//FILE2 DD DSN=<file name>
//SYSOUT DD SYSOUT=* 
//SYSPRINT DD SYSOUT=* 
//SORTOUT DD SYSOUT=*           <=== we can see the JOIN output here(explanatory)
//SYSIN DD * 
 JOINKEYS FILE=F1,FIELDS=(1,10,A) 
 JOINKEYS FILE=F2,FIELDS=(1,10,A) 
 JOIN UNPAIRED,F1,F2 
 REFORMAT FIELDS=(F1:1,16,F2:1,16),FILL=C'@' 
 OPTION COPY 
 OUTFIL FNAMES=BOTH, 
 INCLUDE=(01,01,CH,NE,C'@',AND,17,01,CH,NE,C'@'),BUILD=(1,16)
 OUTFIL FNAMES=FILE1,
 INCLUDE=(01,01,CH,NE,C'@',AND,17,01,CH,EQ,C'@'),BUILD=(1,16)
 OUTFIL FNAMES=FILE2,
 INCLUDE=(01,01,CH,EQ,C'@',AND,17,01,CH,NE,C'@'),BUILD=(17,16)
 /*  

 //***** this REFORMAT output would be something like
 1234567890 FILEB1234567890 FILEB 
 1234678901 FILE1@@@@@@@@@@@@@@@@
 @@@@@@@@@@@@@@@@1234789012 FILE2  
 //*********************************

FILL=C'@' pads the charecter '@' to the record produced by JOIN operation, so that this padded charecter can be used later at the time of Filter using INCLUDE



来源:https://stackoverflow.com/questions/7656172/how-to-get-the-matching-and-non-matching-records-from-two-input-files-in-one-ste

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!