Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Group by a field and take first 2 of every group

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
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    Post subject: Group by a field and take first 2 of every group
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 Moderator


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

PostPosted: Fri Dec 17, 2010 11:22 pm    Post subject:
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    Post subject:
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    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 Why TS/OP would Not contact site supp... RahulG31 All Other Mainframe Topics 2 Wed Mar 22, 2017 7:46 am
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us