Copy only the last record from input to output.

IBM's Sort Product, ICETOOL, ICEMAN and ICEGENER.
Post Reply
Ameya C
New Member
Posts: 2
Joined: Mon Sep 22, 2014 10:17 pm

Copy only the last record from input to output.

Post by Ameya C »

Hi,

I have a VBS file from which I need to get the first record and last record in the output file. I used STOPAFT=1 but it helps to get the first record. But I am not sure how to get the last record only.

Can you please tell me how to get only the last record from a VBS file using SORT.

Thanks,
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Copy only the last record from input to output.

Post by William Collins »

Use JOINKEYS with the same dataset. JOIN UNPAIRED,F1,F2,ONLY. REFORMAT statement including the entire F1 and F2 and the match-markers (?). Depending on value of match-marker, BUILD correct output.The key for the JOINKEYS is an extension to the record containing a sequence number (large enough to be unique for each record in the file). This will be set in the JNFnCNTL files. For one sequence number use START=0, for the other use START=1.
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Copy only the last record from input to output.

Post by William Collins »

Or, for less code and excitement, look at ICETOOL's SUBSET operator.
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Copy only the last record from input to output.

Post by zprogrammer »

Or even OUTFIL NODETAIL with TRAILER :)
zprogrammer
William Collins
Global Moderator
Global Moderator
Posts: 490
Joined: Sun Aug 25, 2013 7:24 pm

Re: Copy only the last record from input to output.

Post by William Collins »

Yes, like this:

Code: Select all

  OUTFIL HEADER1=(1,80),
         TRAILER1=(1,80),
         REMOVECC,
         NODETAIL
The other two are more flexible, as different numbers of "first" and "last" records could be processed (or ignored).
zprogrammer
Global Moderator
Global Moderator
Posts: 588
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars

Re: Copy only the last record from input to output.

Post by zprogrammer »

Ok Thanks William :)
zprogrammer
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.”