INREC Inserting Sequence Numbers Example


Scenario - Generate the sequence numbers to identify the record position from 30th position using INREC.

Input File - MATEPK.SORT.INPUT01 - FB file of 80 length

----+----1----+---2----+---3----+---4----+---5----+---6---+----7----+---8
00001     student1           dept1          560
00003     student3           dept2          520
00004     student4           dept1          540
00005     student5           dept2          500
00002     student2           dept3          510

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
//MATEPKD  JOB (123),'MTH',NOTIFY=&SYSUID
//*
//STEP01   EXEC PGM=SORT
//SORTIN   DD DSN=MATEPK.SORT.INPUT01,DISP=SHR
//SORTOUT   DD DSN=MATEPK.MERGE.OUTPUT,
//            DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
//            SPACE=(CYL,(1,4),RLSE),
//            DCB=(RECFM=FB,LRECL=80,BLKSIZE=0)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=(1,5,ZD,A)
     INREC FIELDS=(1,29,45,30,SEQNUM,4,ZD)
/*

Output File -

---+----1----+----2----+---3---+----4----+---5---+---6----+---7----+---8
00001     student1           560                           0001
00002     student2           510                           0005
00003     student3           520                           0002
00004     student4           540                           0003
00005     student5           500                           0004

Explaining Example -

  1. 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).
  2. INREC FIELDS=(..,SEQNUM,4,ZD)) - Generate the sequence number from 60th byte of length 4.
  3. SORT FIELDS=(1,5,ZD,A) - Once the above two tasks done, the file will sorted and the same writes to output after sorting.