OUTREC Lookup and Change
OUTREC Lookup and Change Example
Scenario - Replace the "dept" with "department".
Input File - MATEPK.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00001 student1 dept 560 01012015 00003 student3 dept 520 03032015 00004 student4 dept 540 06022015 00005 student5 dept 500 09202015 00002 student2 dept 510 05182015
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEPKD JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MATEPK.SORT.INPUT01,DISP=SHR
//SORTOUT DD DSN=MATEPK.MERGE.OUTPUT,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,4),RLSE),
// DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,29,30,4,CHANGE=(12,C'dept',C'department'),
5X,45,30)
/*
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00001 student1 department 560 01012015 00002 student2 department 510 05182015 00003 student3 department 520 03032015 00004 student4 department 540 06022015 00005 student5 department 500 09202015
Explaining Example -
- OUTREC FIELDS=(1,29,..) - Copies the first 29 bytes of data from input file to output as it is.
- OUTREC FIELDS=(..,30,4,CHANGE=(12,C'dept',C'department'),..) - The "dept" text starting from 30th byte of length 4 in the input file should replace with "department" of length 12 while writing it to output file.
- OUTREC FIELDS=(..,5X,..) - add 5 spaces from 40th byte.
- OUTREC FIELDS=(..,45,30) - copies the input file data from 45th byte of length 30 as it is to output starts at 45th byte.