SORT
The SORT statement sorts the record pointers contained in a workfile.
The SORT statement must also specify the sort keys and their usage
(ascending/descending). Since the record pointers must be sorted by the
data to which they point, the database must be accessed once more.
However, only the records whose pointers are in the workfile need to be
read. The order in which the data sets are to be read is governed by the
thread list. Sort keys specified must be defined in an IN DATASET
statement. After sorting is done, the workfile contains the same record
pointers but they are sorted.
The SEARCH and SORT statements are related, yet independent statements.
SEARCH can be done before or after SORT. If no SEARCH has been done when
SORT is executed, the workfile is empty, and a SEARCH ALL is issued
first. In other words, the SORT statement does an implicit SEARCH ALL if
it is executed before a SEARCH statement. On the other hand, if the
SEARCH is done after the SORT, then all the record pointers contained in
the workfile are searched. The workfile may then contain fewer records
after a SEARCH because the record pointers to any data records that do
not satisfy the SEARCH condition are deleted from the workfile.
Syntax
SORT USING line_id; key_list
Parameters
line_id Line label or line number that identifies the line on
which the THREAD IS statement is defined.
key_list List of variables. The DES keyword can follow each
variable in the list. Specifying DES means that the
data is sorted in descending order. If not specified,
data are sorted in ascending order. Whole arrays are
not allowed.
Examples
600 SORT USING 300; A DES, B !Sorts using THREAD statement on line 300