Pick the latest record using SORT.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Post Reply
John Connor
New Member
Posts: 1
Joined: Fri Sep 18, 2015 10:52 am

Pick the latest record using SORT.

Post 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
Last edited by Anuj Dhawan on Sat Sep 10, 2016 8:13 pm, edited 1 time in total.
Reason: Added code tags
Chandan Yadav
Website Team
Website Team
Posts: 70
Joined: Wed Jul 31, 2013 10:19 pm

Re: Pick the latest record using SORT.

Post 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
User avatar
Magesh_j
Registered Member
Posts: 33
Joined: Sun Sep 04, 2016 8:50 pm

Re: Pick the latest record using SORT.

Post 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
Chandan Yadav
Website Team
Website Team
Posts: 70
Joined: Wed Jul 31, 2013 10:19 pm

Re: Pick the latest record using SORT.

Post by Chandan Yadav »

Ok..Thanks Mangesh..

[ Post made via Android ] Image
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “IBM DFSort, ICETOOL, ICEMAN, ICEGENER.”