Summary -
In this topic, we described about the OUTREC lookup and change with detailed example.
OUTREC statement can be used to lookup and change the content in the file while sorting.
Syntax -
OUTREC FIELDS=(Starting position of field1, Length of field1, CHANGE=(v,find,set,...),…)
Name | Description |
---|---|
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.
Syntax -
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 -
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 ********************************
Job:
000100 //Jobcard 000400 //* 000500 //********************************************************************** 000600 //* 000700 //* SORT FOR OUTREC STATEMENT 000800 //* 000900 //********************************************************************** 001100 //STEP01 EXEC PGM=SORT 001300 //SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR 001800 //SORTOUT DD SYSOUT=* 001900 //SYSOUT DD SYSOUT=* 002400 //SYSIN DD * 002411 SORT FIELDS=(1,5,CH,A) 002420 OUTREC FIELDS=(1,29,30,4,CHANGE=(12,C'dept',C'department'), 002430 5X,45,30) 003500 /* ****** **************************** 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 Solution:
- 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.