IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

SUM and Eliminate records if the same key


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
abby.qiong.zhang

New User


Joined: 07 Jun 2012
Posts: 26
Location: China

PostPosted: Fri Nov 30, 2012 7:58 am
Reply with quote

Is this can be done by SORT?

My input is like this:

Code:
KEY         Number
926304    154,963,130.67-
926304       4,092,720.00-


I want the output like this, merge the two records into one and sum the number
Code:
KEY          SUM
926304    159,055,850.67-
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Nov 30, 2012 10:15 am
Reply with quote

Yes

It can be done using SUM FIELDS

But what you need to do is

Format the input and overlay the numeric data without comma and decimal

Use SUM fields

While writing to outrec reformat
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Fri Nov 30, 2012 10:16 am
Reply with quote

Hi,

Check for SUM FIELDS in Sort Manual

Regards,
Chandan
Back to top
View user's profile Send private message
abby.qiong.zhang

New User


Joined: 07 Jun 2012
Posts: 26
Location: China

PostPosted: Fri Nov 30, 2012 2:05 pm
Reply with quote

Pandora-Box wrote:
Yes

It can be done using SUM FIELDS

But what you need to do is

Format the input and overlay the numeric data without comma and decimal

Use SUM fields

While writing to outrec reformat


Thanks for the reply, i found the method, here's it
Code:

  INREC OVERLAY(64:64,16,SFF,ZD,LENGTH=16)
  SORT FIELDS=(13,6,CH,A)
  SUM FIELDS=(64,16,ZD)
  OUTREC OVERLAY=(64:64,16,ZD,EDIT=(SIIII,III,IIT.TT),SIGNS=(+,-))


Code'd
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Nov 30, 2012 2:12 pm
Reply with quote

Please note that both your posts have had Code tags added to them to preserve the spacing of your code/data. Do that yourself next time.

Don't you now have a "leading" sign when previously you had a "trailing" one?
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Nov 30, 2012 2:14 pm
Reply with quote

Nice shot :-)

Frankly I didnt think of SFF icon_redface.gif
Back to top
View user's profile Send private message
Pandora-Box

Global Moderator


Joined: 07 Sep 2006
Posts: 1592
Location: Andromeda Galaxy

PostPosted: Fri Nov 30, 2012 2:43 pm
Reply with quote

abby.qiong.zhang

Did you test this code??

Did you get the output you wanted ??
Back to top
View user's profile Send private message
abby.qiong.zhang

New User


Joined: 07 Jun 2012
Posts: 26
Location: China

PostPosted: Fri Nov 30, 2012 2:58 pm
Reply with quote

Pandora-Box wrote:
abby.qiong.zhang

Did you test this code??

Did you get the output you wanted ??


Yes, I did the test and the output is exactly what I want.
Back to top
View user's profile Send private message
sqlcode1

Active Member


Joined: 08 Apr 2010
Posts: 577
Location: USA

PostPosted: Fri Nov 30, 2012 10:15 pm
Reply with quote

abby.qiong.zhang,
As mentioned earlier, you are now getting leading sign instead of trailing sign which is what NOT you requested earlier.

Alternatively you can use below method so that you don't have to OVERLAY and do the conversion. If your input file is already sorted on key then replace SORT FIELDS= statement with OPTION COPY. If you want trailing positive (+) sign as well, change SIGNS=(,,+,-)

Code:
//STEP0001 EXEC PGM=SORT                                         
//SORTIN   DD  *                                                 
926304    154,963,130.67-                                         
926304      4,092,720.00-                                         
//SORTOUT  DD  SYSOUT=*                                           
//SYSIN DD *                                                     
 SORT FIELDS=(1,6,CH,A),EQUALS                                   
 OUTFIL REMOVECC,NODETAIL,SECTIONS=(1,6,                         
 TRAILER3=(1,10,                                                 
           TOT=(11,15,SFF,EDIT=(III,III,IIT.TTS),SIGNS=(,,,-)))) 
/*                                                               
//SYSOUT DD SYSOUT=*                                             
//*                                                               

OUTPUT
Code:
926304    159,055,850.67-

Thanks,
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Fri Nov 30, 2012 11:20 pm
Reply with quote

abby.qiong.zhang,

Consult the manual for the difference between SUM and the OUTFIL reporting functions and the influence of EQUALS or NOEQUALS on the process, if this requirement is part of a larger one dealing with records of the same key but different information.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Compare only first records of the fil... SYNCSORT 7
No new posts Pulling a fixed number of records fro... DB2 2
No new posts Join multiple records using splice DFSORT/ICETOOL 5
Search our Forums:

Back to Top