ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → System Fields
Using Elements in Operand Positions
Other versions: 7.31 | 7.40 | 7.54
Background
Statements that modify the content of system fields generally evaulate the operands first and then set the system fields. In some complex statements, however, a system field could be set first, before all operand positions are evaluated.
Rule
Do not use system fields in statements that set the fields
For reasons of robustness, do not use system fields as operands of statements that themselves set these system fields.
Details
A program does not always define whether a particular system field is set in a statement before or after an operand is evaluated. This means that, to reduce risks and to make the program easier to read, the content of a system field should always be copied to an auxiliary variable and only this copy should be used within the statement in question.
Note
Also take note of how functional methods are used in operand positions. These methods also modify important system fields. Also be careful here when using system fields in operand positions of the same statement.
Bad example
The following source code shows how the system field sy-tabix
is used in
a READ
statement that sets the system field itself. The case shown here does
not itself present any difficulties, however we still recommend you follow the rule above, not least to make the code more readable.
LOOP AT itab1 ... WHERE ...
...
READ TABLE itab2 ... INDEX sy-tabix.
...
ENDLOOP.
Good example
The following source code makes the example above more robust by assigning the value of the system field sy-tabix
to an auxiliary variable before it is used.
LOOP AT itab1 ... WHERE ...
index = sy-tabix.
...
READ TABLE itab2 ... INDEX index.
...
ENDLOOP.