SORT - Extract

Short Reference

Syntax

SORT [ASCENDING|DESCENDING]
     [AS TEXT]
     [STABLE]
     [sort_key].

Extras:

1. ... ASCENDING|DESCENDING

2. ... AS TEXT

3. ... STABLE

Effect

This statement sorts the extract dataset of the program. It is prerequisite for execution of the statement that the field group header is defined using the statement FIELD-GROUPS, and is thus a component of all field groups. If no explicit sort key sort_key is specified, the extract dataset is sorted by the components of the field group header. In the standard system, numeric and byte-type components are sorted according to their value and character-type components by their binary representation (code page). For textual sorting of character-type components, you can use the addition AS TEXT.

The priority of sorting is based on the order in which the components are inserted into the field group header using INSERT. This variant of the SORT statement sorts components containing hexadecimal 0 before other entries.

The SORT statement simultaneously finalizes the structure of the extract dataset. Executing the statement EXTRACT after execution of the SORT statement leads to an untreatable exception.

Note

The SORT statement for the extract dataset is only syntactically different from the statement SORT for internal tables because no internal table is specified, but the two must not be mistaken.

Addition 1

... ASCENDING|DESCENDING

Effect

Addition 2

... AS TEXT

Effect

The addition AS TEXT specifies that text-type components are sorted according to the locale of the current text environment. If AS TEXT is not specified, text-type components are sorted according to the coding in the code page of the current text environment. For more information, see SORT for internal tables.

Notes

Addition 3

... STABLE

Effect

You can use STABLE to perform stable sorting. The relative order of lines, which is the same in the sort key, remains unchanged when sorting. Without the STABLE addition, the order is not preserved and repeated sorting of the extract dataset with the same sort key changes the order after every sort.

Example

See AT.

Exceptions

Non-Catchable Exceptions