INREC Rearranging Data (Fields)


The INREC statement is used to rearrange data before records are sorting, merging, or copying. Rearranging data refers to modifying the structure of each record by selecting, reordering, or changing certain fields within the record.

Purpose -

  • Rearrange fields by selecting portions of the record and placing them in a new order.
  • Truncate records by including only specific fields.
  • Expand records by adding constants or inserting new fields.

Syntax -

//SYSIN DD * 
    SORT FIELDS=COPY
    INREC FIELDS=(field1_start_pos_in_input_file, field1_length, 
	     field2_start_pos_in_input_file, field2_length, .....)
/*
field1_starting_positionSpecifies the starting position of field1 to be compared
field1_lengthSpecifies the length of the field1 to be compared
field2_starting_positionSpecifies the starting position of field2 to be compared
field2_lengthSpecifies the length of the field2 to be compared

Examples -


Scenario1 - Rearranging Fields.

INREC FIELDS=(1,5,20,10,40,8)

Taking the first 5 bytes starting from position 1 of the input record, 10 bytes starting from position 20, and 8 bytes starting from position 40. The resulting output record will consist of these fields in the order specified, with the first 5 bytes from the input record followed by 10 bytes from position 20, and finally 8 bytes from position 40.

Scenario2 - Inserting Constants While Rearranging.

INREC FIELDS=(1,10,20:C'HELLO123',35,5)

The first 10 bytes from the input record are retained, the constant 'HELLO123' is inserted at position 20, and next 5 bytes are copied from position 35 of the input record.