Summary -
In this topic, we described about the INREC Inserting sequence numbers with detailed example.
To getback the original order of data before sort, a sequence number can be added to each record before therecords are sorted, and use a second step to sort the records back into theiroriginal order by that sequence number. INREC statement can be used toadd the sequence number.
Syntax -
INREC FIELDS=(…,SEQNUM, length, format,..)
Name | Description |
---|---|
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 |
Note! SUM can’t combine with COPY.
Example: -
Generate the sequence numbers to identify the record position before sorting using INREC.
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 *****************************
Job:
000100 //Jobcard
000400 //*
000500 //*******************************************************************
000600 //*
000700 //* SORT FOR OUTREC STATEMENT
000800 //*
000900 //*******************************************************************
001100 //STEP01 EXEC PGM=SORT
001300 //SORTIN DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR
001800 //SORTOUT DD SYSOUT=*
001900 //SYSOUT DD SYSOUT=*
002400 //SYSIN DD *
002411 SORT FIELDS=(1,5,ZD,A)
002420 INREC FIELDS=(1,29,45,30,SEQNUM,4,ZD)
003500 /*
****** **************************** Bottom of Data ***********************
Output:
---+----1----+----2----+---3---+----4----+---5---+---6----+---7----+---8
********************************* TOP OF DATA *******************************
00001 student1 560 0001
00002 student2 510 0005
00003 student3 520 0002
00004 student4 540 0003
00005 student5 500 0004
******************************** BOTTOM OF DATA *****************************
Explaining Solution:
- INREC FIELDS=(1,29,45,30)-Reformat the input file of length 80 to 59 bytes(1 to 29 bytes plus 45 to 75 bytes).
- INREC FIELDS=(..,SEQNUM,4,ZD))-Generate the sequence number from 60th byte of length 4.
- SORT FIELDS=(1,5,ZD,A) - Once the above two tasks done, the file will sorted and the same writes to output after sorting.