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

Replace dup recs by single rec with sum of a field


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 12, 2012 12:35 pm
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: 792
Location: Chennai, India

PostPosted: Thu Apr 12, 2012 12:37 pm
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
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

Moderator Emeritus


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

PostPosted: Thu Apr 12, 2012 1:10 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts How to append a PS file into multiple... JCL & VSAM 3
No new posts replace word 'MONTH' with current mon... SYNCSORT 11
No new posts Submit multiple jobs from a library t... JCL & VSAM 14
Search our Forums:

Back to Top