ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → Internal Tables
Output Behavior
Other versions: 7.31 | 7.40 | 7.54
Background
Internal tables can be read by accessing individual lines
(READ
TABLE
) or sequentially (LOOP AT
). In both cases, you can define one of the following output behaviors:
- The
INTO
addition copies the line content to an appropriate data object. TheASSIGNING
addition assigns the read line to a field symbol, which enables you to directly address the line.
- The
REFERENCE INTO
addition sets a data reference to the read line.
As well as for exports, the ASSIGNING
and REFERENCE INTO
additions can also be used for the APPEND
, COLLECT
,
INSERT
, and MODIFY
statements, where they generate references to the processed line.
Rule
Choose appropriate output behavior
When reading lines of internal tables, select an appropriate output behavior. The rule of thumb is:
- Copy to a work area if the line type is narrow and the read line is not to be modified.
- Assign to a field symbol if the line type is wide or deep and the read line is to be modified.
- Set a data reference if the line type is wide or deep and a reference to the read line is to be passed on.
Details
The criteria for selecting the output behavior are the processing speed, on the one hand, and what will be done with the read line, on the other hand:
- If the content of the read line is to be modified, you should usually use the
ASSIGNING
addition. This allows direct access to the line using the value semantics and saves you having to use aMODIFY
operation later on.
- If you require a reference to the read line that can be processed using reference semantics, use the
REFERENCE INTO
addition.
- If the content of the read line is not to be modified, you can use any of these procedures. As regards
performance, the line type of the table is important here. If the table line is wide or contains deep
components (for example, strings or other tables), read processes are usually faster if you use
ASSIGNING
orREFERENCE INTO
instead ofINTO
. The use is the determining factor for selecting which of the two you should use.
INTO
is faster (at least for the READ
statement)
than configuring the administration that is required for dynamic access. For the LOOP
statement, these costs are generated only once, so that using ASSIGNING
or
REFERENCE INTO
is always recommended above a certain number of lines. In
contrast, INTO
should always be used if you want to change the target area without this affecting the internal table.
Besides the processing speed, it is also important that the source code can be understood. If you adhere
to the recommendations mentioned, reading a table with the ASSIGNING
addition
(but also REFERENCE INTO
) indicates to the reader that the table content
is potentially changed. Reading a table with the INTO
addition, on the other hand, indicates that the table will not be modified.
Bad example
The following source code shows the assignment of lines of an internal table to a work area with the
aim of modifying the read lines. For this modification, however, an additional statement, MODIFY
, is required, and two unnecessary copy processes take place for each loop pass.
LOOP AT itab INTO wa.
...
wa = ...
MODIFY itab FROM wa.
ENDLOOP.
Good example
The following source code corrects the above example; here, a field symbol is used for direct access to modify the read lines. No unnecessary copy costs are incurred.
LOOP AT itab ASSIGNING <fs>.
...
<fs> = ...
ENDLOOP.