Search code examples
mainframejcldfsort

mainframe - generate a report with sum of particular fields


I have a VSAM which has

• 4-byte binary unsigned integer representing a 6-digit decimal branch sortcode (e.g. 420101)

• 4-byte binary unsigned integer representing an 8-digit account number (e.g. 12345678)

• 4-byte signed integer holding the account's current balance

• 32-byte EBCDIC character account owner name (e.g. “PAT JONES”), blank padded on the right

and I want to generate a report as below

enter image description here

I was trying to do this

  INCLUDE COND=(1,7,CH,EQ,C'some sortcode')                              
  SORT FIELDS=(1,7,CH,A)                                            
  SUM FIELDS=(9,2,BI)

But there's plenty of sortcode. I am thinking of sort all the inputs and then sum every record that has the same sortcode together right underneath these sortcode rows. Is there any way in JCL I can do that? Thanks.


Solution

  • Try this:

    //SORTSTEP EXEC PGM=SORT
    //SYSOUT   DD SYSOUT=*
    //SYSPRINT DD SYSOUT=*
    //SORTIN   DD DSN=YourInputDataset,DISP=SHR
    //SORTOUT  DD DSN=YourOutputDataset,
    //          DISP=(NEW,CATLG,DELETE)
    //SYSIN  DD *
      SORT FIELDS=(1,4,BI,A)
      INREC BUILD=(1,4,BI,TO=ZD,LENGTH=6,5,4,9,4,13,32)
      OUTFIL REMOVECC,
             SECTIONS=(1,6,
             HEADER3=(1:C'LIST OF BANK BY BRANCH',/,X,/,
                      1:C'SORTCODE:    ',1,6,/,X,/,
                      1:C'ACCOUNT',10:C'BALANCE',20:C'OWNER NAME',/,
                      1:C'-------',10:C'-------',20:C'----------'),
             TRAILER3=(X,/,
          1:C'BRANCH TOTAL: ',16:TOT=(11,4,BI,EDIT=(SIIIITTT),SIGNS=(,-)))),
             TRAILER1=(X,/,1:C'GRAND TOTAL: ',TOT=(11,4,BI,
                            EDIT=(SIIIITTT),SIGNS=(,-))),
            OUTREC=(1:7,4,BI,TO=ZD,LENGTH=8,10:11,4,BI,EDIT=(SIIIITTT),
                            SIGNS=(,-),20:15,32)
    /*
    

    You can find about more about SECTIONS, HEADER3 and TRAILER3 at this link: https://www.ibm.com/support/knowledgecenter/en/SSLTBW_2.1.0/com.ibm.zos.v2r1.iceg200/ice2cg_Sections.htm