Page 1 of 1

SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Wed Mar 24, 2010 5:21 am
by RonaldCDcosta
Hi,
I need to compare 2 files mentioned below and create 3rd file with dataset information same as file1.
File 1: length 266, field to compare with file 2 = 13:5
File 2: length 675, field to compare with file 1 = 16:5

Once match is found, copy data from file 2, position (60:7) and paste to corresponding record in file 1 at position 328:7. rest all fields same as file 1.
For unmatched records, copy entire data as it is.

The challenge here is, file 1 is unsorted and we want output also in unsorted format. i.e ,out file must be similar to file 1. Only for matching records, the corresponding value must be copied from file2.

Can this be done using SORT or we will need COBOL program?

Re: SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Wed Mar 24, 2010 9:12 pm
by Alissa Margulies
Try the following SyncSort for z/OS job:
//STEP1 EXEC PGM=SORT                     
//SORTIN  DD DSN=FILE1                     (FB/266)                     
//SORTOUT DD DSN=&&TEMP,DISP=(NEW,PASS)    (FB/274)
//SYSOUT  DD SYSOUT=*                     
//SYSIN   DD *                           
  SORT FIELDS=COPY                       
  OUTREC BUILD=(1,266,267:SEQNUM,8,ZD)     
//STEP2  EXEC PGM=SORT                   
//SORTJNF1 DD DSN=&&TEMP,DISP=(OLD,DELETE) (FB/274)
//SORTJNF2 DD DSN=FILE2                    (FB/675)                                                 
//SORTOUT  DD SYSOUT=*                   
//SYSOUT   DD SYSOUT=*                   
//SYSIN    DD    *                       
  JOINKEYS FILES=F1,FIELDS=(13,5,A)       
  JOINKEYS FILES=F2,FIELDS=(16,5,A) 
  JOIN UNPAIRED,F1     
  REFORMAT FIELDS=(F1:1,274,F2:328,7)               
  SORT FIELDS=(267,8,CH,A)                 
  OUTREC IFTHEN=(WHEN=(275,1,CH,EQ,C' '),BUILD=(1,266)),
         IFTHEN=(WHEN=(275,1,CH,NE,C' '),BUILD=(1,59,275,7,67,200))
/*         

Re: SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Wed Mar 24, 2010 10:07 pm
by lal
Slight correction to STEP2. The JOIN statment has to be added to get the required results.
JOIN UNPAIRED,F1


Thanks,
lal

Re: SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Wed Mar 24, 2010 10:31 pm
by Alissa Margulies
You are correct - COPY and PASTE error. Thank you for catching that. I'll update the previous post to reflect the correction.

Re: SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Fri Mar 26, 2010 7:45 am
by RonaldCDcosta
Spool message:
JOINKEYS REFORMAT RECORD LENGTH= 281, TYPE = F
OUTREC RECORD LENGTH = 281
SORTOUT : RECFM=FB ; LRECL= 266; BLKSIZE= 27930
SORTOUT HAS INCOMPATIBLE LRECL


Looks like this sort creates file of reclength 281. Whereas the file needs to be of 266. How to handle this?

Re: SYNSORT compare 2 files & copy retaining the sequence

PostPosted: Fri Mar 26, 2010 9:30 pm
by Alissa Margulies
Try replacing the OUTREC statement in the second sort step with this and let me know what your results are:

 OUTREC IFTHEN=(WHEN=(275,1,CH,EQ,C' '),BUILD=(1,266)),
       IFTHEN=(WHEN=NONE,BUILD=(1,59,275,7,67,200))