Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Replace dup recs by single rec with sum of a field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
rbkool

New User


Joined: 26 Sep 2006
Posts: 3

PostPosted: Thu Apr 12, 2012 12:28 pm    Post subject: Replace dup recs by single rec with sum of a field
Reply with quote

I have a file which has duplicate records and a count field in each record. I have to replace all the duplicate records with a single record. The single record count field should have the sum of count field from the duplicate records.

The input/output file is FB.

The sort keys are 1,3,ch and 5,2,ch and count is 8,1,zd

input file:
Code:
aaa xx 1
aaa xx 1
bbb xx 2
bbb xx 1
bbb yy 1
ccc xx 1
ccc yy 2
ccc yy 1
ddd xx 1


the output file should be:
Code:
aaa xx 2
bbb xx 3
bbb yy 1
ccc xx 1
ccc yy 3
ddd xx 1


I have come as far as identifying the duplicate records and extracting them to a temporary file. Then I am extracting the first of the duplicate record. But I am stuck at how to sum the count field to put in the single record of the duplicate records.

Code:
//STEP0010 EXEC PGM=ICETOOL,REGION=0M
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN      DD DSN=INPUT1,DISP=SHR
//TMP1    DD DSN=&&TEMP1,UNIT=SYSDA,SPACE=(CYL,(5,5)),
//           DISP=(MOD,PASS)
//OUT1    DD DSN=OUTPUT.DUP,
//           DISP=(NEW,CATLG,DELETE),DCB=*.IN,DATACLAS=SMALL
//OUT2    DD DSN=OUTPUT.REM,
//           DISP=(NEW,CATLG,DELETE),DCB=*.IN,DATACLAS=SMALL
//TOOLIN  DD *
SELECT FROM(IN) TO(TMP1) ON(1,3,CH) ON(5,2,CH) -
HIGHER(1) DISCARD(OUT2)
SELECT FROM(TMP1) TO(OUT1) ON(1,3,CH) ON(5,2,CH) FIRSTDUP
/*


This will give me the first of duplicate records in OUT1 and the non-duplicate records in OUT2. Once i get each record in OUT1 updated with the sum of count fields, i can sort it back in to OUT2 to get the desired output.

out1:
Code:
aaa xx 1
bbb xx 2
ccc yy 2


out2:
Code:
bbb yy 1
ccc xx 1
ddd xx 1
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7251

PostPosted: Thu Apr 12, 2012 12:35 pm    Post subject: Reply to: Replace dup recs by single rec with sum of a field
Reply with quote

I may be missing something, but don't you just need a SUM statement?
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 785
Location: Chennai, India

PostPosted: Thu Apr 12, 2012 12:37 pm    Post subject:
Reply with quote

Looks simple to me.
Code:
SORT FIELDS=(1,6,CH,A)   
SUM FIELDS=(8,1,ZD)     

Please let me know if something is missed.
Back to top
View user's profile Send private message
rbkool

New User


Joined: 26 Sep 2006
Posts: 3

PostPosted: Thu Apr 12, 2012 1:01 pm    Post subject:
Reply with quote

Thanks icon_smile.gif Looks simple enough...I was thinking SUM fields retained the duplicates..
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7251

PostPosted: Thu Apr 12, 2012 1:10 pm    Post subject: Reply to: Replace dup recs by single rec with sum of a field
Reply with quote

That's what the manuals are for. To get you to say to yourself "now, why did I ever think that? I'll not forget that in a hurry (ever)".
Back to top
View user's profile Send private message
rbkool

New User


Joined: 26 Sep 2006
Posts: 3

PostPosted: Thu Apr 12, 2012 1:53 pm    Post subject:
Reply with quote

Thanks Bill..this I will never forget for sure icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts For each given key value, how to keep... Div Grad DFSORT/ICETOOL 7 Fri Nov 11, 2016 11:38 pm
No new posts Two Selects in a single select query Rohit Umarjikar DB2 1 Fri Nov 04, 2016 8:46 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us