SUM FIELDS in DFSORT

2.9k views Asked by At
//SUMREC01 JOB SUMREC0J
//SUMEXEC EXEC PGM=SORT
//SORTIN DD *
CA-02963
CA 06288
CA 07351
CA 05027
CA 05200
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
 SORT FIELDS=(1,2,CH,A)
 SUM FIELDS=(3,6,ZD)
/*

When I submit the above job I got "CA026829" Which is the wrong answer.What I have to do for the JCL to consider the minus sign as well and get answer "CA023866"

1

There are 1 answers

0
RainMoose On

You can convert the SFF field to ZD to sum the data as follows:

//SUMREC01 JOB SUMREC0J
//SUMEXEC EXEC PGM=SORT
//SORTIN DD *
CA-02963
CA 06288
CA 07351
CA 05027
CA 05200
//SORTOUT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSIN DD *
 INREC FIELDS=(1,2,3,6,SFF,TO=ZD)
 SORT FIELDS=(1,2,CH,A)
 SUM FIELDS=(3,6,ZD)
 OUTREC FIELDS=(1,2,3,6,ZD,EDIT=(SIIIIT),SIGNS=(,-))
/*

Will result in your output file containing:

CA 20903

Verified with AHLSORT for Windows x64, Version v14r3-87-g811342a2

Should work the same for DFSORT and SYNCSORT.