Page 1 of 1

Get the first 3 records for each key

PostPosted: Sun Jan 25, 2009 7:10 pm
by ranga_subham
Hi,

I want to get the first 3 records for each key from the below dataset. I have pasted only portion of it (LRECL=190, RECFM=FB).

CENTRE1000
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE9898
CENTRE9898
CENTRE9898
CENTRE9898
CENTR10980
CENTR10980
CENTR10980
CENTR10980
CENTR10980


Output:
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE9898
CENTRE9898
CENTRE9898
CENTR10980
CENTR10980
CENTR10980


I tried using below code with SYNCTOOL but unsuccessfully. I thought it is not supported in v1.2.3.1R.

//TOOLIN DD *
SELECT FROM(IN1) TO(OUT1) ON(1,10,CH) FIRST(3)
/*


Please suggest.

Thanks.

Re: Get the first 3 records for each key

PostPosted: Mon Jan 26, 2009 8:45 pm
by Alissa Margulies
ranga_subham,

If the data is already in sorted order, then you can use the job below:

//SORT1 EXEC PGM=SORT                                   
//SYSOUT  DD SYSOUT=*
//SORTOUT DD DSN=output.file,...
//SORTIN  DD *
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE1000
CENTRE9898
CENTRE9898
CENTRE9898
CENTRE9898
CENTR10980
CENTR10980
CENTR10980
CENTR10980
CENTR10980
//SYSIN   DD *
   INREC FIELDS=(1,10,11:SEQNUM,8,ZD,RESTART=(1,10))   
   SORT FIELDS=COPY                                 
   OUTFIL INCLUDE=(11,8,ZD,LE,3),OUTREC=(1,10)       
/*

Re: Get the first 3 records for each key

PostPosted: Tue Jan 27, 2009 5:09 pm
by ranga_subham
Wow.....thanks a lot Alissa.....nice alternative !