When you read table entries using READ or in a LOOP, you can assign them to a field symbol using the addition
The field symbol
Remember when you access internal tables using field symbols that you must not change the contents of the key fields of sorted or hashed tables. If you try to assign a new value to a key field using a field symbol, a runtime error occurs. Note that you cannot use the SUM statement with field symbols, since the statement is always applied to work areas.
Advantages of Field Symbols
When you read from an internal table, there are no overheads for copying the table line to the work area. When you change an internal table with the MODIFY statement, you must first fill a work area with values, and then assign them to the internal table. If you work with field symbols instead, you do not have this overhead. This can improve performance if you have large or complex internal tables. It also makes it easier to process nested internal tables.
Overheads of READ
Note that internal overheads arise when you access internal tables using field symbols. After a READ statement with a field symbol, the system has to register the assignment. When you delete a table line to which a field symbol is pointing, the system also has to unassign the field symbol to prevent it from pointing to an undefined area.
When you read individual table lines, it is worth using field symbols with the READ statement for tables with a line width of 1000 bytes or more. If you also change the line using the MODIFY statement, using field symbols is worthwhile from a line width of 100 bytes onwards.
Overheads of LOOP
To minimize the overheads incurred by using field symbols in loop processing, the system does not register the assignment of each current line to the field symbol. Instead, it registers a general assignment between a line of the table and the field symbol. When the loop is finished, the line processed in the last loop pass is assigned to the field symbol.
Consequently, it is worth using field symbols in a LOOP when the internal table has as few as 10 lines. However, it is not possible to reassign the field symbol to another field or unassign it altogether within the loop. If you include the statements ASSIGN, UNASSIGN, or the ASSIGNING addition for the same field symbol within the loop block, a runtime error occurs.
DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.
DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.
DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING
READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING
DELETE ITAB INDEX 3.
LOOP AT ITAB ASSIGNING
The output is:
The example fills a sorted table ITAB with 4 lines. The second line is assigned to the field symbol