Ansicht
Dokumentation
ABENABAP_LANGUAGE_EXCEPTIONS - ABAP LANGUAGE EXCEPTIONS
rdisp/max_wprun_time - Maximum work process run time BAL Application Log DocumentationThis documentation is copyright by SAP AG.
Exceptions in ABAP Statements
Error situations that occur during the execution of an ABAP statement raise exceptions. These exceptions are fully integrated into the exception concept and are raised by the runtime framework. Two types of exception exist:
- Catchable exceptions, which are based on predefined exception classes.
- Uncatchable exceptions, which directly produce runtime errors.
Each catchable exception is assigned to a runtime error that terminates the program if the exception is neither caught by using the CATCH statement with a suitable exception class nor propagated to a caller. The keyword documentation lists the type of exceptions that can be raised for each statement.
For reasons of backward compatibility, catchable exceptions raised by many ABAP statements can be caught by using
- This is the recommended way.
- This statement is obsolete. To use it, the runtime error assigned to the exception class must be catchable itself.
Within processing blocks, the two mechanisms prevent each other from handling exceptions. It is advisable to catch an exception between TRY ... ENDTRY using CATCH or to use the RAISING addition in the definition of the interface to propagate it to the caller. Catching exceptions using CATCH SYSTEM-EXCEPTIONS is no longer recommended.
Example
Unhandled Exception
The following program lines produce the runtime error COMPUTE_INT_ZERODIVIDE because division by zero is invalid and this exception situation is not handled:
DATA result TYPE i.
result = 1 / 0.
Handling Exceptions Using Exception Classes
The above exception is represented by the exception class CX_SY_ZERODIVIDE, which is a subclass of the exception class CX_SY_ARITHMETIC_ERROR. Therefore, the exception can be handled as follows (the ERR_TEXT variable is passed the text 'Division by zero.'):
DATA myref TYPE REF TO cx_sy_arithmetic_error.
DATA err_text TYPE string.
DATA result TYPE i.
TRY.
result = 1 / 0.
CATCH cx_sy_arithmetic_error INTO myref.
err_text = myref->get_text( ).
ENDTRY.
Handling Exceptions as Catchable Runtime Errors
Since the runtime error COMPUTE_INT_ZERODIVIDE is catchable and assigned to the exception group ARITHMETIC_ERRORS, it can also be handled using the obsolete statement CATCH SYSTEM-EXCEPTIONS.
DATA result TYPE i.
CATCH SYSTEM-EXCEPTIONS arithmetic_errors = 4.
result = 1 / 0.
ENDCATCH.
IF sy-subrc = 4.
...
ENDIF.
Fill RESBD Structure from EBP Component Structure SUBST_MERGE_LIST - merge external lists to one complete list with #if... logic for R3up
This documentation is copyright by SAP AG.
Length: 3982 Date: 20240419 Time: 025026 sap01-206 ( 66 ms )