Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist 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: 7314

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

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 Formatting multiple records to a sing... Vignesh Sid SYNCSORT 3 Tue Nov 07, 2017 12:22 pm
This topic is locked: you cannot edit posts or make replies. Incrementing current time field by 30... arunsoods DFSORT/ICETOOL 11 Thu Oct 26, 2017 3:22 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts More than 1 Include criteria for sing... Roy Ware SYNCSORT 6 Wed Sep 13, 2017 11:45 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us