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=()
/*

Saturday, October 20, 2012

Using JOINKEYS of DFSORT for matching and merging datasets

Joinkeys applications of DFSORT is a very useful application to match and merge files. The below example joins two input datasets based on a key. The two datasets may have the keys in different data formats, so we can use various data conversion techniques of SORT using INREC in the JNF*CNTL files. Matched records, Records which are only present in dataset 1 and records which are present only in dataset 2 can be segregated using this technique.


//JS010 EXEC PGM=SORT

//SYSOUT DD SYSOUT=*

//IN1 DD DSN=ATOM.INPUT.DATASET1,DISP=SHR

//IN2 DD DSN=ATOM.INPUT.DATASET2,DISP=SHR

//SYMNAMES DD *
   IN1_CUST_ZD,3,6,ZD
   
   IN2_CUST_PD,6,4,PD
   
   IN2_CUST_ZD,=,6,ZD

//JNF1CNTL DD *
   INREC OVERLAY=(IN1_CUST_ZD:IN1_CUST_ZD,TO=ZDF,LENGTH=6)

//JNF2CNTL DD *
   INREC OVERLAY=(IN2_CUST_PD:IN2_CUST_PD,TO=ZDF,LENGTH=6)

//OUT1   DD SYSOUT=*

//OUT2   DD SYSOUT=*

//OUT12  DD DSN=ATOM.OUTPUT.DATASET.MATCHED,

//             RECFM=FB,

//             LRECL=13,

//             DSORG=PS,

//             AVGREC=U,

//             SPACE=(TRK,(800,100),RLSE),

//             DISP=(NEW,CATLG,KEEP),

//             UNIT=SYSDA

//SYSIN  DD *
   JOINKEYS F1=IN1,FIELDS=(IN1_CUST_ZD,A)

   JOINKEYS F2=IN2,FIELDS=(IN2_CUST_ZD,A)

   JOIN UNPAIRED,F1,F2

   REFORMAT FIELDS=(F1:1,8,F2:1,256,?)

   OPTION COPY

   OUTFIL FNAMES=OUT12,INCLUDE=(265,1,CH,EQ,C'B'),

   BUILD=(1:1,8,9:21,3,PD,TO=ZDF,LENGTH=5)

   OUTFIL FNAMES=OUT1,INCLUDE=(265,1,CH,EQ,C'1'),
 
   BUILD=(1,8)

   OUTFIL FNAMES=OUT2,INCLUDE=(265,1,CH,EQ,C'2'),

   BUILD=(9,256)
/*

Popular

Featured

Three Months of Chadhei