GUIDELINE 6.29
Using Elements in Operand Positions
ABAP_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.
ABAP_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.
ABAP_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.
...
.... itab2[ index ] ...
...
ENDLOOP.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved