OUTFIL Creating Trailer in Reports Example


Scenario - Create the report with min, max, avg marks statistics.

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)
//SYSOUT   DD SYSOUT=*
//SYSIN    DD *
     SORT FIELDS=(1,5,ZD,A)
     OUTFIL FNAMES=OUTPUT1,LINES=17,BLKCCH2,

     HEADER1=(20:'Student Details',
        37:'Printed on ',DATE=(MD4/),' AT ',TIME),

     HEADER2=(/,15:'Class X Students details',
        40:'Page',PAGE,53:' on ',58:DATE=(MD4-),4/,
        1:'Std num',11:'Std name',30:'Department',45:'Total marks',/, 
        1:'-------',11:'--------',30:'----------',45:'-----------'),  

     OUTREC=(1,80),
 
     TRAILER1=(2/,
        5:'Max  Marks    = ',MAX=(45,3,ZD,M12,LENGTH=10),/,
        5:'Min  Marks    = ',MIN=(45,3,ZD,M12,LENGTH=10),/,      
        5:'Avg  Marks    = ',AVG=(45,3,ZD,M12,LENGTH=10))        
/*

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

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8
                   Student Details  Printed on 01/13/2017 AT 06:21:18

              Class X Students details Page     1    on  01-13-2017

Std num   Std name           Department     Total marks
-------   --------           ----------     -----------
00001     student1           dept1          560 
00002     student2           dept3          510
00003     student3           dept2          520
00004     student4           dept1          540
00005     student5           dept2          500
00006     student6           dept3          550
00007     student7           dept3          510
00008     student8           dept1          530
00009     student9           dept2          520 
00010     student10          dept2          505

    Max  Marks    =        560
    Min  Marks    =        500
    Avg  Marks    =        524 

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,.. - Writes the output to the output1 file.
  3. OUTFIL FNAMES=OUTPUT1,LINES=17,BLKCCH2,… - LINES=8 is equal to a single record per page. LINES=17 means 10 records will be written to page.
  4. OUTFIL FNAMES=OUTPUT1,..,HEADER1=(20:'Student Details',37:'Printed on ',DATE=(MD4/),' AT ',TIME), - Creates the main/overall header.
  5. HEADER2=(/,15:'Class X Students details',40:'Page',PAGE,53:' on ',58:DATE=(MD4-),4/,1:'Std num',11:'Std name',30:'Department',45:'Total marks',/, 1:'-------',11:'--------',30:'----------',45:'-----------') - Creates pages level header.
  6. OUTREC=(1,80) - Build the output record from input file of length 80.
  7. TRAILER1=(2/,..) - Adds two empty lines to output file after the data copied from input file.
  8. TRAILER1=(..,5:'Max Marks = ',MAX=(45,3,ZD,M12,LENGTH=10),/,..) - Calculates MAX marks from the Marks from 45th position of length 3 and displays the maximum value from 5th position in the output file.
  9. TRAILER1=(..,/,..) - moves the control to the next line.
  10. TRAILER1=(..,5:'Min Marks = ',MIN=(45,3,ZD,M12,LENGTH=10),/,..) - Calculates MIN marks from the Marks from 45th position of length 3 and displays the maximum value from 5th position in the output file.
  11. TRAILER1=(..,/,..) - moves the control to the next line.
  12. TRAILER1=(..,5:'Avg Marks = ',AVG=(45,3,ZD,M12,LENGTH=10)) - Calculates AVG marks from the Marks from 45th position of length 3 and displays the maximum value from 5th position in the output file.