OUTREC: lookup and change
OUTREC: lookup and change
Summary
OUTREC statement can be used to lookup and change the content in the file while sorting.
Syntax1 -
OUTREC FIELDS=(Starting position of field1, Length of field1,
CHANGE=(v,find,set,...),…)
Starting position of field1 | Specifies field1 starting position in the input file after sorting. |
Length of feild1 | Field1 physical length in input file. |
V | Specifies the length of the output field |
Find | Table consisting pairs of find constants |
Set | Set constants or set fields |
- NOMATCH can be used to change if no match found with any of the constants in the table.
- NOMATCH=(set) to set the output value when an input field value does not match any of the find constants.
Syntax2 -
NOMATCH=(C'string') sets a character string constant.
NOMATCH=(X'string') sets a hexadecimal string constant.
NOMATCH=(q,n) sets an input field value.
Note! If do notspecify NOMATCH=(set), DFSORT terminates with an error message when aninput field value does not match any of the find constants.
Example -
Scenario - Replace the "dept" with "department".
Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
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
******************************** Bottom of Data ********************************
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Job-card
//*
//**********************************************************************
//*
//* SORT FOR OUTREC STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
//SORTOUT DD SYSOUT=*
//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)
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
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
******************************** BOTTOM OF DATA ********************************
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.