ABAPCLEANUP_TRY - CLEANUP TRY

General Material Data   CL_GUI_FRONTEND_SERVICES - Frontend Services  
This documentation is copyright by SAP AG.

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 thereis such a clause, it must come after the last CATCHand 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 caughtfurther up in the call hierarchy, all the routines inbetween are exited. This can generally cause theprogram 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. Ifan exception is not caught in the current TRY block, but only at a higher call level, the systemexecutes the CLEANUP area of the TRY block before it leaves the context, and the exceptionis 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 bechanged through statements within the CLEANUP area. For this reason, all the statements thatchange 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 theCLEANUP area is exited because of them. Since the occurrence of a further exception within theCLEANUP 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 orderto 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 warehousestock 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


General Material Data   CPI1466 during Backup  
This documentation is copyright by SAP AG.


Length: 5233 Date: 20120518 Time: 205130     triton ( 217 ms )