OUTFIL Updating Counts and Totals in Trailer Example


Scenario - Separate the files at depart level with min, max and avg marks for each department.

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
H 2017/01/17
DTL 1     student1           dept1      560
DTL 2     student2           dept3      510
DTL 3     student3           dept2      520
DTL 4     student4           dept1      540
DTL 5     student5           dept2      500
DTL 6     student6           dept3      550
DTL 7     student7           dept3      510
DTL 8     student8           dept1      530
DTL 9     student9           dept2      520
DTL10     student10          dept2      505
T 00010

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

     OUTFIL FNAMES=OUTPUT1,INCLUDE=(30,5,CH,EQ,C'dept1'),
            IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
       TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6)))

     OUTFIL FNAMES=OUTPUT2,INCLUDE=(30,5,CH,EQ,C'dept2'),
            IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
       TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6))) 

     OUTFIL FNAMES=OUTPUT3,INCLUDE=(30,5,CH,EQ,C'dept3'),
            IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T'),
       TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6))) 

/*

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
H 2017/01/17
DTL 1     student1           dept1      560
DTL 4     student4           dept1      540
DTL 8     student8           dept1      530
T 0000003    001630

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
H 2017/01/17 
DTL 3     student3           dept2      520
DTL 5     student5           dept2      500
DTL 9     student9           dept2      520
DTL10     student10          dept2      505
T 0000004    002045

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
H 2017/01/17
DTL 2     student2           dept3      510
DTL 6     student6           dept3      550
DTL 7     student7           dept3      510
T 0000003    001570

Explaining Example -

  1. 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.
  2. OUTFIL FNAMES=OUTPUT1,..,IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T') - IFTRAIL tells to DFSORT that update the tailor record in output1 file.
  3. OUTFIL FNAMES=OUTPUT1,.., TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6)) - Updates the trailer record in the output1 file.
  4. 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.
  5. OUTFIL FNAMES=OUTPUT2,..,IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T') - IFTRAIL tells to DFSORT that update the tailor record in output2 file.
  6. OUTFIL FNAMES=OUTPUT2,.., TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6)) - Updates the trailer record in the output2 file.
  7. OUTFIL FNAMES=OUTPUT3,INCLUDE=(30,5,CH,EQ,C'dept1') - All the records marching with "dept3" from the 30th position of length 5 will be copied to output3 file.
  8. OUTFIL FNAMES=OUTPUT3,..,IFTRAIL=(HD=YES,TRLID=(1,1,CH,EQ,C'T') - IFTRAIL tells to DFSORT that update the tailor record in output3 file.
  9. OUTFIL FNAMES=OUTPUT3,.., TRLUPD=(6:COUNT=(M11,LENGTH=4),14:TOT=(41,3,ZD,TO=ZD,LENGTH=6)) - Updates the trailer record in the output3 file.