z/OS DFSORT Application Programming Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Example 3

z/OS DFSORT Application Programming Guide
SC23-6878-00

SUBSET FROM(IN3) TO(OUT4) KEEP OUTPUT - 
  LAST(5) USING(CTL1)

This example illustrates how you can keep the last 5 sorted records.

The CTL1CNTL data set contains:
  SORT FIELDS=(1,15,CH,A)
The input records look like this:
Psychology
Biology
Russian
French
History
Geography
Calculus
Geometry
Algebra
Greek
Astronomy
Latin
We want to sort the records by the CH field in positions 1-15 and keep the last 5 sorted records. We use KEEP, OUTPUT and LAST(5) to keep the last 5 output records. We use the SORT statement to sort the records before they are output. After the SORT statement is executed, the intermediate records look like this:
Algebra
Astronomy
Biology
Calculus
French
Geography
Geometry
Greek
History
Latin
Psychology
Russian
After the SUBSET operator is executed, the final output records look like this:
Greek
History
Latin
Psychology
Russian

Note that we could use TRAILER(5) instead of LAST(5).

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014