View previous topic :: View next topic
|
Author |
Message |
VAIDHI
New User
Joined: 14 Aug 2003 Posts: 5
|
|
|
|
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 |
|
|
vicky10001 Warnings : 1 Active User
Joined: 13 Jul 2005 Posts: 136
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
Alain Benveniste
New User
Joined: 14 Feb 2005 Posts: 88
|
|
|
|
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 |
|
|
VAIDHI
New User
Joined: 14 Aug 2003 Posts: 5
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
Alain Benveniste
New User
Joined: 14 Feb 2005 Posts: 88
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
VAIDHI
New User
Joined: 14 Aug 2003 Posts: 5
|
|
|
|
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 ..
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
|