OUTREC Reformatting records with OVERLAY


The OUTREC statement with the OVERLAY parameter is used to modify or reformat specific portions of records by inserting or updating data at designated positions.

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.

Examples -


Scenario1 - Overlaying with a constant value.

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

Inserts the constant 'NEWVAL' starting at position 30, replacing any existing data at that position.

Scenario2 - Modifying a Numeric Field with arithmetic operations.

//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 writes the result to position 20 in the output record.

Scenario3 - Overlaying multiple fields.

//SYSIN   DD  *
  SORT FIELDS=COPY
  OUTREC OVERLAY=(10:C'NEW',30:15,5,ZD,MUL,+2)
/*

Inserts the constant 'NEW' starting at position 10. Multiplies the 5-byte zoned decimal field starting at position 15 by 2 and writes the result to position 30.