ABAP Keyword Documentation →  ABAP Programming Guidelines →  Robust ABAP →  Internal Tables → 

Output Behavior

Background

Internal tables can be read by accessing individual rows (using READ TABLE or table expressions) or sequentially (using LOOP AT). In both cases, the following output behavior can be defined by using the statements with the following additions:

In the case of table expressions, the output behavior is controlled by the category of the result.

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 create references to the row being edited.

Rule

Choose appropriate output behavior

When reading rows of internal tables, select an appropriate output behavior. The rule of thumb is:

Details

The criteria for selecting the output behavior are the processing speed, on the one hand, and what is to be done with the read row, on the other hand:

When working with tables whose rows are flat and do not occupy more than approximately 1KB, copying with INTO is faster (at least for the READ statement) than configuring the administration that is required for dynamic access. For the statement LOOP, these costs are incurred only once, so that using ASSIGNING or REFERENCE INTO is always recommended above a certain number of rows. In contrast, INTO should always be used if the target area is to be modified without this affecting the internal table.

Besides the processing speed, it is also important that the source code can be understood. If the recommendations mentioned are kept, reading a table with the addition ASSIGNING (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.

For table expressions, the information here applies to the selection of the appropriate result.

Bad example

The following source code shows the assignment of rows of an internal table to a work area with the aim of modifying the read rows. 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 rows. No unnecessary copy costs are incurred.

LOOP AT itab ASSIGNING <fs>.
   ...
   <fs> = ...
ENDLOOP.