Page 1 of 1

Sort first 'N' records for each Key in a group of DUP keys

PostPosted: Sun Jun 21, 2009 8:41 am
by gopal0802
Hi, I need to sort first 'N' records of each KEY in a set of records having many records with duplicate keys. Example is shown below::

Input Records:
AAA 1234
AAA 2345
AAA 9878
AAA 6754
BBB 5675
BBB 2346
BBB 2345
CCC 5674
CCC 4325
AAA 3453
BBB 3636

From the above input, I need to sort out first 2 records of each Key (Key = First 3 bytes) and write in out file the combined output

Expected output.
AAA 1234
AAA 2345
BBB 5675
BBB 2346
CCC 5674
CCC 4325

Is there any utility that can be used for the above scenario ? Could any one help me with the solution for the above problem?
It is greatly appreciated, if you provide and solution which can be used in a JCL.

-Ram

Re: Sort first 'N' records for each Key in a group of DUP keys

PostPosted: Mon Jun 22, 2009 8:35 pm
by skolusu
gopal0802,

The following DFSORT/ICETOOL jcl will give you the desired results

//STEP0100 EXEC PGM=ICETOOL                   
//TOOLMSG  DD SYSOUT=*                         
//DFSMSG   DD SYSOUT=*                         
//IN       DD *                               
AAA 1234                                       
AAA 2345                                       
AAA 9878                                       
AAA 6754                                       
BBB 5675                                       
BBB 2346                                       
BBB 2345                                       
CCC 5674                                       
CCC 4325                                       
AAA 3453                                       
BBB 3636                                       
//OUT      DD SYSOUT=*                         
//TOOLIN   DD *                               
  SELECT FROM(IN) TO(OUT) ON(1,3,CH) FIRST(2) 
//*


For more details about selecting the first n records and other new features visit
http://www.ibm.com/systems/support/stor ... /mvs/ugpf/