Show TOC

Background documentationObject-Oriented Transaction Mode Locate this document in the navigation structure

 

Syntax Syntax

  1. report DEMO_TRANSACTION_SERVICE.
  2. class CL_OS_SYSTEM definition load.
  3. data TM type ref to IF_OS_TRANSACTION_MANAGER.
  4. data T  type ref to IF_OS_TRANSACTION.
  5. data WA_SPFLI type SPFLI.
  6. data: CONNECTION type ref to CL_SPFLI_PERSISTENT,
  7.       AGENT      type ref to CA_SPFLI_PERSISTENT.
  8. data: EXC type ref to CX_ROOT,
  9.       TEXT type STRING.
  10. class TH definition.
  11.   public section.
  12.     methods HANDLE for event FINISHED of IF_OS_TRANSACTION
  13.                    importing STATUS.
  14. endclass.
  15. class TH implementation.
  16.   method HANDLE.
  17.     if status = OSCON_TSTATUS_FIN_SUCCESS.
  18.       message 'Update commited ...' type 'I'.
  19.     endif.
  20.   endmethod.
  21. endclass.
  22. data H type ref to TH.
  23.   load-of-program.
  24.   CL_OS_SYSTEM=>INIT_AND_SET_MODES( I_EXTERNAL_COMMIT = OSCON_FALSE
  25.                                 I_UPDATE_MODE = OSCON_DMODE_DEFAULT ).
  26. start-of-selection.
  27.   TM = CL_OS_SYSTEM=>GET_TRANSACTION_MANAGER( ).
  28.   T  = TM->CREATE_TRANSACTION( ).
  29.   create object H.
  30.   set handler H->HANDLE for T.
  31.   WA_SPFLI-CARRID     = 'LH'.
  32.   WA_SPFLI-CONNID     = '123'.
  33.   AGENT = CA_SPFLI_PERSISTENT=>AGENT.
  34.   try.
  35.       T->START( ).
  36.       CONNECTION = AGENT->GET_PERSISTENT( I_CARRID = WA_SPFLI-CARRID
  37.                                          I_CONNID = WA_SPFLI-CONNID ).
  38.       WA_SPFLI-DEPTIME = CONNECTION->GET_DEPTIME( ).
  39.       WA_SPFLI-ARRTIME = CONNECTION->GET_ARRTIME( ).
  40.       WA_SPFLI-DEPTIME = WA_SPFLI-DEPTIME + 3600.
  41.       WA_SPFLI-ARRTIME = WA_SPFLI-ARRTIME + 3600.
  42.       CONNECTION->SET_DEPTIME( WA_SPFLI-DEPTIME ).
  43.       CONNECTION->SET_ARRTIME( WA_SPFLI-ARRTIME ).
  44.       T->END( ).
  45.     catch CX_ROOT into EXC.
  46.       TEXT = EXC->GET_TEXT( ).
  47.       message TEXT type 'I'.
  48.   endtry.
End of the code.

In this example, a transaction is run in object-oriented mode. Parameter I_EXTERNAL_COMMIT of the system service method INIT_AND_SET_MODES is set to OSCON_FALSE in the program constructor. Once a Transaction Manager and a transaction (which is also the top level transaction) have been created, the transaction is started with START and ended with END. During the transaction, attributes DEPTIME and ARRTIME of a persistent object of class CL_SPFLI_PERSISTENT are changed. Calling method END implicitly triggers a COMMIT WORK and writes the change to the database asynchronously. The HANDLE method of local class TH reacts to the end of the transaction and evaluates its status.