Module 8: JCL Sort & Merge
INREC Statement
INREC statement is used to reformat input dataset before sort. In other words INREC statement is used to add, delete or to rearrange the fields of dataset before records are sorted, merged or copied.
- FIELDS or BUILD
- OVERLAY
- FINDREP
- IF THEN clauses
IMP NOTE: Explanation for all these parameters are already detailed in previous articles 'OUTREC FIELDS or BUILD', 'OUTREC OVERLAY', 'OUTREC FINDREP', 'OUTREC IF THEN clauses'. The only difference is that, when we use INREC, records are formatted before they are sorted.
Example :-
Input file:-
----+----1----+----2----+----3
JOHN MON 08000
AKSHAY TUE 10000
SMITH WED 25000
JOHN SUN 28000
STEVE MON 20000
VIJAY XXX 24000
VIJAY SUN 30000
Requirement: Give sequence number to each records of input file and then sort it based on ascending order of employee-name.
JCL Code Solution:
//SORTSTEP EXEC PGM=SORT
//SORTIN DD DSN=DEPT.EMPL.DATA.OUTPUT1,DISP=SHR
//SORTOUT DD DSN=DEPT.EMPL.DATA.OUTPUT2,
// DISP=(,CATLG,DELETE),
// DCB=(RECFM=FB,LRECL=40,BLKSIZE=0),
// UNIT=TEST,SPACE=(CYL,(50,10),RLSE)
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=(1,10,CH,A)
INREC FIELDS=(1:1,30,36:SEQNUM,5,ZD)
/*
Output file:
----+----1----+----2----+----3----+----4
AKSHAY TUE 10000 00002
JOHN MON 08000 00001
JOHN SUN 28000 00004
SMITH WED 25000 00003
STEVE MON 20000 00005
VIJAY XXX 24000 00006
VIJAY SUN 30000 00007
Explanation:
- As mentioned earlier INREC is used to reformat data before sort, thus in above case first each records will be created by appending sequence number at 36th position and then it will be sorted in ascending order based on employee-name. If you observer output file shown above, the sequence number at position 36 indicates original position sequence when record was in input file