SAP USE ACTUAL PARAMETERS - Guide
Get Example source ABAP code based on a different SAP table
Using System Fields as Actual Parameters
ABAP_BACKGROUND
The structure
ABAP_RULE
Never use system fields as actual parameters - especially not for passing by reference.
ABAP_DETAILS
This rule reinforces the rule
Even pass by value should be avoided for system fields. This is because a procedure might be switched to pass by reference in an enhancement process, without the consumer of the procedure being notified. The only secure method is to assign the value of a system field to a regular variable and then use this variable as the actual parameter when calling the program.
ABAP_EXAMPLE_BAD
Looking at the method
PUBLIC SECTION.
METHODS main.
PRIVATE SECTION.
METHODS do_something IMPORTING index TYPE i.
ENDCLASS.
CLASS class IMPLEMENTATION.
METHOD main.
DO 2 TIMES.
do_something( sy-index ).
ENDDO.
ENDMETHOD.
METHOD do_something.
DO 3 TIMES.
... index ... .
ENDDO.
ENDMETHOD.
ENDCLASS.>
ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD
The following source code corrects the call of the method
CLASS class IMPLEMENTATION.
METHOD main.
DATA index TYPE sy-index.
DO 2 TIMES.
index = sy-index.
do_something( index ).
ENDDO.
ENDMETHOD.
...
ENDCLASS.
...>
ABAP_EXAMPLE_END