Role of the Top-Level Transaction
The top-level transaction is the transaction of the uppermost level. All the transactions started during the top-level transaction are subtransactions and do not trigger a COMMIT WORK when they are ended. The
transaction mode determines how the top-level transaction is created.Compatibility Mode
The top-level transaction is usually created implicitly when the Object Services are initialized. All explicit transactions of the program are subtransactions of this implicit top-level transaction.
Object-Oriented Transaction Mode
The top-level transaction is created explicitly when the first transaction in the program is started. All the other transactions that are started before the top-level transaction is ended are subtransactions of the explicit top-level transaction.
Subtransactions
You can create a subtransaction by starting a new transaction before another transaction has come to an end. Subtransactions must be ended within the transaction in which they are embedded. A COMMIT WORK is never triggered when a subtransaction is ended. Changes to the persistent objects of a subtransaction are only made when the top-level transaction is ended. This occurs explicitly in a COMMIT WORK or implicitly in an END, depending on the transaction mode. You can also query the transaction mode with IF_OS_TRANSACTION~GET_MODES for subtransactions, but the transaction mode always tells you the global setting of the Object Services for the current program.
Sequential Processing
Top-Level Transactions
A program may only have one top-level transaction at a time. A new transaction can be started as the top-level transaction when the old top-level transaction has come to an end.
Compatibility Mode
In compatibility mode, a new top-level transaction is implicitly created and started when the old top-level transaction has ended with COMMIT WORK. The new top-level transaction manages the changes made to persistent objects.
Object-Oriented Mode
When the top-level transaction is ended with END, a COMMIT WORK is triggered. The transaction object is invalidated in the program and cannot be started again. The next transaction that is started with IF_OS_TRANSACTION~START becomes the new top-level transaction. A program is without a transaction between the end of the last and the start of the next top-level transaction. Changes made to persistent objects before the new transaction was started are ignored.
Subtransactions
Within a transaction, further subtransactions can be started after the end of another subtransaction. Changes made to persistent objects between subtransactions belong to the transaction at the next higher level.
Concatenation of Top-Level Transactions
If you execute transactions one after the other, that is you end one top-level transaction and then start a new one, the relevant persistent objects are invalidated. When you access such an object in the next transaction, it is loaded again from the database. You can avoid this time-consuming process by concatenating top-level transactions with IF_OS_TRANSACTION~END_AND_CHAIN or IF_OS_TRANSACTION~UNDO_AND_CHAIN. In this case the persistent objects are not invalidated. However, a new transaction object is created and its reference is returned as the return value.
You can use these methods for top-level transactions in object-oriented mode, but not for the top-level transaction in compatibility mode.
You do not need to use the methods for subtransactions since the persistent objects are retained until the change has been made, and are not invalidated.
Example
data TM type ref to IF_OS_TRANSACTION_MANAGER.
data T type ref to IF_OS_TRANSACTION.
...
TM = CL_OS_SYSTEM=>GET_TRANSACTION_MANAGER( ).
T = TM->CREATE_TRANSACTION( ).
"Create first transactionT->START( ).
"Start first transactionAfter calling method END_AND_CHAIN, reference variable T refers to a new transaction object.