Monday, October 22, 2012

Parse and separate strings in records of a flat file

Lets say we have a file with records containing some strings which we care about. Lets assume all these strings of interest follow a pattern in the records such that they are followed by the word 'COPY' and then a space after it. The file would look something like:

12345COPY string1 
111COPY string2
1234COPY string3

Now we want the output file to have all these "string*" values as the records of length 8 characters. For this we can use the Parse command of DFSORT in the following way.


//SP02 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=DAIW.IMG.SRTPARSE.IN,DISP=SHR
//SORTOUT DD DSN=DAIW.IMG.SRTPARSE.OUT,
//             RECFM=FB,
//             LRECL=8,
//             DSORG=PS,
//             AVGREC=U,
//             SPACE=(TRK,(20,10),RLSE),
//             DISP=(NEW,CATLG,DELETE),
//             UNIT=SYSDA
//SYSIN DD *
   OPTION COPY
   INREC PARSE=(%=(ENDAT=C'COPY'),
   =(STARTAFT=BLANKS,FIXLEN=8)),
   BUILD=()
/*

No comments:

Post a Comment

Popular

Featured

Three Months of Chadhei