基于动态内表排序引用ABAP_SORTORDER_TAB。主要用于动态内表排序或内表动态字段排序。
DATA:
W_IT_FIELD TYPE ABAP_SORTORDER_TAB, "引用sorttab参数
W_STR_FIELD TYPE ABAP_SORTORDER.
W_STR_FIELD-NAME = ‘SLEVEL’. "定义排序字段
W_STR_FIELD-DESCENDING = ‘’.
APPEND W_STR_FIELD TO W_IT_FIELD.
W_STR_FIELD-NAME = ‘ZCOLOR’.
W_STR_FIELD-DESCENDING = ‘’.
APPEND W_STR_FIELD TO W_IT_FIELD.
W_STR_FIELD-NAME = ‘SORTF’.
W_STR_FIELD-DESCENDING = ‘’.
APPEND W_STR_FIELD TO W_IT_FIELD.
”SORT ITAB BY (W_IT_FIELD). ”内表排序示例
SORT BY (W_IT_FIELD). “动态内表排序
*& 对动态内表排序
DATA: lt_sort_fields TYPE ABAP_SORTORDER_TAB.
lt_sort_fields = VALUE #(
( name = 'EBELN' )
( name = 'EBELP' )
( name = 'MBLNR' )
( name = 'MJAHR' )
( name = 'ZEILE' ) ).
sort <fs_itab> by (lt_sort_fields).