OUTREC Extending records with OVERLAY


The OUTREC statement with the OVERLAY parameter is used to extend or modify specific portions of records. The OVERLAY operation allows us to insert, update, or replace data in fields of a record without changing the entire record structure.

Syntax -

//SYSIN   DD  *
  OPTION COPY
  OUTREC OVERLAY=(starting_pos_of_field1_in_output_file:
		starting_pos_of_field1_in_input_file,
		,length_of_field1[,overlay_operation],…)
/*
starting_pos_of_field1_in_output_fileSpecifies field1 starting position in the output file.
starting_pos_of_field1_in_input_fileSpecifies field1 starting position in the input file.
length_of_field1Specifies field1 physical length in input file.
overlay_operationSpecifies the overlay operation or data conversion operation. Optional.
Note! All the reformatting features can be used with the OVERLAY parameter of the INREC, OUTFIL, and OUTREC statements.

Examples -


Scenario1 - Overlaying with a constant value.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC OVERLAY=(30:C'HELLO')
/*

Inserts the constant string 'HELLO' starting at position 30 in each record of the output dataset. The original data in that position is replaced by 'HELLO'.

Scenario2 - Modifying an existing numeric field.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC OVERLAY=(20:11,5,ZD,ADD,+100)
/*

Adds 100 to the 5-byte zoned decimal field starting at position 11 and updates the result at position 20 in the output record.

Scenario3 - Extending a record by adding a new field.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC OVERLAY=(81:C'HELLO')
/*

Extends the record by adding the constant 'HELLO' starting at position 81, effectively increasing the length of each record by the length of the inserted field.