What Is the Use of SY-SUBRC?

SY-SUBRC is a system component which contains return value which is set by ABAP statements. The return value (an integer value like 0, 4, 8, …) is used to determine the execution status (successful, error, warning and among others) of an ABAP statement.

Generally, when the SY-SUBRC equals to \’0\’ means that the ABAP statement has been executed successfully. If the value is other than \’0\’ means that the statement has raised an error or warning.

\’SUBRC\’ can be found in the structure \’SYST\’.

Please find below some main examples of the of the return value of the statement \’SY-SUBRC\’:

  • Statement \’SELECT\’ sets SY-SUBRC to 0 if at least one line was retrievedelse SY-SUBRC sets to 4/8.
  • For function module the statement \’CALL FUNCTION\’ sets SY-SUBRC based on the exceptions declared in the FM. Same applies for \’CALL METHOD\’.
  • Statement \’AUTHORITY-CHECK\’ sets SY-SUBRC to 0 if the user has the required authorization else SY-SUBRC sets to 4, 8, 12, 16, 24, 28, 32, or 36 depending on the cause of the authorization failure.
  • Statement \’OPEN DATASET\’ sets SY-SUBRC to 0 if the file could be opened, else SY-SUBRC sets to 8.
  • Statement \’LOOP\’ sets SY-SUBRC to 0 if there has been at least one pass through the loop else SY-SUBRC sets to a value other than 0.

Please refer to this list for more return value of \’SY-SUBRC\’.