SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → Internal Tables →Sorted Filling
Background
The statement APPEND for attaching rows to an internal table has the addition SORTED BY. This addition can be used to fill a standard table by using sorted filling. The prerequisites are:
Once these prerequisites have been met, a ranking list is generated that contains at most the same number of rows as specified with INITIAL SIZE. This list is sorted by the component specified after SORTED BY in descending order.
Rule
Create ranking lists with unsorted filling
Do not use the SORTED BY addition of the APPEND statement to generate ranking lists. Use the SORT statement instead.
Details
If the APPEND statement is used with the SORTED BY addition, you cannot simply append rows (contrary to what the name implies). Instead, a complicated process is started that only generates a ranking list if specific prerequisites are met. Otherwise incomprehensible results are returned. In addition, it is not possible to sort by more than one column.
The SORT statement is more robust, more powerful and easier to comprehend when used in this scenario.
Bad Example
The following source code shows how to create a ranking list of the ten longest distances from a table of flight connections, by using the rule APPEND SORTED BY. This rule is no longer recommended, as described above. When declaring the ranking list table, you need to specify the addition INITIAL SIZE.
Good Example
The following source code shows how to create the same ranking list in the previous example, but using the more robust statement SORT.