sapdev logo background
sapdev logo sapdev logo
Comments

ABAP SORT EXTRACT Statement syntax, information and example SAP source code



Return to Statement index



SORT - Extract

Short Reference

ABAP Syntax(Obsolete) SORT [ASCENDING|DESCENDING]
[AS TEXT]
[STABLE]
[ sort_key ].

ABAP_ADDITIONS:
1 ... ASCENDING|DESCENDING
2 ... AS TEXT
3 ... STABLE

What does it do? 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.

Latest notes: The SORT statement for the extract dataset is syntactically different to the SORT statement for internal tables , the only difference being that no internal table is specified, but 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 numerical 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
SORT statement is possible for globally defined field groups.
Extracts are obsolete. Internal tables are recommended instead.

ABAP_ADDITION_1 ... ASCENDING|DESCENDING

What does it do? The addition ASCENDING or DESCENDING can 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 sort_key .

ABAP_ADDITION_2 ... AS TEXT

What does it do? 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 .


ABAP_ADDITION_3 ... STABLE

What does it do? 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 ABAP Coding See Extracts, Processing



Runtime Exceptions
Non-catchable Exceptions

Reason for error: A sort field with the explicit addition AS TEXT is not text-like.
Runtime error: SORT_AS_TEXT_EX_BAD_TYPE
Reason for error: More than 50 sort criteria.
Runtime error: SORT_EXTRACT_TOO_MANY_FIELDS
Reason for error: The field group HEADER does not contain a sort criterion.
Runtime error: SORT_FIELD_NOT_IN_HEADER
Reason for error: The field group HEADER is not defined.
Runtime error: SORT_NO_HEADER
Reason for error: It is not possible to use SORT in a loop through an extract dataset.
Runtime error: SORT_WITHIN_LOOP
Reason for error: Insufficient memory space.
Runtime error: SORT_EXTRACT_INDEX_NO_ROLL

Reason for error: Sort Mode weder 'E' noch 'I'.
Runtime error: SORT_ILLEGAL_MODE
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




SORT
SORT_ITAB




comments powered by Disqus