SAP RAISE EXCEPTION CLASS ABAP Statements

Get Example source ABAP code based on a different SAP table
  


Standard SAP Help for RAISE

RAISE EXCEPTION

Short Reference
• RAISE EXCEPTION ABAP Statement
• EXPORTING RAISE EXCEPTION
• TYPE RAISE EXCEPTION

ABAP_BASIC_FORM_1 RAISE [RESUMABLE] EXCEPTION
{ {TYPE cx_class [EXPORTING p1 = a1 p2 = a2 ...]}
| oref }.

ABAP Addition
... RESUMABLE

What does it do? This statement interrupts execution of the current statement block and raises a class-based exception. It can be used at any point in a processing block. The statement interrupts the program flow and searches for a handler as described in System Response After a Class-Based Exception. Depending on the definition of the handler, the context of the exception is closed before or after the handler is executed; this can include cleanup tasks . Only if the RESUMABLE addition is declared can processing be resumed again after the RAISE EXCEPTION statement during handling, without closing the context.

If the TYPE addition is specified, an exception of exception class cx_class is raised and, if necessary, an exception object is created. Every exception class cx_class visible at this point can be specified after TYPE. The EXPORTING addition can be used to assign appropriate actual parameters to the input parameters of the instance constructor of the exception class by using the same syntax as used for CREATE OBJECT. As in regular method calls, a1, a2, ... are general expression positions. In other words, functions and expressions can be passed as actual parameters, alongside data objects. Special rules apply in this case.

If oref is specified, no new exception object is created when the exception is raised. For oref, an object reference variable must be specified that references an existing exception object. In the existing exception object, the internal attributes that describe the position of the exception and that are read using the method GET_SOURCE_POSITION, are applied at the position of the RAISE statement. In addition, the attribute IS_RESUMABLE is set to a new value, depending on how the addition RESUMABLE is used.

The RAISE EXCEPTION statement must not be used in a method or function module in whose interface non-class-based exceptions are declared. Also, the statement does not permit simultaneous use of the CATCHSYSTEM-EXCEPTIONS statement for the obsolete handling of catchable runtime errors, and the RAISE or MESSAGE RAISING statements to raise non-class-based exceptions in function modules and methods in the current processing block.


Latest notes:If the TYPE addition is used, an exception object is only created when required, for performance reasons, that is, when an appropriate CATCH or CLEANUP block with the addition INTO is used in a surrounding TRY control structure. In principle, an exception is the same thing as an exception object being generated. A difference in behavior can occur only if a non-handled exception of the instance constructor replaces the original exception when the object is generated. However, this situation should never arise.
If oref is specified, either an exception object instantiated using CREATE OBJECT can be used, or an exception that was previously caught during exception handling can be raised again.
If a caught exception is raised again, note that the exception object does not remain unmodified and that the information about the position of the exception is changed. If the original information is to be propagated to an external handler, a new exception from the same class can be raised. The original exception object is then passed to the parameter PREVIOUS of the constructor of this class. It may be enough to propagate the original exception implicitly (and not raise it again using RAISE). The corresponding original exception can then be evaluated in the CLEANUP block, if required
If a procedure is exited by raising an exception, the content of the formal parameter for which the pass by value is defined is not assigned to the respective actual parameters.
Only the constants of the exception class that specify an exception text of the exception class should be passed to the TEXTID input parameters of the instance constructor of the exception class. The addition THROW in a conditional expression makes it possible to raise a class-based exception in an operand position.



Example ABAP Coding
See Exceptions, RAISE.




Example ABAP Coding
A predefined exception is raised explicitly for which an
exception text other than the standard exception text is selected and whose placeholder <(> <)>TOKEN<(> <)> is filled by passing a value to the attribute with the same name. DATA exc TYPE REF TO cx_sy_dynamic_osql_semantics.

TRY.
...
RAISE EXCEPTION TYPE cx_sy_dynamic_osql_semantics
EXPORTING textid = cx_sy_dynamic_osql_semantics=>unknown_table_name
token = 'Test'.
...
CATCH cx_sy_dynamic_osql_semantics INTO exc.
MESSAGE exc->get_text( ) TYPE 'I'.
ENDTRY.
• RESUMABLE RAISE EXCEPTION

ABAP Addition

What does it do? The RESUMABLE addition raises an exception as a resumable exception. When an exception of this type is handled in a CATCH block, the RESUME statement can be used to jump back to directly before the raising statement, as long as the context of the exception was not deleted before the exception was handled.

Latest notes:If the RESUMABLE statement is used to raise an exception as a resumable exception , the handler has to determine whether processing is resumed after RAISE EXCEPTION, or whether processing for the current context is canceled completely. Both alternatives can occur when an exception is raised. It is important to note that CLEANUP blocks are only executed when the context is deleted.
When exceptions of the types CX_STATIC_CHECK and CX_DYNAMIC_CHECK (which are raised as resumable) are propagated, they can become non-resumable if the RESUMABLE addition is not declared for the RAISING addition (for the exception) in each interface involved.
When exceptions of type CX_NO_CHECK are propagated, the resumable attribute is always retained. However, caution should be used when raising exceptions of type CX_NO_CHECK as resumable, and it is important to ensure a procedure always displays the required behavior.

Return to menu