Search for
Login | Username Password Forgot? | Email: | Create Account
Education | Entries: 275 | Views: 532 | Modified: 4 hours ago | | Add to My Feeds
Report

When you read table entries using READ or in a LOOP, you can assign them to a field symbol using the addition

... ASSIGNING

The field symbol points directly to the assigned line in memory. Unlike work areas, in which the contents of the line are only available indirectly, field symbols allow you to read and change table entries directly.

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.

Example


DATA: BEGIN OF LINE,
COL1 TYPE I,
COL2 TYPE I,
END OF LINE.

DATA ITAB LIKE SORTED TABLE OF LINE WITH UNIQUE KEY COL1.

FIELD-SYMBOLS LIKE LINE OF ITAB.

DO 4 TIMES.
LINE-COL1 = SY-INDEX.
LINE-COL2 = SY-INDEX ** 2.
APPEND LINE TO ITAB.
ENDDO.

READ TABLE ITAB WITH TABLE KEY COL1 = 2 ASSIGNING .
-COL2 = 100.

READ TABLE ITAB WITH TABLE KEY COL1 = 3 ASSIGNING .
DELETE ITAB INDEX 3.

IF IS ASSIGNED.
WRITE ' is assigned!'.
ENDIF.

LOOP AT ITAB ASSIGNING .
WRITE: / -COL1, -COL2.
ENDLOOP.

The output is:

1 1

2 100

4 16

The example fills a sorted table ITAB with 4 lines. The second line is assigned to the field symbol (which has the same type), and modified using it. The third line is assigned to and then deleted. Consequently, the logical expression in the IF statement is untrue. is used to display the table lines in the LOOP. Afterwards, it points to the third line of the table.


More from SAP e-rec

SAP Reports 09 Mar 31

^ Back To Top