OUTREC: Inserting sequence numbers
OUTREC: Inserting sequence numbers
Summary
OUTREC statement can be used to add the sequence number to the records after sorting.
Syntax1 -
Simple sequence number generation -
OUTREC OVERLAY=(…,Starting position in o/p file:SEQNUM, length, format,..)
Starting position in o/p file | Specifies the position from where the sequence number to start in o/p file |
SEQNUM | A keyword specifies the sequence number to be generated from the next available position of INREC |
Length | Length of the sequence number to be generated |
Format | Format of the sequence number to be generated |
Syntax2 -
Sequence number generation with increment -
OUTREC OVERLAY=(…,Starting position in o/p file:SEQNUM, length,
format,START=start number, INCR=increment by,
Restart=(field1 starting position, field1 length)…)
Starting position in o/p file | Specifies the position from where the sequence number to start in o/p file |
SEQNUM | A keyword specifies the sequence number to be generated from the next available position of INREC |
Length | Length of the sequence number to be generated |
Format | Format of the sequence number to be generated |
START=start number | Specifies the sequence number starts with |
INCR=increment by | Specifies the number that used to increment the start number |
Restart=(field1 starting position, field1 length) | Specifies the field starting position and length on which the sequence number restart |
Example -
Scenario -Generate the sequence numbers starting from 5 and incrementing by 5 for each record using OUTREC.
Input File - MTHUSER.SORT.INPUT01 - FB file of 80 length
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
00001 student1 dept1 560
00003 student3 dept2 520
00004 student4 dept1 540
00005 student5 dept2 500
00002 student2 dept3 510
******************************** Bottom of Data ********************************
JCL -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Jobcard
//*
//**********************************************************************
//*
//* SORT FOR OUTREC STATEMENT
//*
//**********************************************************************
//STEP01 EXEC PGM=SORT
//SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,5,ZD,A)
OUTREC OVERLAY=(60:SEQNUM,2,ZD,START=5,INCR=5)
/*
**************************** Bottom of Data ****************************
Output -
----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* TOP OF DATA **********************************
00001 student1 dept1 560 05
00002 student2 dept3 510 10
00003 student3 dept2 520 15
00004 student4 dept1 540 20
00005 student5 dept2 500 25
******************************** BOTTOM OF DATA ********************************
Explaining Example -
- SORT FIELDS=(1,5,ZD,A) - Input file will be sorted first and writes to the output.
- OUTREC OVERLAY=(60:SEQNUM,2,ZD,START=5,INCR=5) - Generates the sequence number of length 2 from 60th byte. The sequence number starts at 5 and incremented by 5 each time.