Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing External Data →  ABAP Database Access →  Object Services →  transaction service 

Transaction Service

This example demonstrates the execution of an object-oriented transaction.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(t) = cl_os_system=>get_transaction_manager(
      )->create_transaction( ).

    DATA(h) = NEW th( ).
    SET HANDLER h->handle FOR t.

    DATA(wa_spfli) = VALUE spfli(
      carrid     = 'LH'
      connid     = '123' ).

    TRY.

        t->start( ).

        DATA(connection) = ca_spfli_persistent=>agent->get_persistent(
          i_carrid = wa_spfli-carrid
          i_connid = wa_spfli-connid ).
        wa_spfli = VALUE #( BASE wa_spfli
          deptime = connection->get_deptime( ) + 3600
          arrtime = connection->get_arrtime( ) + 3600 ).
        connection->set_deptime( wa_spfli-deptime ).
        connection->set_arrtime( wa_spfli-arrtime ).

        t->end( ).

      CATCH cx_root INTO DATA(exc).
        MESSAGE exc->get_text( ) TYPE 'I'.
    ENDTRY.

Description

In this example, a transaction is run in object-oriented mode. To do this, the parameter I_EXTERNAL_COMMIT of the system service method INIT_AND_SET_MODES in the static constructor is set to OSCON_FALSE. After a transaction manager and a transaction (which is also the top level transaction) are created, they are started using START and ended using END. During the transaction, the attributes DEPTIME and ARRTIME of the class object CL_SPFLI_PERSISTENT (created in the executable persistent service example) are changed. Calling the END method starts a COMMIT WORK implicitly and writes the changes to the database in the asynchronous update mode. The method handle of the local class th responds to the end of the transaction and analyzes its status.