SORT - Extract
This statement sorts the extract
dataset of the program. A prerequisite for executing the statement is that the field group
header is defined using the statement
and is therefore 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. Numeric and byte-like components are sorted according to their value and character-like components are sorted by default according to their binary representation
(code page). Here, components
containing hexadecimal 0 are placed before other entries. Text sorting for character-like components can be done using the addition
The priority of sorting is based on the order in which the components are inserted into the field group
Sorting is unstable by default, which means that the relative order of rows that do not have different
sort keys is not preserved when they are sorted, and can change when a sort is performed multiple times. The addition
STABLE can be used for stable sorting.
SORT also finalizes the structure of the extract dataset. Executing
EXTRACT after executing the statement
SORT raises an non-handleable exception.
The only difference in the syntax of the statement
SORTfor the extract dataset and the statement
SORTfor internal tables is that no internal table is specified. Regardless of this, the two should not be confused with one another.
- If components with the content hexadecimal 0 are placed before other entries, this can lead to unexpected behavior when sorting numeric data types.
In global classes, no field groups can be defined or edited. In methods of local classes of programs other than class pools, the statement
SORTis possible for globally defined field groups.
Extracts are obsolete. Internal tables are recommended instead.
DESCENDINGcan be used to specify the sort direction explicitly as ascending or descending. If neither addition is specified, the data is sorted in ascending order by default. The sort direction can be overwritten for individual components in the explicit sort key
... AS TEXT
AS TEXT specifies that
text-like components are sorted according to the
locale of the current text environment.
AS TEXT is not specified, text-like components are sorted according to
the encoding in the code page of the current text environment. For more information, see
SORT for internal tables.
STABLE can be used to perform stable sorting. The relative order of rows,
which is the same in the sort key, remains unchanged when sorting. Without the addition
the order is not stable and repeated sorting of the extract dataset with the same sort key can change the order in each sort.
Cause: A sort field with the explicit addition
AS TEXTis not text-like.
Cause: More than 50 sort criteria.
Cause: The field group
HEADERdoes not contain a sort criterion.
Cause: The field group
HEADERis not defined.
Cause: It is not possible to use
SORTin a loop through an extract dataset.
Cause: Insufficient memory space.