Syncsort - Write UNPAIRED records to SORTOUT file, and PAIRED records to PAIRED file

1.4k views Asked by At

I'm able to save the UNPAIRED records to SORTOUT (this is what I want) using the following:

//SORT     EXEC PGM=SORT,PARM='DYNALLOC=(SYSDA,255)'
//SORTMSGS DD SYSOUT=*
//SORTJNF1 DD DSN=FILE1,
//            DISP=OLD,DCB=BUFNO=255
//SORTJNF2 DD DSN=FILE2,
//            DISP=OLD,DCB=BUFNO=255
//SORTOUT  DD DSN=FILEOUT,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=(SYSDA,59),
//            SPACE=(CYL,(500,100),RLSE)
//SYSIN    DD *
SORT FIELDS=COPY
JOINKEYS FILE=F1,FIELDS=(25,4,A,115,20,A,135,4,A,140,4,A,5,20,A)
JOINKEYS FILE=F2,FIELDS=(5,4,A,9,20,A,29,4,A,33,4,A,37,20,A)
JOIN UNPAIRED,F2,ONLY

but I need to save the PAIRED records to a separate file. I tried the following statement but the PAIRED records don't get saved in my PAIRED file:

//SORT     EXEC PGM=SORT,PARM='DYNALLOC=(SYSDA,255)'
//SORTMSGS DD SYSOUT=*
//SORTJNF1 DD DSN=FILE.F1,
//            DISP=OLD,DCB=BUFNO=255
//SORTJNF2 DD DSN=FILE.F2,
//            DISP=OLD,DCB=BUFNO=255
//SORTOUT  DD DSN=FILE.SORTOUT,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=(SYSDA,59),
//            SPACE=(CYL,(500,100),RLSE)
//PAIRED   DD DSN=FILE.PAIRED,
//            DISP=(NEW,CATLG,DELETE),
//            UNIT=(SYSDA,59),
//            SPACE=(CYL,(500,100),RLSE)
//SYSIN    DD *
SORT FIELDS=COPY
JOINKEYS FILE=F1,FIELDS=(25,4,A,115,20,A,135,4,A,140,4,A,5,20,A)
JOINKEYS FILE=F2,FIELDS=(5,4,A,9,20,A,29,4,A,33,4,A,37,20,A)
JOIN UNPAIRED,F2,ONLY
OUTFIL FNAMES=SORTOUT
OUTFIL FNAMES=PAIRED,SAVE
1

There are 1 answers

2
Srinivasan JV On BEST ANSWER

Edit 1: OP has mentioned (in the comments section of this answer), "I only want to keep the UNPAIRED records (F2 only) in my main SORTOUT dataset, and the PAIRED records (F2 only) in my PAIRED dataset." Paired records mean both F1 & F2. OP is basically looking for RIGHT JOIN. The SORT statements provided below are edited as per OP's requirement. Note that a REFORMAT statement is required unless a JOIN statement with the ONLY operand is specified.

You must use a method in Syncsort (which is called as indicator method in dfsort), to acheive what you're expecting. See below SORT statements.

SORT FIELDS=COPY
JOINKEYS FILE=F1,FIELDS=(25,4,A,115,20,A,135,4,A,140,4,A,5,20,A)
JOINKEYS FILE=F2,FIELDS=(5,4,A,9,20,A,29,4,A,33,4,A,37,20,A)
REFORMAT FIELDS=(F1:p,l,F2:p,l,?)
JOIN UNPAIRED,F2
OUTFIL FNAMES=BOTH,INCLUDE=(53,1,CH,EQ,C'B'),BUILD=(Build the columns you need from F1/F2)                          
OUTFIL FNAMES=UNPAIRED,INCLUDE=(53,1,CH,EQ,C'2'),BUILD=(Build the columns you need from F2)

where,

p - The position value indicates the first byte of the field relative to the beginning of the input record.

l - The length value indicates the length of the field.

Observe the ? in the REFORMAT FIELDS statement.

Quote from Syncsort for z/OS Programmer's guide:

?

This symbol is used to place a one-byte indicator in the reformatted record that indicates whether the reformatted record is a paired or an unpaired joined record. The indicator will be set to one of three different printable values:

“B” if the reformatted record is a paired record

“1” if the reformatted record is an unpaired record created from the F1 file

“2” if the reformatted record is an unpaired record created from the F2 file

More details:

Hope this helps!