Syntax APPEND line_spec TO itab [SORTED BY comp] [result].
Effect This statement appends one or more rows line_spec to an internal index table itab. If itab is a standard table, you can use SORTED BY to sort the table in a specified way. Use result when appending a single row as of release 6.10 to set a reference to the appended row in the form of a field symbol or a data reference.
For the individual table types, appending is done as follows:
To standard tables, rows are appended directly and without checking the content of the internal table.
To sorted tables, rows are appended only if they correspond to the sort sequence and do not create duplicate entries with unique table key. Otherwise, an untreatable exception is triggered.
To hashed tables, no rows can be appended.
The APPEND statement sets sy-tabix to the table index of the last appended row.
Addition ... SORTED BY comp
Effect This addition is allowed only if you specify a workarea wa and if you use a standard table, where wa must be compatible to the row type of the table. You can specify component comp as shown in section Specifying Components, however, you can access only one single component and no attributes of classes using the object component selector.
The statement is executed in two steps:
Starting at the last row, the table is searched for a row, in which the value of component comp is greater than or equal to the value of component comp of wa. If such a row exists, the workarea wa is included after this row. If no such row exists, the workarea wa is included before the first row. The table index of all rows following the included rows increases by one.
If the number of rows before the statement is executed is greater than or equal to the number specified in the definition of the internal table in the INITIAL SIZE addition, the newly-created last row is deleted.
Note When using only the statement APPEND with addition SORTED BY to fill an internal table, this rule results in an internal table that contains no more than the number of rows specified in its definition after INITIAL SIZE and that is sorted in descending order by component comp (ranking).
The SORT statement should usually be used instead of APPEND SORTED BY.
Example Creating a ranking of the three flights of a connection showing the most free seats.
PARAMETERS: p_carrid TYPE sflight-carrid, p_connid TYPE sflight-connid.
DATA: BEGIN OF seats, fldate TYPE sflight-fldate, seatsocc TYPE sflight-seatsocc, seatsmax TYPE sflight-seatsmax, seatsfree TYPE sflight-seatsocc, END OF seats.
DATA seats_tab LIKE STANDARD TABLE OF seats INITIAL SIZE 3.
SELECT fldate seatsocc seatsmax FROM sflight INTO seats WHERE carrid = p_carrid AND connid = p_connid. seats-seatsfree = seats-seatsmax - seats-seatsocc. APPEND seats TO seats_tab SORTED BY seatsfree. ENDSELECT.
|
|