Skip to content

ABAP Keyword Documentation →  ABAP Programming Guidelines →  Robust ABAP →  System Fields 

Return Value

Other versions: 7.31 | 7.40 | 7.54

Background

The most prominent system field should be the return value sy-subrc. This indicates the successful execution of an ABAP statement or, if you are using classic exceptions, a procedure. A return value of 0 usually means that the execution was successful.

Rule

return valuesy-subrc

Evaluate the return value sy-subrc after every ABAP statement that sets the value according to the documentation. However, sy-subrc should never be set after statements are executed for which the setting of a return value is not documented.

Details

The system field sy-subrc indicates whether a statement was successfully executed. If the execution was not successful, the program should usually react accordingly. If this does not happen, the program's response will probably be unexpected.

This rule is a specialization of the more general rule evaluate system fields in the correct place. It is listed here again separately due to the prominent role of the return value sy-subrc. The system field sy-subrc must always be evaluated immediately and, if necessary, assigned to a help variable. An evaluation cannot occur after statements that set sy-subrc not defined, because otherwise wrong conclusions could easily be drawn.

Exception

If a handling action seems unnecessary because, in the developer's opinion, the statement is always executed successfully, you should at least save and document your assumption using an assertion.

Bad example

The following source code shows how further processing of data is performed using the work area of a SELECT command, without a request from sy-subrc. However, the content of wa is usually undefined here, if a request from sy-subrc does not guarantee that database access will be successful.

SELECT ...
       INTO wa
       ...
... "work with wa

Good example

The following source code corrects the above example. This means the successful execution of the SELECT statement is checked.

SELECT ...
       INTO wa
       ...
IF sy-subrc <> 0.
  ...
ENDIF
... "work with wa