Internal tables can be read by accessing individual lines
TABLE) or sequentially (
LOOP AT). In both cases, you can define one of the following output behaviors:
INTOaddition copies the line content to an appropriate data object. The
ASSIGNINGaddition assigns the read line to a field symbol, which enables you to directly address the line.
REFERENCE INTOaddition sets a data reference to the read line.
As well as for exports, the
additions can also be used for the
MODIFY statements, where they generate references to the processed line.
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.
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
ASSIGNINGaddition. This allows direct access to the line using the value semantics and saves you having to use a
MODIFYoperation later on.
- If you require a reference to the read line that can be processed using reference semantics, use the
- 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
REFERENCE INTOinstead of
INTO. The use is the determining factor for selecting which of the two you should use.
INTO is faster (at least for the
than configuring the administration that is required for dynamic access. For the
statement, these costs are generated only once, so that using
REFERENCE INTO is always recommended above a certain number of lines. In
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
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.
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.
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> = ...