Summing 2 fields of same record into 1



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

Summing 2 fields of same record into 1

Postby D9988 » Tue Mar 22, 2011 12:27 am

Hello - I am trying to perform a sort/sum. For all records that match the sort-key, I want to sum the 2 amount fields into one. Here's an example of what my input file looks like:

=COLS> ----+----1----+----2----+----3----+----4-
000001 111115559265667
000002 111116214218451
000003 222229871521492
000004 222224542121599


1,5 = account(a5) - this is the sort key
6,5 = amount 1(n3.2)
11,5 = amount 2(n3.2)

The output should look like this:
=COLS> ----+----1----+----2----+----3----+----4-
000001 11111201852
000002 22222187227


Thanks for your help!
David
D9988
 
Posts: 34
Joined: Fri Nov 09, 2007 10:55 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Summing 2 fields of same record into 1

Postby Frank Yaeger » Tue Mar 22, 2011 1:42 am

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

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
111115559265667
111116214218451
222229871521492
222224542121599
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  INREC BUILD=(1,5,6:6,5,ZD,ADD,11,5,ZD,TO=ZD,LENGTH=6)
  SORT FIELDS=(1,5,CH,A)
  OPTION ZDPRINT
  SUM FIELDS=(6,6,ZD)
/*
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

These users thanked the author Frank Yaeger for the post:
sinmani (Wed May 15, 2013 12:14 pm)
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: Summing 2 fields of same record into 1

Postby D9988 » Wed Mar 23, 2011 1:33 am

This is great! Got it to work. Thanks Frank, you're awesome as always :D
David
D9988
 
Posts: 34
Joined: Fri Nov 09, 2007 10:55 pm
Has thanked: 0 time
Been thanked: 0 time


Return to DFSORT/ICETOOL/ICEGENER

 


  • Related topics
    Replies
    Views
    Last post