Add the amounts



IBM's flagship sort product DFSORT for sorting, merging, copying, data manipulation and reporting. Includes ICETOOL and ICEGENER

Add the amounts

Postby Ramanath » Thu Mar 24, 2011 6:58 pm

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
Ramanath
 
Posts: 7
Joined: Thu Feb 17, 2011 3:51 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Add the amounts through JCL sort

Postby NicC » Thu Mar 24, 2011 8:42 pm

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) 
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: Add the amounts

Postby Frank Yaeger » Thu Mar 24, 2011 10:16 pm

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.
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times

Re: Add the amounts

Postby Ramanath » Fri Mar 25, 2011 1:56 pm

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
Ramanath
 
Posts: 7
Joined: Thu Feb 17, 2011 3:51 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Add the amounts

Postby Frank Yaeger » Fri Mar 25, 2011 11:31 pm

-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)))                       
Frank Yaeger - DFSORT Development Team (IBM) - yaeger@us.ibm.com
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
=> DFSORT/MVS is on the Web at http://www.ibm.com/storage/dfsort
User avatar
Frank Yaeger
Global moderator
 
Posts: 1079
Joined: Sat Jun 09, 2007 8:44 pm
Has thanked: 0 time
Been thanked: 15 times


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post