AS ABAP Release 758, ©Copyright 2024 SAP SE. All rights reserved.
ABAP - Keyword Documentation → ABAP - Programming Language → Processing Internal Data → Internal Tables (itab) → itab - Processing Statements → APPEND →
APPEND, line_spec
Syntax
... wa
| {INITIAL LINE}
| {LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY
keyname]} ...
1. ... wa
2. ... INITIAL LINE
3. ... LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY keyname]
Effect
Either a work area wa, an initial line INITIAL LINE, or multiple lines of an internal table jtab can be appended.
... wa
Effect
A new line is appended to which the content of the work area wa is assigned. wa is a general expression position. wa may be incompatible with the line type of the internal table and, if necessary, is converted to the line type in accordance with the conversion rules. If a conversion error occurs here, the exception cannot be handled using CX_SY_CONVERSION_ERROR and the associated runtime error occurs instead. If an arithmetic expression is specified for wa, the line type of the internal table is used to determine the calculation type.
Hints
Example
Appending of square numbers to a sorted table with elementary line type.
DATA: int TYPE i,
itab LIKE SORTED TABLE OF int
WITH UNIQUE KEY table_line.
DO 10 TIMES.
int = sy-index ** 2.
APPEND int TO itab.
ENDDO.
... INITIAL LINE
Effect
A new line is appended in which every component contains the type-dependent initial value.
Example
Appending of an initial line that simultaneously is linked to a field symbol using the addition ASSIGNING. This means that initial lines can be processed directly.
DATA itab TYPE TABLE OF spfli.
FIELD-SYMBOLS <line> LIKE LINE OF itab.
APPEND INITIAL LINE TO itab ASSIGNING <line>.
<line>-carrid = '...'.
...
... LINES OF jtab [FROM idx1] [TO idx2] [STEP n] [USING KEY keyname]
Effect
The lines of an internal table jtab are appended as a block. jtab is a functional operand position.
The lines to be inserted are taken sequentially from the table jtab. The line type of jtab can be incompatible with the line type of the internal table itab and is converted to the line type of the target table, if necessary, in accordance with the conversion rules. If a conversion error occurs here, the exception cannot be handled using CX_SY_CONVERSION_ERROR and the associated runtime error occurs instead.
The order in which the lines are taken is the same as for the statement LOOP and can also be affected by specifying a table key keyname after USING KEY. The additions FROM idx1 and TO idx2 have the same syntax and effect as for LOOP with respect to jtab. STEP n has the same syntax and effect as for LOOP with the exception that the value of n must be positive.
If a conflict with existing primary or secondary table keys occurs, this always raises an uncatchable exception when multiple lines are appended from an internal table.
Hint
When a standard table is constructed, the constructor operators NEW and VALUE can also append multiple lines from a table to the target table using LINES OF.
Example
Appending of the lines of an internal table itab2 to the standard table itab1.
SELECT *
FROM spfli
WHERE carrid = 'LH'
INTO TABLE @DATA(itab1).
SELECT *
FROM spfli
WHERE carrid = 'UA'
INTO TABLE @FINAL(itab2).
APPEND LINES OF itab2 TO itab1.
Example
Appending of the lines of an internal table jtab to the standard table itab with the additions FROM, TO, and STEP.
DATA: itab TYPE STANDARD TABLE OF i,
jtab LIKE itab.
itab = VALUE #( FOR i = 1 UNTIL i > 10 ( i ) ).
jtab = VALUE #( FOR j = 11 UNTIL j > 20 ( j ) ).
APPEND LINES OF jtab FROM 1 TO 5 STEP 2 TO itab.