INREC
The INREC statement is used to reformat input records before they are sorted, merged, or copied. It allows us to rearrange, edit, and add or remove fields from the input records before the data is processed by the sort or merge operation.
Key Features -
- Modify Records Before Sorting - Allows you to reformat records before they are sorted or merged.
- Add Constants - Inserts fixed values or constants into records.
- Change Field Formats - Modifies field types such as converting between character, packed decimal, binary, etc.
- Truncate or Rearrange Fields - Chooses specific portions of the records to keep, move, or discard.
Syntax1 - Rearranging Record
//SYSIN DD *
SORT FIELDS=COPY
INREC FIELDS=(field1_start_pos_in_input_file, field1_length,
field2_start_pos_in_input_file, field2_length, .....)
/*
Syntax2 - Inserting constant
//SYSIN DD *
SORT FIELDS=COPY
INREC FIELDS=(start_pos_in_output_file:lengthC'constant',...)
/*
Examples -
Scenario1 - Rearranging Fields.
INREC FIELDS=(1,10,15,5,25,4)
Copies the first 10 bytes from the input record starting at position 1, copies 5 bytes starting at position 15, copies 4 bytes starting at position 25. The resulting record will contain these fields in the order they are coded.
Scenario2 - Using Constants in INREC
INREC FIELDS=(1,10,20:C'CONSTANT',35,5)
Copies the first 10 bytes from the input record starting at position 1, inserts the constant 'CONSTANT' at position 20 and copies 5 bytes from position 35.