OUTREC Inserting sequence numbers
OUTREC Inserting sequence numbers
OUTREC statement with OVERLAY is used to insert sequence numbers into records. This is useful for numbering records sequentially, either starting from a specific value or using a specific increment.
Syntax1 - Simple sequence number generation
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(...,
starting_pos_in_output_file:SEQNUM,
seqnum_length,seqnum_format,...)
/*
Syntax2 - Sequence number generation with custom increment
//SYSIN DD *
SORT FIELDS=COPY
OUTREC OVERLAY=(...,
starting_pos_in_output_file:SEQNUM,
seqnum_length,seqnum_format,
START=starting_seq_num,
INCR=seqnum_increment_by,
RESTART=(field1_starting_pos,
field1_length),...)
/*
starting_pos_in_output_file | Specifies the position from where the sequence number to start in output file |
SEQNUM | Specifies a keyword to generate the sequence number |
seqnum_length | Specifies the length of the sequence number |
seqnum_format | Specifies the format of the sequence number |
START=starting_seq_num | Specifies the starting sequence number with |
INCR=seqnum_increment_by | Specifies the number that used to increment |
RESTART=(field1_starting_pos,field1_length) | Specifies the field starting position and length on which the sequence number restart |
Examples -
Scenario1 - Inserting sequence numbers with default start and increment.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,20,21:SEQNUM,5,ZD)
/*
Inserts a 5-byte zoned decimal sequence number starting at position 21. The sequence starts from 1 by default and increments by 1.
Scenario2 - Inserting sequence numbers with custom start and increment.
//SYSIN DD *
SORT FIELDS=COPY
OUTREC FIELDS=(1,30,31:SEQNUM,6,ZD,START=1000,INCR=10)
/*
Inserts a 6-byte zoned decimal sequence number starting at position 31. The sequence starts at 1000 and increments by 10 for each record.