ABAP Keyword Documentation →  ABAP − Reference →  Obsolete Language Elements →  Obsolete Extracts → 

SORT - Extract  Syntax Diagram

Short Reference

Obsolete 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. A prerequisite for executing the statement is that the field group header is defined using the FIELD-GROUPS 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-type components are sorted according to their value and character-type 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-type components can be done using 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.

Sorting is unstable by default, which means that the relative order of rows that do not have different sort keys is not retained when they are sorted, and can change when they are sorted more than once. The addition STABLE can be used for stable sorting.

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

Notes

Addition 1

... ASCENDING|DESCENDING

Effect

Addition 2

... AS TEXT

Effect

The addition AS TEXT specifies that text-like components are sorted according to the locale of the current text environment. If 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.



Addition 3

... STABLE

Effect

You can use STABLE to perform stable sorting. The relative order of rows, which is the same in the sort key, remains unchanged when sorting. Without the STABLE 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.

Example

See Extracts, Processing

Exceptions

Non-Catchable Exceptions




Continue
SORT - sort_key