Suimon
Suimon

Reputation: 291

Sorting dynamic table by certain field of that table

I'm having trouble with dynamic table sorting. Im reading a table via a dynamic field symbol. How can I sort this table by a certain field of that table (after the select). I know for a fact that this field is in the table, but since its dynamic I can't simply use "sort table by field".'

What are the alternatives?

Upvotes: 2

Views: 4102

Answers (1)

Florian
Florian

Reputation: 5091

You can sort

FIELD-SYMBOL <product_list> TYPE STANDARD TABLE.

by a single column with

CONSTANTS category TYPE char30 VALUE 'CATEGORY'.
SORT <product_list> BY (category).

and by multiple columns with

DATA(category_and_price) = VALUE abap_sortorder_tab( ( name = 'CATEGORY' ) 
                                                     ( name = 'PRICE'
                                                       descending = abap_true ) ).

SORT <product_list> BY (category_and_price).

as described in the ABAP Keyword Documentation article SORT itab.

Upvotes: 4

Related Questions