Your solution is close the original requirement you'd shared in this post; though when you execute the code shared (after correcting SECTIONS), you'll notice that it returns a CC 16 for 'FNAME='; when same is cleaned up, the output generated should look something as below, which is very different from what you were looking for, notice the decimal truncation that has occurred due to usage of M5:
Output from the shared card:
SURESH 100 TOTAL AMOUNT 0.00 NO. OF COUNT 1
RAMESH 250 TOTAL AMOUNT 0.00 NO. OF COUNT 1
SURESH 150 TOTAL AMOUNT 0.00 NO. OF COUNT 1
SURESH 200 TOTAL AMOUNT 0.00 NO. OF COUNT 1
RAMESH 100 TOTAL AMOUNT 0.00 NO. OF COUNT 1
Expected output from original post:
RAMESH 35000 2
SURESH 45000 3
I have cleaned up your code a little bit; notice the differences:
//STEP002 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
//SORTOUT DD SYSOUT=*
//SYSIN DD *
* SORT FIELDS=COPY REPLACED WITH VALID SORTING KEY TO GROUP DATA AND
* FACILITATE SECTIONS PROCESSING.
* OUTFIL USED TO TAILOR THE OUTPUT WITH REPORTING FEATURES
* REMOVECC USED TO REMOVE THE CARRIAGE CONTROL
* CHARACTER WHICH WILL BE INSERTED FOLLOWING USAGE OF
* OUTFIL REPORTING FEATURE.
* NODETAIL USED TO AVOID THE INPUT DATA CHUNK FROM
* GETTING COPIED TO SORTOUT DS.
* SECTIONS BREAKS THE DATA INTO GROUPS DEFINED IN THE
* SECTIONS KEY.
* TRAILER3 COMES BUNDLED WITH SECTIONS.
* TOT IS THE SUB-COMMAND OF TRAILER3, ALLOWS
* SUMMATION OF USER-DEFINED FIELDS.
* ZD IS ZONED DECIMAL FORMAT.
* M10 IS THE EDIT MASK PATTERN, WHICH ALLOWS USER
* TO CHOOSE HOW THEY WANT TO SEE THE OUTPUT DATA.
* COUNT IS ANOTHER SUB-PARAMETER, WHICH DOES WHAT
* THE NAME SAYS: IT COUNTS.
C' TOTAL AMOUNT:',TOT=(8,5,ZD,M10,LENGTH=10),
RAMESH TOTAL AMOUNT: 35000 COUNT: 2
SURESH TOTAL AMOUNT: 45000 COUNT: 3
The above code is more or less self-explanatory, for more details on edit mask patterns, data formats, refer DFSORT Application Programming Guide.
Hope this helps.