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

Group by a field and take first 2 of every group


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

New User


Joined: 22 Feb 2008
Posts: 70
Location: Turkey

PostPosted: Fri Dec 17, 2010 6:10 pm
Reply with quote

Hi,
I wan to Group by a column and take max. 2 data from 2. column for every group.

For example my input data is like that;
Code:
COL1  COL2
AAAAA 101
AAAAA 102
AAAAA 103
BBBBB 201
BBBBB 202
BBBBB 203
CCCCC 301
CCCCC 302
CCCCC 303


desired output;
Code:
AAAAA 103
AAAAA 102
BBBBB 203
BBBBB 202
CCCCC 303
CCCCC 302


I want to group by COL1 and take the record which have max 2 value from Col2 for each COl1 groups.
Thanks...
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 17, 2010 11:22 pm
Reply with quote

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

Code:

//S1    EXEC  PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG  DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=...  output file
//TOOLIN   DD   *
SELECT FROM(IN) TO(OUT) ON(1,5,CH) FIRST(2) USING(CTL1)
/*
//CTL1CNTL DD   *
  SORT FIELDS=(1,5,CH,A,7,3,CH,D)
/*
Back to top
View user's profile Send private message
ozgurseyrek

New User


Joined: 22 Feb 2008
Posts: 70
Location: Turkey

PostPosted: Fri Dec 17, 2010 11:37 pm
Reply with quote

Thank you Frank.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts To Unstring spaces in a field COBOL Programming 3
No new posts Extract records for a specific condit... DFSORT/ICETOOL 25
No new posts Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:


Back to Top