OUTFIL Repeating Example


Scenario -

Create three output files like below -

  • Repeat dept1 records 1 time, move to file1 and add 1 digit sequence number from 60th byte starting from 1 and increment by 1.
  • Repeat dept2 records 2 times, move to file2 and add 2 digit sequence number from 60th byte starting from 2 and increment by 2.
  • Repeat dept3 records 3 times, move to file3 file2 and add 3 digit sequence number from 60th byte starting from 2 and increment by 3.

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
00006     student6           dept3          550
00008     student8           dept1          530
00007     student7           dept3          510
00009     student9           dept2          520
00010     student10          dept2          505

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
//OUTPUT1  DD DSN=MATEPK.SORT.OUTPT01,
//             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,
//             DISP=(NEW,CATLG,DELETE)
//OUTPUT2  DD DSN=MATEPK.SORT.OUTPT02,
//             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,
//             DISP=(NEW,CATLG,DELETE)
//OUTPUT3  DD DSN=MATEPK.SORT.OUTPT03,
//             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,
//             DISP=(NEW,CATLG,DELETE)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=(1,5,ZD,A)
     OUTFIL FNAMES=OUTPUT1,INCLUDE=(30,5,CH,EQ,C'dept1'),
     BUILD=(1,59,X,SEQNUM,1,ZD,START=1,INCR=1)

     OUTFIL FNAMES=OUTPUT2,REPEAT=2,INCLUDE=(30,5,CH,EQ,C'dept2'),
     BUILD=(1,59,X,SEQNUM,2,ZD,START=1,INCR=2)

     OUTFIL FNAMES=OUTPUT3,REPEAT=3,INCLUDE=(30,5,CH,EQ,C'dept3'),
     BUILD=(1,59,X,SEQNUM,3,ZD,START=1,INCR=3)
/*

Output File1 - MATEPK.SORT.OUTPT01 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00001     student1           dept1          560             1
00004     student4           dept1          540             2
00008     student8           dept1          530             3

Output File2 - MATEPK.SORT.OUTPT02 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00003     student3           dept2          520             01
00003     student3           dept2          520             03
00005     student5           dept2          500             05
00005     student5           dept2          500             07
00009     student9           dept2          520             09
00009     student9           dept2          520             11
00010     student10          dept2          505             13
00010     student10          dept2          505             15

Output File3 - MATEPK.SORT.OUTPT03 - FB file of 80 length

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
00002     student2           dept3          510             001
00002     student2           dept3          510             004
00002     student2           dept3          510             007
00006     student6           dept3          550             010
00006     student6           dept3          550             013
00006     student6           dept3          550             016
00007     student7           dept3          510             019
00007     student7           dept3          510             022
00007     student7           dept3          510             025

Explaining Example -

  1. SORT FIELDS=(1,5,ZD,A) - sort all outputs in ascending order based on the ZD value from 1 to 5 positions.
  2. OUTFIL FNAMES=OUTPUT1,INCLUDE=(30,5,CH,EQ,C'dept1') - All the records marching with "dept1" from the 30th position of length 5 will be copied to output1 file.
  3. OUTFIL FNAMES=OUTPUT1,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output file1 as it is (which satisfies the above condition).
  4. OUTFIL FNAMES=OUTPUT1,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  5. OUTFIL FNAMES=OUTPUT1,.., BUILD=(..,SEQNUM,1,ZD,START=1,INCR=1) - generates the sequence number in OUTPUT1 file starts with 1 and increments by 1 every time from 61st byte of length one byte.
  6. OUTFIL FNAMES=OUTPUT2,INCLUDE=(30,5,CH,EQ,C'dept2') - All the records marching with "dept2" from the 30th position of length 5 will be copied to output2 file.
  7. OUTFIL FNAMES=OUTPUT2,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output2 file as it is (which satisfies the above condition).
  8. OUTFIL FNAMES=OUTPUT2,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  9. OUTFIL FNAMES=OUTPUT2,.., BUILD=(..,SEQNUM,2,ZD,START=1,INCR=2) - generates the sequence number in OUTPUT2 file starts with 1 and increments by 2 every time from 61st byte of length 2 bytes.
  10. OUTFIL FNAMES=OUTPUT3,INCLUDE=(30,5,CH,EQ,C'dept3') - All the records marching with "dept3" from the 30th position of length 5 will be copied to output3 file.
  11. OUTFIL FNAMES=OUTPUT3,.., BUILD=(1,59,...) - Copies 1 to 59 bytes data from input file to output3 file as it is (which satisfies the above condition).
  12. OUTFIL FNAMES=OUTPUT3,.., BUILD=(1,59,X,..) - Add space to the 60th byte.
  13. OUTFIL FNAMES=OUTPUT3,.., BUILD=(..,SEQNUM,3,ZD,START=1,INCR=3) - generates the sequence number in OUTPUT2 file starts with 1 and increments by 3 every time from 61st byte of length 3 bytes.