Ansicht
Dokumentation

ABAPCLEANUP_TRY - CLEANUP TRY

ABAPCLEANUP_TRY - CLEANUP TRY

TXBHW - Original Tax Base Amount in Local Currency   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.
SAP E-Book

CLEANUP Syntax Diagram

CLEANUP

Syntax

CLEANUP.

Effect

The statement CLEANUP defines the CLEANUP area of a TRY block introduced with TRY. Each TRY block can contain, at maximum, one CLEANUP clause, and, if there is such a clause, it must come after the last CATCH and before ENDTRY. The CLEANUP area covers all the statements between CLEANUP and ENDTRY.

If, at runtime, no handler is found within the TRY block for an exception, but this is caught further up in the call hierarchy, all the routines inbetween are exited. This can generally cause the program to be inconsistent or can mean that external resources are not released again. Often , the handler does not react adequately to such situations, in particular when it jumps through several levels.

The CLEANUP area, in this case, is used to get the program back into a consistent status. If an exception is not caught in the current TRY block, but only at a higher call level, the system executes the CLEANUP area of the TRY block before it leaves the context, and the exception is propagated further upwards along the call hierarchy. This can mean that further CLEANUP areas are run through by surrounding TRY blocks until the exception finally arrives at the respective handler.

Since the path of the exception from the trigger point to the handler is predetermined, it cannot be changed through statements within the CLEANUP area. For this reason, all the statements that change the control flow and cause premature exit from the CLEANUP area are forbidden. This applies, for example, to statements such as RETURN, STOP and REJECT, but also to commands such as EXIT, CONTINUE or CHECK, if the CLEANUP area is exited because of them. Since the occurrence of a further exception within the CLEANUP area has an effect on the control flow, all exceptions that occur locally within a CLEANUP area must also be handled locally. Otherwise a RABAX is initiated.

The following example demonstrates this clearly:

Example

Goods receipt in a company (class CL_GOODS_RECEPTION) contains a method enter in order to post goods receipt. The actual posting takes place when the warehouse stock stock is increased by the number of delivered parts and finally the account is debited with the price to be paid.

CLASS CL_GOODS_RECEPTION IMPLEMENTATION.
...
  METHOD enter.
    stock->increase( number_of_items ).
    TRY.
      price = number_of_items * price_per_item.
      account->withdraw( price ).
    CLEANUP.
       stock->decrease( number_of_items ).
  ENDTRY.
  ENDMETHOD.
...
ENDCLASS.

Now, if an exception occurs during the debit to the account, for example, because the account is not covered (CX_NO_COVERING), then this exception should not be processed at this point; however, the warehouse stock must be changed again accordingly in order to maintain consistency. The goods receipt could then be as follows:

DATA goods_reception TYPE REF TO CL_GOODS_RECEPTION.
...
TRY.
  ...
  goods_reception->enter( EXPORTING number_of_items = ... )
  ...
CATCH CX_STOCK_FULL CX_NO_COVERING.
  send_goods_back( ).
ENDTRY.

Related

TRY, CATCH, RAISE EXCEPTION

Additional help

Class-Based Exceptions






BAL Application Log Documentation   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 5134 Date: 20240425 Time: 104820     sap01-206 ( 99 ms )