When the dynamic internal table is to be sorted, because the field names in the internal table are not known, SORT table BY field1 field2 cannot be used directly...
The following method can be used to achieve: SORT table BY (sorttable)
table type: ABAP_SORTORDER_TAB
structure type: ABAP_SORTORDER
code example:
DATA:
W_IT_FIELD TYPE ABAP_SORTORDER_TAB,
W_STR_FIELD TYPE ABAP_SORTORDER.
W_STR_FIELD-NAME = 'NAME1'.
W_STR_FIELD-DESCENDING = ''.
APPEND W_STR_FIELD TO W_IT_FIELD. W_STR_FIELD
-NAME = 'KUNNR'.
W_STR_FIELD -NAME = 'KUNNR'.
W_STR_FIELD TO W_IT_FIELD.
SORT <DYN_TABLE> BY (W_IT_FIELD).
The following method can be used to achieve: SORT table BY (sorttable)
table type: ABAP_SORTORDER_TAB
structure type: ABAP_SORTORDER
code example:
DATA:
W_IT_FIELD TYPE ABAP_SORTORDER_TAB,
W_STR_FIELD TYPE ABAP_SORTORDER.
W_STR_FIELD-NAME = 'NAME1'.
W_STR_FIELD-DESCENDING = ''.
APPEND W_STR_FIELD TO W_IT_FIELD. W_STR_FIELD
-NAME = 'KUNNR'.
W_STR_FIELD -NAME = 'KUNNR'.
W_STR_FIELD TO W_IT_FIELD.
SORT <DYN_TABLE> BY (W_IT_FIELD).