|
View previous topic :: View next topic
|
| Author |
Message |
rbkool
New User
Joined: 26 Sep 2006 Posts: 3
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| I may be missing something, but don't you just need a SUM statement? |
|
| Back to top |
|
 |
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
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 |
|
 |
rbkool
New User
Joined: 26 Sep 2006 Posts: 3
|
|
|
|
Thanks Looks simple enough...I was thinking SUM fields retained the duplicates.. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
rbkool
New User
Joined: 26 Sep 2006 Posts: 3
|
|
|
|
Thanks Bill..this I will never forget for sure  |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|