Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

TO copy only last record using SORT

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
VAIDHI

New User


Joined: 14 Aug 2003
Posts: 5

PostPosted: Mon Sep 04, 2006 7:23 pm    Post subject: TO copy only last record using SORT
Reply with quote

Hi,

How to copy only the last record from an i/p file to an o/p file using SORT utility? Any options there?
Back to top
View user's profile Send private message

vicky10001
Warnings : 1

Active User


Joined: 13 Jul 2005
Posts: 136

PostPosted: Mon Sep 04, 2006 7:42 pm    Post subject:
Reply with quote

If u know record count then you use as below keyword

SKIPREC=n
causes sort to skip over 'n' records in the input file before
starting a sorting or copying operation.

STOPAFT=n
causes sort to stop after 'n' records in the input file have
been sorted or copied.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Mon Sep 04, 2006 9:37 pm    Post subject:
Reply with quote

You can use a DFSORT job like the following to do what you asked for. I assumed your input file has RECFM=FB and LRECL=80, but the job can be changed appropriately for other attributes.

Code:

//S1    EXEC  PGM=ICEMAN                       
//SYSOUT    DD  SYSOUT=*                       
//SORTIN DD DSN=...  input file (FB/80)                                 
//SORTOUT DD DSN=...  output file (FB/80)                         
//SYSIN    DD    *
* Add seqnum                             
  INREC OVERLAY=(81:SEQNUM,8,ZD)               
* Sort on seqnum in descending order
  SORT FIELDS=(81,8,ZD,D)             
* Get top record = last.  Remove seqnum.         
  OUTFIL ENDREC=1,BUILD=(1,80)               
/*   
Back to top
View user's profile Send private message
Alain Benveniste

New User


Joined: 14 Feb 2005
Posts: 88

PostPosted: Tue Sep 05, 2006 1:33 am    Post subject: Re: TO copy only last record using SORT
Reply with quote

or this way...

Code:

//STEP0001 EXEC PGM=ICETOOL
//TOOLMSG  DD SYSOUT=*
//DFSMSG   DD SYSOUT=*
//TOOLIN   DD *
  SELECT FROM(IN) TO(OUTX) ON(81,1,ZD) USING(ICE0) LAST
/*
//IN       DD *
KEY1 DATE5
KEY1 DATE6
KEY2 DATE1
KEY3 DATE2
KEY3 DATE3
/*
//OUTX     DD SYSOUT=*
//ICE0CNTL DD *
  INREC OVERLAY=(81:C'0')
  SORT FIELDS=COPY
  OUTFIL FNAMES=OUTX,
         OUTREC=(1,80)

alain
Back to top
View user's profile Send private message
VAIDHI

New User


Joined: 14 Aug 2003
Posts: 5

PostPosted: Tue Sep 05, 2006 12:06 pm    Post subject: Re: TO copy only last record using SORT
Reply with quote

Thanks to all for all ur suggestions.

I have some 50 files which contains lakhs and lakhs of records.
I feel adding sequence number then sorting and geting the last record will consume time.
I will go for file-aid which is very much handy for this requirement(reading the last record directly), rather than dfsort.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Tue Sep 05, 2006 9:31 pm    Post subject:
Reply with quote

VAIDHI,

If you already knew how to do this with FileAid and prefer it, why did you waste our time by asking for a sort solution?
Back to top
View user's profile Send private message
Alain Benveniste

New User


Joined: 14 Feb 2005
Posts: 88

PostPosted: Wed Sep 06, 2006 1:05 am    Post subject:
Reply with quote

Code:

I feel adding sequence number then sorting and geting the last record will consume time.

That's exactly what my jcl doesn't do.

Alain
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Sep 06, 2006 3:12 am    Post subject:
Reply with quote

Alain's DFSORT/ICETOOL method uses COPY with an E35 (via SELECT), whereas my method uses SORT without an E35. I suspect Alain's method is faster but YMMV. But both DFSORT methods read all of the records to get to the last one. If FileAid does a read backwards to read only one record (the last one), then one would assume it would be faster. Of course, if FileAid actually also reads all of the records to get to the last one, then one of the DFSORT methods may actually be faster. But VAIDHI has already decided that FileAid is faster without actually trying anything, so I don't know why he asked for a sort solution in the first place.
Back to top
View user's profile Send private message
VAIDHI

New User


Joined: 14 Aug 2003
Posts: 5

PostPosted: Thu Sep 07, 2006 2:44 pm    Post subject: Re: TO copy only last record using SORT
Reply with quote

All the jobs in my system uses SORT utility. I couldnt find FILEAID anywhere.. So i just want to find out whether any option is there in SORT utility to read backward .. Thats y i asked you buddies icon_smile.gif ..

As i already said my input files contains lakhs and lakhs of records.. So the best feasible solution is FILEAID which you have also confirmed.

Thanks Guys
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Thu Sep 07, 2006 9:24 pm    Post subject:
Reply with quote

Quote:
So i just want to find out whether any option is there in SORT utility to read backward


Well, you could have just asked that directly instead of asking about copying the last record.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts HALDB data refresh/copy from producti... vineetanand2007 IMS DB/DC 1 Mon Jan 02, 2017 11:16 am
No new posts Copy RECFM =VB TO FB file with RECL =... sahil41352 DFSORT/ICETOOL 3 Wed Dec 28, 2016 11:29 pm
No new posts syncsort: copy lines after the keyword shreya19 SYNCSORT 7 Fri Dec 02, 2016 9:47 am
No new posts Limit duplicate records in the SORT pshongal SYNCSORT 6 Mon Nov 21, 2016 12:54 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us