Discussion Locked

Print last n records from DFSORT/ICEMAN

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Is there an operator in IBM's DFSORT or ICEMAN that will print or dump the last n records of a dataset? (e.g. The last 10 records of a dataset).

1 reply

by chris.bonner

I've done this in multiple steps, when I don't know how many records there are.

Step 1. SORT FIELDS=COPY the file, appending sequence numbers to the end of each record. I.E., OUTREC FIELDS=(1,80,SEQNUM,8,ZD...

Step 2. sort the output of step 1 in descending order of the sequence number you appended.

Step 3. sort copy the output of step 2, with a STOPAFT=10.

Step 4. sort the output of step 3, ascending order of sequence number, stripping off the sequence number.

You should be left with the last ten records of the file, in the same order as originally.

This discussion is closed to new replies.