SORT-BY section

The SORT-BY section is an optional section that is used to specify the sort order of the extraction results of each SELECT section condition (the results of RUNMODE(EXTRACT)).

Restriction: Do note include the SORT-BY section when you are using the Universal Batch Utility with the selector analysis utility. The selector analysis utility determines the sort order and the sort order should not be changed.
SORT sections must use the following syntax:
SORT-BY:
		field1[(A|D)] field2[(A|D)] ... fieldN[(A|D)]

where the field names are a set of fields defined for the target object-type, and the value specified in the brackets specifies the SORT direction. Valid sort direction values include A (ascending) or D (descending). If no sort direction is specified after the field, then A (ascending) is used by default.

For example:
	SORT-BY:
		NAME(A) DEPARTMENT USERID(D)

In this example, the result of each WHERE clause from the SELECT section will be sorted by NAME in ascending order, then DEPARTMENT in ascending order, and then USERID in descending order. This is the equivalent of ORDER BY NAME ASC, DEPARTMENT ASC, USERID DESC in SQL.

Note: Grouped objects (such as layouts and selectors) can only be sorted by the fields of header records. This avoids possible problems during cloning procedures.
Note: For distribution lists, if the TARGET_ID field is specified in the SORT-BY section, then the SORT sub-criteria is also used to order the recipient entries of each resulting distribution list.