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: 7315

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: 788
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: 7315

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 Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
No new posts Replace values in the input data Vikas Maharnawar DFSORT/ICETOOL 10 Thu May 11, 2017 2:18 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm
No new posts Alter &DATENS field in HEADER1 Angad DFSORT/ICETOOL 4 Mon Apr 24, 2017 11:49 am
This topic is locked: you cannot edit posts or make replies. SDSF multiple spool datasets extracte... PJAlarcon CLIST & REXX 1 Fri Apr 21, 2017 10:50 pm


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