OUTFIL: Updating counts and totals in trailer


  • OUTFIL's IFTRAIL parameter can be used to update count and total values in an existing trailer (last) record to reflect the actual data records in the data set.
  • IFTRAIL communicates DFSORT to update the trailer record.

Syntax -


OUTFIL FNAMES=DDNAMEn, INCLUDE=(..), 
IFTRAIL=(HD=YES,TRLID=(starting position, length, format, Character/String),
TRLUPD=(…))
DDNAMEnDDNAME is eight character’s name that representing the actual dataset in JCL.
HD=YESindicates the first record is a header record.
If the input data set has a header, HD=YES need to use to avoid treating the header record as a data record.
TRLID=(logexp) identifies the trailer record using the same type of logical expression used for INCLUDE.
TRLID=(logexp) identifies the trailer record as having a 'T' in position 1.
The identified trailer record is treated as the last record; it is not treated as a data record.
TRLUPD indicates the fields in the data records to be used to update counts and totals.
c:, COUNT=, COUNT+n=, COUNT-n=, TOT= and TOTAL= can be used in TRLUPD in the same way they are used in TRAILER1.
TRLUPD indicates the counts and totals to be updated.

Example -


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

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
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                                                                         
******************************** Bottom of Data ********************************

JCL -

----+----1----+----2----+----3----+----4----+----5----+----6----+----7--
***************************** Top of Data ******************************
//Jobcard 
//*                                                                     
//**********************************************************************
//*                                                                     
//STEP01   EXEC PGM=SORT                                               
//SORTIN   DD DSN=MTHUSER.SORT.INPUT01,DISP=SHR                   
//OUTPUT1  DD DSN=MTHUSER.SORT.OUTPT01,                           
//             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,                    
//             DISP=(NEW,CATLG,DELETE)                                 
//OUTPUT2  DD DSN=MTHUSER.SORT.OUTPT02,                           
//             SPACE=(CYL,(1,1),RLSE),DCB=*.SORTIN,                    
//             DISP=(NEW,CATLG,DELETE)                                 
//OUTPUT3  DD DSN=MTHUSER.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))) 
                                                                        
/*                                                                      
**************************** Bottom of Data ****************************

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

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

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
********************************* Top of Data **********************************
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                                                             
******************************** Bottom of Data ********************************

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

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

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.