Sorting Internal Tables in ABAP - Sorting by Another Sort Key
Details
- Details
- Category: ABAP
- Created on Thursday, 15 November 2012 08:37
- Last Updated on Thursday, 15 November 2012 08:43
- Published on Thursday, 15 November 2012 08:37
- Written by Administrator
- Hits: 35261
Sorting by Another Sort key
If you have an internal table with a structured line type that you want sort by a different key, you can specify the key in the SORT statement:
SORT <itab> [ASCENDING|DESCENDING] [AS TEXT] [STABLE]
BY <f1> [ASCENDING|DESCENDING] [AS TEXT]
...
<fn> [ASCENDING|DESCENDING] [AS TEXT].
The table is now sorted by the specified components <f 1 > ... <f n > instead of by the table key. The number of sort fields is limited to 250. The sort order depends on the sequence of the fields <f i >. The sort sequence specified before BY applies to all fields. The sort sequence after a field applies only to that column of the table.
You can specify a sort field dynamically by specifying (<f>) instead of <f i >. The contents of the field <f> determines the name of the sort field. If <f> is empty when the statement is executed, the field is ignored in the sort. If it contains an invalid component name, a runtime error occurs.