Page 1 of 1

Add the amounts

PostPosted: Thu Mar 24, 2011 6:58 pm
by Ramanath
How to sum the amounts?

Input file

XYZ USA 100.00
XYZ USA 100.00
XYZ USA 100.00
ABC ENG 100.00
ABC ENG 100.00
ABC ENG 100.00

Output file

XYZ USA 300.00
ABC ENG 300.00

Re: Add the amounts through JCL sort

PostPosted: Thu Mar 24, 2011 8:42 pm
by NicC
First - do not post in JCL as JCL cannot do this but it will tell the OS that you want to run sort (which flavour of sort do you use? DF or SYNC or soemthing else?) to do what you want. You should post in the appropriate SORT section of the forum.

Suggest you use the manual for your sort product and the answer is probably along the lines of:
SORT FIELDS=(1,8,CH,A)
SUM FIELDS=(10,6,ZD) 

Re: Add the amounts

PostPosted: Thu Mar 24, 2011 10:16 pm
by Frank Yaeger
Ramanath,

You can use a DFSORT job like the following to do what you asked for:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
XYZ  USA   100.00
XYZ  USA   100.00
XYZ  USA   100.00
ABC  ENG   100.00
ABC  ENG   100.00
ABC  ENG   100.00
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  OUTFIL REMOVECC,NODETAIL,
    SECTIONS=(1,8,
      TRAILER3=(1,8,10:TOT=(10,8,UFF,EDIT=(IIIIT.TT))))
/*



Note: SUM with ZD will NOT work correctly for values with decimal points.

Re: Add the amounts

PostPosted: Fri Mar 25, 2011 1:56 pm
by Ramanath
The following is working for addition of positive amounts.

Input file

XYZ USA 0000000000100Û50
XYZ USA 0000000000100Û00
XYZ USA 0000000000100Û00
ABC ENG 0000000000100Û00
ABC ENG 0000000000100Û00
ABC ENG 0000000000100Û00

Output file
ABC ENG 0000000000300Û00
XYZ USA 0000000000300Û50

//SYSIN DD *
SORT FIELDS=(1,7,CH,A)
SUM FIELDS=(10,13,ZD,24,2,ZD)
/*

Now my question is how to add negative amounts

XYZ USA 0000000000100Û50
XYZ USA -000000000100Û00
XYZ USA 0000000000100Û00
ABC ENG 0000000000100Û00
ABC ENG 0000000000100Û00
ABC ENG 0000000000100Û00

Re: Add the amounts

PostPosted: Fri Mar 25, 2011 11:31 pm
by Frank Yaeger
-000000000100 is NOT a ZD value. It's an SFF value and you would use SECTIONS and TRAILER3 with TOTAL to sum these values similar to the first example I showed. The DFSORT control statements would be something like this:

  OPTION COPY                                               
  OUTFIL REMOVECC,NODETAIL,                                 
    SECTIONS=(1,7,                                           
      TRAILER3=(1,8,                                         
        9:TOT=(9,14,SFF,EDIT=(STTTTTTTTTTTTT),SIGNS=(,-)),   
        23,1,                                               
        TOT=(24,2,ZD,TO=ZD,LENGTH=2)))