2 Sort Statements and Functions

The SORT BY Statement

The SORT BY statement generates pointers accessing data in a specified order.

SORT BY variable name [DES] [,..., variable name [DES]]

The parameter is:

variable name
An Eloquence variable linked via the IN DATA SET statement to an item appearing in one of the data sets in the thread. Substrings are not allowed.
Sorting can occur on up to ten data items. If an order cannot be determined from the first data item, subsequent data items can be specified to determine the order. If no order can be found, the order for those records will be determined by their record pointer value(s) in the data set(s). The specified data is sorted in reverse order by specifying DES. Each data item listed can be sorted in either order.

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

Eloquence Sort Manual - 19 DEC 2002