Both Bad and Good files have the same record structure and have first 3 bytes as the key. If 4th byte of the Bad file is spaces then it is a corrupted record. I need to replace those corrupted records in the bad file with the corresponding record from the Good file. If it is not corrupted in the input file, then I don't want to replace it. I did this using Easytrieve but I'm trying to see whether I can do this using SYNCSORT (I don't have DFSORT in my shop). please help
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Wed Mar 12, 2003 12:07 am Post subject:
praveen,
The following JCl will give you the desired results.I assumed that both the files are having 80 bytes lrecl and are of FB format. Also I assumed that both the files are unique. A brief explanation of the job. we concatenate both good and bad input files together.Using Inrec we change the 4th byte from space to zero so that we can sum on that byte.
Now using sum fields we sum on the 4th byte. so for all the matching keys it will sum the value in the 4th bytes there by updating the bad file.
Using Outrec we will again change back the 4th byte from 0 to space( this is for non match records.
Code:
//STEP0100 EXEC PGM=SORT
//*
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=YOUR BAD INPUT,
// DISP=SHR
// DD DSN=YOUR GOOD INPUT,
// DISP=SHR
//SORTOUT DD DSN=YOUR UPDATED FILE,
// DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,
// SPACE=(CYL,(X,Y),RLSE)
//SYSIN DD *
OPTION NZDPRINT
INREC FIELDS=(1,3, $ COPY FIRST 3 BYTES
4,1,CHANGE=(1,C' ',C'0'), $ CHANGE ' ' TO 0 FOR SUMMING
NOMATCH=(4,1), $ COPY AS IS IF NOT SPACE
5,75) $ COPY THE REST OF BYTES
SORT FIELDS=(1,3,CH,A) $ SORT ON KEY
SUM FIELDS=(4,1,ZD) $ SUM ON BAD FIELD
OUTREC FIELDS=(1,3, $ COPY THE FIRST 3 BYTES
4,1,CHANGE=(1,C'0',C' '), $ CHANGE 0 TO ' '
NOMATCH=(4,1), $ COPY AS IS IF NOT 0
5,75) $ COPY THE REST OF BYTES
/*
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Wed Mar 12, 2003 9:20 am Post subject:
praveen,
I assumed that you wanted replace only the 4TH byte in the bad file. Please let me know the LRECL,RECFM and fields & position to be replaced/updated in the bad file.
I want to replace the whole record in the bad file with the corresponding good record (matched by the key). If 4th byte of the bad file is spaces then replace that whole record with the good record. If it is not spaces, then leave that record in bad file as is. LRECL = 80, RECFM = FB, first 3 bytes are the key.
Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
Posted: Wed Mar 12, 2003 3:46 pm Post subject:
Praveen,
The following JCL will give you the desired results.A brief explanation of the job.
The first copy operator takes in the BAD file and splitts into 2 different files.we add a seqnum using inrec so that we can retain the order of the records later.
File T1 will have all the records which have a space in the 4th byte.Using outrec.we will pad the bytes 4 thru 81 with binary zeroes so that we can over lay the contents from the good file.we add a constant of '1' to identify the file. We also copy the the bytes 4 thru 80 of input once again as it will useful for any non matching record from the good file.At the end we copy the seqnum.
File T2 will have all the records which does not have an space in the 4th byte.
The Second copy operator takes in the good file and creates file T3 reformating it using outrec with a constant of '2' and pad with binary zeroes to match the lrecl of T1
Now we concatenate files T1 & T3 as CON1 and sum on the binary zeros from position 4 thru 81 and also on the constants in 83rd bytes. so for any matched records the 83rd byte will have a value of 3 and it has contents from the good file.These will be written to file file T4
Any record which does not have a match in the good file will have a value of '1' in the 82nd byte. for these records we write out the records to file T5. This is where copying of 4 thru 80 bytes comes into use as we dont't have a match we copy as is from input.
now we take files T2,T4,T5 and concatenate them together as con2 and sort on the seqnum to retain the original order of the bad file but with updated records.
Code:
//STEP0100 EXEC PGM=SYNCTOOL
//*
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD *
123 AA000
124 BB111
125 CC222
126 CC333
127ECC444
128SCC555
//IN2 DD *
123EAA666
124EBB777
125ECC888
127EDD999
//T1 DD DSN=&T1,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//T2 DD DSN=&T2,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//T3 DD DSN=&T3,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//T4 DD DSN=&T4,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//T5 DD DSN=&T5,DISP=(,PASS),SPACE=(CYL,(X,Y),RLSE)
//CON1 DD DSN=&T1,DISP=OLD,VOL=REF=*.T1
// DD DSN=&T3,DISP=OLD,VOL=REF=*.T3
//CON2 DD DSN=&T2,DISP=OLD,VOL=REF=*.T2
// DD DSN=&T4,DISP=OLD,VOL=REF=*.T4
// DD DSN=&T5,DISP=OLD,VOL=REF=*.T5
//OUT DD SYSOUT=*
//TOOLIN DD *
COPY FROM(IN1) USING(CTL1)
COPY FROM(IN2) USING(CTL2)
SORT FROM(CON1) USING(CTL3)
SORT FROM(CON2) USING(CTL4)
//CTL1CNTL DD *
INREC FIELDS=(1,80, $ TOTAL LRECL
SEQNUM,8,ZD) $ 8 BYTE SEQNUM
OUTFIL FNAMES=T1,
INCLUDE=(4,1,CH,EQ,C' '), $ INCLUDE WHEN 4TH BYTE IS SPACE
OUTREC=(1,3, $ COPY FIRST 3 BYTES
78Z, $ PAD WITH 78 BINARY ZEROES
C'1', $ ADD A CONSTANT '1'
4,77, $ COPY THE CONTENTS 4 THRU 80
81,8) $ SEQNUM
OUTFIL FNAMES=T2,SAVE $ SAVE WHEN 4TH BYTE NOT SPACE
//CTL2CNTL DD *
OUTFIL FNAMES=T3,
OUTREC=(1,80, $ COPY AS IS FROM INPUT
Z,C'2', $ ADD BINARY ZERO AND CONSTANT 2
85Z) $ ADD ANOTHER 85 BINARY ZEROES
//CTL3CNTL DD *
OPTION EQUALS
SORT FIELDS=(1,3,CH,A) $ SORT ON KEY
SUM FIELDS=(04,8,BI, $ SUM ON BINARY ZEROES
12,8,BI, $ SUM ON BINARY ZEROES
20,8,BI, $ SUM ON BINARY ZEROES
28,8,BI, $ SUM ON BINARY ZEROES
36,8,BI, $ SUM ON BINARY ZEROES
44,8,BI, $ SUM ON BINARY ZEROES
52,8,BI, $ SUM ON BINARY ZEROES
60,8,BI, $ SUM ON BINARY ZEROES
68,8,BI, $ SUM ON BINARY ZEROES
76,4,BI, $ SUM ON BINARY ZEROES
80,2,BI, $ SUM ON BINARY ZEROES
82,1,ZD) $ SUM ON CONSTANT
OUTFIL FNAMES=T4,
INCLUDE=(82,1,ZD,EQ,3), $ MATCHED RECORDS
OUTREC=(1,80, $ UPDATED 80 BYTES
160,8) $ SEQNUM
OUTFIL FNAMES=T5,
INCLUDE=(82,1,ZD,EQ,1), $ NON MATCHED RECORDS
OUTREC=(1,3, $ COPY KEY
83,77, $ COPY THE INPUT AS IS
160,8) $ SEQNUM
//CTL4CNTL DD *
SORT FIELDS=(81,8,ZD,A) $ SORT ON SEQNUM
OUTFIL FNAMES=OUT,
OUTREC=(1,80) $ STRIP THE SEQNUM
/*
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum