SORT card to add header and trailer with date & Counts

This SORT example is to add Header and Trailer to the sorted file along with the total number of records.
Header –> A Name along with the current System date
Trailer–> A static message along with number of input records count

Example Sort Card:

//JOBRPT09 JOB MSGLEVEL=(1,1),MSGCLASS=X
//**********************************************************************
//* ADDING HEADER AND TRAILER ALONG WITH COUNTS AND DATES
//***************************************************************
//STEP01 EXEC PGM=SORT
//SYSPRINT DD SYSOUT=A
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=TTR.SORT.TEST.IN,DISP=SHR
//SORTOUT DD DSN=TTR.SORT.TEST.OT,DISP=(NEW,CATLG,DELETE),
// UNIT=SYSDA,SPACE=(CYL,(5,5)),
// DCB=(RECFM=FB,LRECL=50,BLKSIZE=5000)
//*
//SYSIN DD *
  SORT FIELDS=COPY
   OUTFIL REMOVECC,
   HEADER1=(1:'CARD DETAILS AS ON',20:DATE=(MD4/),'@',TIME),
   TRAILER1=(1:'TOTAL NUM OF RECORDS:',COUNT=(M11,LENGTH=4))
/*

Header1 –> It has a Static message which start from 1st position followed by a date and Time. Here given ‘@’ just to separate date and time. You can give anything here.
Trailer1–> Count gives the records count excluding Header and Trailer with length of 4.
MD4/ –> is a Date format with ‘/’ as a separator. There are few other date formats as well that can be used here.
M11 –> this is an Edit mask pattern which gives the numbers in 0005 format if the value is 5. Means it shows the leading zeroes as well. There are many other Patterns which we can use here, but as an example I have used M11.
REMOVECC–> It removes the ANSI carriage control character from the Output file.

 

Output:

----+----1----+----2----+----3----+----4--
CARD DETAILS AS ON 07/23/2019@05:32:39
001990828GOLD CREDIT3395
002990829GOLD DEBIT 3396
003990830SILVRCREDIT3396
004990831PLTNMDEBIT 3395
005990832SILVRDEBIT 3395
TOTAL NUM OF RECORDS:0005

 

5 Comments

Add a Comment

Your email address will not be published. Required fields are marked *