0
votes
//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
The JCL does nothing to your data, sort does. Sort is not JCL and its control statements are not JCL. They are control statements, Your numbers are not ZD. ZD numbers have the sign in the last byte, You need the SFF format. - NicC
Right. As @NicC alludes to, those aren't numbers but EBCDIC characters and they have to be parsed into numbers before they can be SUMmed. - Martin Packer

1 Answers

1
votes

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.