DFSORT OUTREC Inserting sequence numbers

OUTREC: Reformatting with IFTHEN DFSORT INREC

Advertisements


OUTREC statement can be used toadd the sequence number to the records after sorting.


Syntax- Simple sequence number generation:

OUTREC OVERLAY=(…,Starting position in o/p file:SEQNUM, length, format,..)

Name Description
Starting position in o/p fileSpecifies the position from where the sequence number to start in o/p file
SEQNUMA keyword specifies the sequence number to be generated from the next available position of INREC
Length Length of the sequence number to be generated
FormatFormat of the sequence number to be generated

Syntax- 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)…)

Name Description
Starting position in o/p fileSpecifies the position from where the sequence number to start in o/p file
SEQNUMA keyword specifies the sequence number to be generated from the next available position of INREC
Length Length of the sequence number to be generated
FormatFormat of the sequence number to be generated
START=start numberSpecifies the sequence number starts with
INCR=increment bySpecifies 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: -

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 ********************************

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      OUTREC OVERLAY=(60:SEQNUM,2,ZD,START=5,INCR=5)                     
003500 /*                                                                      
****** **************************** 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 Solution:

  1. SORT FIELDS=(1,5,ZD,A) - Input file will be sorted first and writes to the output.
  2. 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.

OUTREC: Reformatting with IFTHEN DFSORT INREC

Advertisements