Ansicht
Dokumentation

ABENABAP_RUNTIME_ERRORS - ABAP RUNTIME ERRORS

ABENABAP_RUNTIME_ERRORS - ABAP RUNTIME ERRORS

General Data in Customer Master   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.
SAP E-Book

Exception Handling

(see also: Application Help)

Exceptions

An exception is a situation that occurs during the execution of an ABAP program, which renders a normal program continuation pointless. Exceptions can be caused both implicitly in the ABAP runtime environment as well as explicitly in the ABAP program. A division by zero, for example, causes an exception in the ABAP runtime environment. However, you can detect this situation through a query in the ABAP program and then raise an exception there yourself.

We differentiate between exceptions that can be handled andexceptions that cannot be handled

  • Exceptions that can be handled indicate error situations in the runtime environment or in the ABAP program, in the case of which the program execution can be continued - by handling the exception in the ABAP program - without the system reaching a critical condition. If such a situation is not handled a runtime error will occur.
  • Exceptions that cannot be handled indicate critical error situations in the runtime environment, which cannot be handled with/by ABAP means and always cause a runtime error.

For historical reasons, there are several mechanisms you can use to define and handle exceptions in ABAP:

Class-Based Exceptions

In Release 6.10 the concept of class-based exceptions has been introduced, in which exceptions are generally represented by objects of exception classes. There are pre-defined (that is, shipped with the SAP Web Application Server) exception classes for error situations in the runtime environment and you can define your own exception classes for general error handling in ABAP programs.

Class-based exceptions are raised in ABAP programs either by the runtime environment - for example through error situations in ABAP statements - or by using the RAISE EXCEPTION statement. The runtime environment only causes exceptions that are based on pre-defined classes, while in ABAP programs you can use pre-defined as well as user-specific exception classes. Class-based exceptions are handled using the control structure TRY ... ENDTRY. Class-based exceptions in procedures can be propagated to the caller in the definition of the interface using the RAISING addition, if the exception is not to be handled in the procedure.

The concept of class-based exceptions comprises and standardizes the functions of the previously used separate concepts of catchable runtime errors, which could be used to handle error situations in the runtime environment, and of exceptions defined by yourself in the interface of function modules and methods. For compatibility reasons, the old concepts will remain in the system, but these should not be used in new developments.

Preceding Concepts

Prior to the introduction of class-based exceptions in Release 6.10 threre were two different types of exception. These exceptions and the mechanisms used to handle them are still available along with the class-based exceptions, for reasons of backward compatibility (mentioned above). However, you cannot use both handling types in parallel within one and the same processing block.

Pre-Defined Exceptions in the Runtime Environment

Prior to Release 6.10 error situations in the runtime environment which could be handled sensibly in the program, were treated as catchable runtime errors. Catchable runtime errors are assigned to certain ABAP statements and are caused by the runtime environment if there are errors in an ABAP statement, for example a division by zero in the COMPUTE statement. In Release 6.10 every catchable runtime error has been assigned an exception class.

Catchable runtime errors are handled using the control structure CATCH SYSTEM-EXCEPTIONS ... ENDCATCH. If catchable runtime errors are not handled the program is terminated. Because you can handle all catchable runtime errors using TRY ... ENDTRY, due to the assigned exception class, you should not use this catch mechanism for any future developments.

User-Specific Exceptions in Procedures

To allow the caller to handle error situations in procedures you could define exceptions in the interface of function modules and methods. For global procedures you did this in the ABAP Workbench and for local methods using the EXCEPTIONS addition to the METHODS statement. You can raise exceptions defined in this way within the procedure using the RAISE statement and the RAISING addition to the MESSAGE statement.

Exceptions defined in the interface are handled using the EXCEPTIONS additions to the relevant CALL statement. These exceptions cannot be passed on in the call hierarchy and if they are not handled the program is terminated

If you specify the pre-defined exception ERROR_MESSAGE after the EXCEPTIONS addition to a procedure call, you can also handle type E and A messages sent with the MESSAGE statement as exceptions.

Because the class-based approach is also considerably more powerful and flexible here, you should also use it for your own exceptions or new developments.






General Material Data   General Data in Customer Master  
This documentation is copyright by SAP AG.

Length: 6263 Date: 20240425 Time: 030442     sap01-206 ( 128 ms )