DESCENDING is initial, the sort is performed in ascending order. If
DESCENDING has the value "X" , the table is sorted in
descending order.
ASTEXT of type CHAR with length 1
for the text sorting of the current component. If ASTEXT has the
value "X", the sort is performed as with the AS TEXT addition.
This is only possible for character-like components. If ASTEXT is
initial, character-like components are sorted in accordance with their
binary representation.
If a column of otab has invalid content (that is, if NAME
contains the name of a component that does not exist or an incorrect
offset/length or if DESCENDING and ASTEXT do not contain
"X" or the initial value), this raises a handleable exception of
the class CX_SY_DYN_TABLE_ILL_COMP_VAL .
Latest notes: The addition BY (otab) cannot be combined with
BY compi .
When using the addition BY (otab) , it is not possible to use
DESCENDING or AS TEXT to specify a descending sort
direction or textual sorting for all components.
If a single parenthesized data object (dobj) is specified after
the BY addition, its data type decides whether its content is
used to specify a single component or multiple components. In either
case, no sort takes place if dobj is initial.
Example ABAP Coding Dynamic import of a database table into a dynamic
internal table and dynamic sorting of its content. The name of the
database table and the names of the columns by which the table is to be
sorted can be entered in a selection screen.
PARAMETERS dbtab TYPE c LENGTH 30.
SELECT-OPTIONS columns FOR dbtab NO INTERVALS.
DATA: otab TYPE abap_sortorder_tab,
oline TYPE abap_sortorder,
dref TYPE REF TO data.
FIELD-SYMBOLS: <(><<)>column> LIKE LINE OF columns,
<(><<)>itab> TYPE STANDARD TABLE.
TRY.
CREATE DATA dref TYPE STANDARD TABLE OF (dbtab).
ASSIGN dref->* TO <(><<)>itab>.
CATCH cx_sy_create_data_error.
MESSAGE 'Wrong data type!' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
TRY.
SELECT *
FROM (dbtab)
INTO TABLE <(><<)>itab>.
CATCH cx_sy_dynamic_osql_semantics.
MESSAGE 'Wrong database table!' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
LOOP AT columns ASSIGNING <(><<)>column>.
oline-name = <(><<)>column>-low.
APPEND oline TO otab.
ENDLOOP.
TRY.
SORT <(><<)>itab> BY (otab).
CATCH cx_sy_dyn_table_ill_comp_val.
MESSAGE 'Wrong column name!' TYPE 'I' DISPLAY LIKE 'E'.
LEAVE PROGRAM.
ENDTRY.
ABAP_ADDITION_6 ... BY expr
What does it do? The addition BY expr can be used to specify an
expression or a functional method call expr whose result is an
internal table with the same type and content as in the preceding
addition BY (otab) . expr is a
general expression position .
The behavior is the same as when specifying a parenthesized internal
table directly.
Latest notes: Parentheses cannot be placed around expr .
Example ABAP Coding See Sorting Internal Tables
Dynamically .
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved