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

Get duplicates along with the count


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Thu Dec 22, 2005 2:38 am
Reply with quote

I need to create one single file deviod of duplicates along with the count. Like :

Input File A :

Code:
         
aaaaa   
aaaaa
bbbbb
bbbbb
bbbbb
bbbbb
ccccc


Output file should be like :

Code:

aaaaa 2
bbbbb 4
ccccc 1


How can I use the sort utility for this?
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Dec 22, 2005 3:28 am
Reply with quote

Here's a DFSORT job that will do what you asked for:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
aaaaa
aaaaa
bbbbb
bbbbb
bbbbb
bbbbb
ccccc
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  SORT FIELDS=(1,5,CH,A)
  OUTFIL REMOVECC,NODETAIL,
    SECTIONS=(1,5,
      TRAILER3=(1,5,X,COUNT=(M11,LENGTH=1)))
/*


If the records are already in sorted order as shown, then you could do a merge instead of a sort (change SORTIN to SORTIN01 and change SORT to MERGE).
Back to top
View user's profile Send private message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Thu Dec 22, 2005 5:22 am
Reply with quote

Frank Yaeger wrote:
Here's a DFSORT job that will do what you asked for:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
aaaaa
aaaaa
bbbbb
bbbbb
bbbbb
bbbbb
ccccc
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  SORT FIELDS=(1,5,CH,A)
  OUTFIL REMOVECC,NODETAIL,
    SECTIONS=(1,5,
      TRAILER3=(1,5,X,COUNT=(M11,LENGTH=1)))
/*


If the records are already in sorted order as shown, then you could do a merge instead of a sort (change SORTIN to SORTIN01 and change SORT to MERGE).



Thanks for that answer Frank.
But when I try to write this to a sortout file which has double the recordlength of the input file its abending with this info:
1 - CONTROL STATEMENTS FOR 5694-A01, Z/OS DFSORT V1R5 - 18:41 ON WED DEC 21, 200
SORT FIELDS=COPY
OUTFIL REMOVECC,NODETAIL,
SECTIONS=(1,5,
TRAILER3=(1,5,X,COUNT=(M11,LENGTH=1)))
0 RECORD TYPE IS F - DATA STARTS IN POSITION 1
0 5 BYTE FIXED RECORD LENGTH IS NOT EQUAL TO 7 BYTE LRECL FOR SORTOUT
0 C5-K05352 C6-Q95214 C7-K90000 C8-K05352 E9-K06751 E7-K90000
3 END OF DFSORT

Here I have a input file of length 5. And I need to write the ouput to a file of record length 7.
Also what shud I do to write only those records whose count exceeds certain limit only. Like
Input File:
aaaa
bbbb
aaaa
aaaa
bbbb
ccccc

I need an output file with only those records whose count is equal to 3. So my output file shud be like
aaaa
Please help.

Thanks,
Nithin.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Dec 22, 2005 6:13 am
Reply with quote

Nithin,

It would really help if you gave all the information needed for somebody to figure out what you want to do in your first post. You showed an example of your input records and what you wanted for output. I showed you how to do that. Now you're telling me you want this and this and ... It's very hard to hit a moving target. In the future, please try to give all of the information needed in your first post.

If your input file has LRECL=5 and you want the output file to have LRECL=7, change the OUTFIL statement to:

Code:

  OUTFIL REMOVECC,NODETAIL,                 
    OUTREC=(1,5,2X),                         
    SECTIONS=(1,5,                           
      TRAILER3=(1,5,X,COUNT=(M11,LENGTH=1)))


If you want to write records with a count equal to 3 (without having the actual count in the records), you can use a DFSORT/ICETOOL job like this:

Code:

//S2   EXEC PGM=ICETOOL                                       
//TOOLMSG  DD SYSOUT=*                                         
//DFSMSG   DD SYSOUT=*                                         
//IN DD DSN=...  input file                               
//T1   DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,5)),DISP=(,PASS)   
//OUT  DD DSN=...  output file                                           
//TOOLIN   DD *                                               
SELECT FROM(IN) TO(T1) ON(1,5,CH) EQUAL(3)                     
SELECT FROM(T1) TO(OUT) ON(1,5,CH) FIRST                       
/*
Back to top
View user's profile Send private message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Thu Dec 22, 2005 9:39 pm
Reply with quote

Frank,
Thanks for all your help. My problem got resolved by using the second method you provided me. Again, now I am stuck with a different problem.
Here I have multiple input files having the same format and I need a single output file having the same format as that of input file having only those records present all the different input file.
Like :

Input1:
AAA
AAA
BBB
CCC
DDD

Input2:
AAA
AAA
BBB
CCC

Input3:
CCC

My outptu file shud be like
Output file:
AAA
CCC

Please help me.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Thu Dec 22, 2005 10:59 pm
Reply with quote

In the future, please start a new topic for a new question - it makes it easier to search.


You say
Quote:
having only those records present all the different input file.


Your output has AAA and CCC, but Input3 only has CCC. AAA is not present in all the input files so why would you expect it to be in the output file?. Please clarify.
Back to top
View user's profile Send private message
pjnithin

Active User


Joined: 22 Dec 2005
Posts: 116

PostPosted: Fri Dec 23, 2005 1:22 am
Reply with quote

Sorry, that was a mistake i made while sending the query. It shud be like
Input1:
AAA
AAA
BBB
CCC
DDD

Input2:
AAA
AAA
BBB
CCC

Input3:
AAA
CCC

My outptu file shud be like
Output file:
AAA
CCC

So basically I need those records common all the input files with no dups.
Frank Yaeger wrote:
In the future, please start a new topic for a new question - it makes it easier to search.


You say
Quote:
having only those records present all the different input file.


Your output has AAA and CCC, but Input3 only has CCC. AAA is not present in all the input files so why would you expect it to be in the output file?. Please clarify.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


Joined: 15 Feb 2005
Posts: 7129
Location: San Jose, CA

PostPosted: Fri Dec 23, 2005 2:03 am
Reply with quote

See my response in the new topic.
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 To get the count of rows for every 1 ... DB2 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Validating record count of a file is ... DFSORT/ICETOOL 13
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
No new posts Count the number of characters in a f... CA Products 1
Search our Forums:

Back to Top