ABAP Keyword Documentation → ABAP − Reference → Processing External Data → ABAP Database Access → Data Consistency → Database LUW
Database Rollback
Database rollbacks are triggered implicitly or explicitly in AS ABAP.
Other versions: 7.31 | 7.40 | 7.54
Note
A database rollback closes all opened
database cursors. It is particularly important that database rollbacks are not triggered (in one
of the ways listed here) in SELECT
loops and after the statement OPEN CURSOR
.
Implicit Database Rollbacks
The following exceptions trigger an implicit database rollback:
- A termination message is sent.
- A program is terminated when a message is sent.
The implicit database rollback takes place on all currently open database connections.
Notes
- A termination message also produces a database rollback if the message is handled by the predefined
exception
error_message
when a function module is called.
- Termination and exit messages always terminate the program. Other message types can also terminate a program in certain contexts .
- When an internal session is exited, there is no implicit database commit on the standard connection and there is no database rollback. This must be programmed explicitly if required.
Explicit Database Rollbacks
Explicit database rollbacks in ABAP programs can be triggered in the following ways:
- The relevant database-specific Native SQL statement is used.
- In ADBC, only the method ROLLBACK of the class CL_SQL_CONNECTION can be used to do this. In other cases, the database interface does not detect the end of the transaction and might not be able to perform certain actions.
- Any
ROLLBACK
statement embedded statically betweenEXEC
andENDEXEC
is detected by the database interface and any required actions performed.
- Executing the ABAP SQL
statement
ROLLBACK CONNECTION
. The database rollback takes place on the specified database connection.
- Calling the function module DB_ROLLBACK. This function module encapsulates the corresponding Native SQL statement. By default, the database rollback is triggered on the
connection currently open for
EXEC SQL
. The rollback is triggered explicitly on the standard connection by passing the value ofabap_true
to the input parameter IV_DEFAULT. The function module DB_ROLLBACK raises the event DB_TRANSACTION_FINISHED of the class CL_DBI_TRANSACTION_STATE, which is handled by the application log framework.
- Executing the ABAP SQL
statement
ROLLBACK WORK
. The database rollback takes place on all currently open database connections. The statementROLLBACK WORK
also closes the current SAP LUW and performs the associated actions.
ROLLBACK statements are not allowed in AMDP methods.
Notes
- A simple database rollback in an ABAP program is is usually triggered using the statement
ROLLBACK CONNECTION
(the standard connection can be specified here usingdefault
). The database LUW can be monitored by the application log by using the function module DB_ROLLBACK. Apart from the database rollback itself, using the statementROLLBACK WORK
also has certain other consequences with respect to the SAP LUW.
- An explicit database rollback in an ABAP program is is best triggered using the statement
ROLLBACK CONNECTION
(the standard connection can be specified here usingdefault
).
- All the methods specified here for explicit database rollbacks clear any global temporary tables and prevent the runtime error COMMIT_GTT_ERROR in the case of implicit database commits.
Database Rollback on Database Connections
When a secondary connection or a service connection is closed explicitly in Native SQL, a database rollback is triggered in the transaction context of this database connection. For more information, see Database Connections.