OUTREC Lookup and Change
OUTREC Lookup and Change
The OUTREC statement is used with the LOOKUP functionality to look up values in a table and replace them in the output records. This is often used for translating or changing values based on a predefined mapping.
Syntax1 -
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(...,
starting_pos_of_field1,
length_of_field1,
CHANGE=(length_of_replcing_string,
string_to_find,
string_to_replace,...),...)
/*
starting_pos_of_field1 | Specifies field1 starting position in the input file after sorting. |
length_of_field1 | Specifies field1 length in input file. |
length_of_replcing_string | Specifies the length of the output field |
string_to_find | Specifies the string to be replaced |
string_to_replace | Specifies the new string |
Examples -
Scenario1 - Find specific string and replace with new string.
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,29,30,4,CHANGE=(12,C'dept',C'department'),
5X,45,30)
/*
Searches for 'dept' string and replaces with 'department'.
Scenario2 - Find specific string and empty it.
//SYSIN DD *
SORT FIELDS=(1,5,CH,A)
OUTREC FIELDS=(1,29,30,4,CHANGE=(12,C'dept',C' '),
5X,45,30)
/*
Searches for 'dept' string and replaces with spaces.