SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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.
Source Code
REPORT demo_transaction_service.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: main,
class_constructor.
ENDCLASS.
CLASS th DEFINITION.
PUBLIC SECTION.
METHODS handle FOR EVENT finished OF if_os_transaction
IMPORTING status.
ENDCLASS.
CLASS th IMPLEMENTATION.
METHOD handle.
IF status = oscon_tstatus_fin_success.
MESSAGE 'Update commited ...' TYPE 'I'.
ENDIF.
ENDMETHOD.
ENDCLASS.
DATA tm TYPE REF TO if_os_transaction_manager.
DATA t TYPE REF TO if_os_transaction.
DATA wa_spfli TYPE spfli.
DATA: connection TYPE REF TO cl_spfli_persistent,
agent TYPE REF TO ca_spfli_persistent.
DATA: exc TYPE REF TO cx_root,
text TYPE string.
DATA h TYPE REF TO th.
CLASS demo IMPLEMENTATION.
METHOD class_constructor.
cl_os_system=>init_and_set_modes( i_external_commit = oscon_false
i_update_mode = oscon_dmode_default ).
ENDMETHOD.
METHOD main.
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.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
demo=>main( ).
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.