Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  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

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

    CREATE OBJECT h.
    SET HANDLER h->handle FOR t.

    wa_spfli-carrid     = 'LH'.
    wa_spfli-connid     = '123'.

    agent = ca_spfli_persistent=>agent.

    TRY.

        t->start( ).

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

        t->end( ).

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

Description

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