2 Sort Statements and Functions
SORT BY variable name [DES] [,..., variable name [DES]]
The parameter is:
Data items used for sorting can come from any data set belonging to the thread of the current workfile. When listing the data items in the SORT BY statement, you must place them in order of their significance to the sort, not in their original set order. If an item occurs in two data sets in the thread, the item will be assumed to come from the leftmost set.
Since SORT BY and FIND handle record pointers in the data base, and other users may be modifying the data base, care should be taken when using FIND and SORT BY while the data base is opened in mode 1.
There are a couple of miscellaneous items concerning SORT BY. The first is that executing a SORT BY resets the workfile pointer (as determined by REC) to 1. The second is that if SORT BY is reading the data base via pointers in the workfile (rather than accessing the data base directly) and records in the data base have been deleted since the FIND, SORT or PRINT # that put the pointers there, then any logical workfile record which contains a pointer to a deleted data set record will be deleted. This is true only when SORT BY accesses the set in which the deletion occurred. If there is no sort item needed from that set, SORT BY will not perform the read to determine if a deletion has occurred.
Some example sequences using SORT BY are:
SORT BY Order_no$ SORT BY Product_no$,Name$ DES