BUT you CANNOT define the order (ascending or descending) dynamically:

SORT sflight by (l_fieldname) (l_order). <<==-- This is impossible in ABAP.

Now, with the new tree controlÂ­, when you want to give fully customizable tree, ou need to dynamically set the order in the sort command.

The first method is by using a CREATE SUBROUTINE POOL with your sort. Each time you will run the program, this subroutine will be recompiled. This is VERY slow and we should avoid using this command whenever it's possible.

The second method is a simple trick that have no major impact on performance. You duplicate each fields you want to sort, 1 copy for ascending and 1 for descending. You move the fieldname only in 1 of those fields depending on what order you want.

* The order must be "ASC" or "DES" or space, any other value is rejectedl_flag_not_asc_des = 'X'.CHECK ( s_ord1 = 'ASC' OR s_ord1 = 'DES' OR s_ord1 IS INITIAL ) AND ( s_ord2 = 'ASC' OR s_ord2 = 'DES' OR s_ord2 IS INITIAL ) AND ( s_ord3 = 'ASC' OR s_ord3 = 'DES' OR s_ord3 IS INITIAL ) AND ( s_ord4 = 'ASC' OR s_ord4 = 'DES' OR s_ord4 IS INITIAL ) AND ( s_ord5 = 'ASC' OR s_ord5 = 'DES' OR s_ord5 IS INITIAL ).CLEAR l_flag_not_asc_des.

* the field name must be = "FIELD1, 2, 3, 4 or 5", any other value is rejectedl_flag_invalid_field = 'X'.CHECK 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field1 AND 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field2 AND 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field3 AND 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field4 AND 'FIELD1FIELD2FIELD3FIELD4FIELD5' CS s_field5.CLEAR l_flag_invalid_field.

* for a certain field, if the user ask descending order, the name of this field is * moved in l_field_des1 AND it's important that l_field_asc1 remain empty.IF s_field1 IS NOT INITIAL. IF s_ord1 = 'ASC'. l_field_asc1 = s_field1. ELSE. l_field_des1 = s_field1. ENDIF.ENDIF.

* EACH field is used twice in the sort with different name for ascending and descending. 1 of the * 2 fields will be empty and the sort will ignore it.SORT lt_fields BY (l_field_asc1) ASCENDING (l_field_des1) DESCENDING (l_field_asc2) ASCENDING (l_field_des2) DESCENDING (l_field_asc3) ASCENDING (l_field_des3) DESCENDING (l_field_asc4) ASCENDING (l_field_des4) DESCENDING (l_field_asc5) ASCENDING (l_field_des5) DESCENDING.