Page 1 of 1

Pick the latest record using SORT.

Posted: Sat Sep 10, 2016 11:08 am
by John Connor
Hi,

I need help in a SORT related request. Please see below:

The input file is has records like this:

Code: Select all

XXXX8558011 
XXXX8558012 
XXXX8558013 
YYYY9559011 
YYYY9559012 
YYYY9559013 
ZZZZ7557011 
ZZZZ7557012 
ZZZZ7557013 

I want to generate an output like this. In which I wnat to keep only the latest record.

Code: Select all

XXXX8558013
YYYY9559013 
ZZZZ7557013


So, from the series:

Code: Select all

XXXX8558011 
XXXX8558012 
XXXX8558013 
In output I only want

Code: Select all

XXXX8558013 
And same for every series. Can this be done in SORT. Elese I would need a program. Please help

Re: Pick the latest record using SORT.

Posted: Sat Sep 10, 2016 6:38 pm
by Chandan Yadav
Yes..it can be done using sort..
You need to group the records on each key in INREC and assign sequence number for each group..
Sort the records using your key and sequence number descending to get the latest record first then eliminate the duplicates in next step

I don't have access to system now so can't provide the code snippet but it should work

Thanks,
Chandan

[ Post made via Android ] Image

Re: Pick the latest record using SORT.

Posted: Sat Sep 10, 2016 10:47 pm
by Magesh_j
Chandan Yadav,

We dont need group, sort, sequence number.

Assuming input is already sorted in 1,4

here is the optimal solution.

Code: Select all

//SYSIN DD *                          
  OPTION COPY                         
  OUTFIL NODETAIL,REMOVECC,           
  SECTIONS=(01,04,TRAILER3=(1,11))    
 
Thanks
Magesh

Re: Pick the latest record using SORT.

Posted: Sun Sep 11, 2016 1:28 pm
by Chandan Yadav
Ok..Thanks Mangesh..

[ Post made via Android ] Image