ABAP Keyword Documentation → ABAP Programming Guidelines → Robust ABAP → System Fields
Access
Other versions: 7.31 | 7.40 | 7.54
Background
The system fields are supplied with values by the ABAP runtime environment. In a program, however, they behave like normal variables. You can assign values to these fields using the ABAP program. This is because both the ABAP kernel and the ABAP components of the ABAP runtime environment have write access to system fields.
Rule
Do not write to system fields
Only use read access and never write access to access system fields in an application program.
Details
The values of system fields are usually vital for correct program execution. Therefore, write access to system fields carries a lot of risk. Write operations in system fields can lead to a loss of important information, which can prevent programs from running correctly. Therefore, you cannot overwrite system fields to change the execution of the program or use the fields to replace explicitly defined variables.
In addition, you cannot misuse system fields as implicit output parameters of procedures, irrespective of whether the fields have been explicitly set within the procedure (due to a prohibited write access or as the result of an executed statement).
Exception
The only system fields where it was permitted to change the field content (in an application program) belong to classical list processing. This should no longer be used.
Bad example
The following source code shows a write access to the sy-subrc
system field,
which occurs frequently. This write access is not harmful but it also is not beneficial: sy-subrc
is always set to zero when a function module is called and only adopts a different value by handling a classical exception. Therefore, the statement is redundant.
sy-subrc = 4.
CALL FUNCTION ...
...
EXCEPTIONS ...
CASE sy-subrc.
...
Good example
The source code below omits the write access shown above.
CALL FUNCTION...
...
EXCEPTIONS ...
CASE sy-subrc.
...