Page 1 of 1

Summing 2 fields of same record into 1

PostPosted: Tue Mar 22, 2011 12:27 am
by D9988
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!

Re: Summing 2 fields of same record into 1

PostPosted: Tue Mar 22, 2011 1:42 am
by Frank Yaeger
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)
/*

Re: Summing 2 fields of same record into 1

PostPosted: Wed Mar 23, 2011 1:33 am
by D9988
This is great! Got it to work. Thanks Frank, you're awesome as always :D