Entering content frame

SAVEPOINT/ROLLBACK TO Stmnt (savepoint/rollback_to_statement) Locate the document in its SAP Library structure

Within a transaction, subtransactions can be defined to make a series of database operations within a transaction appear as a unit with regard to modifications to the database.

The SAVEPOINT statement is used to define an SQL savepoint, that is, the start of a subtransaction within a transaction, and to assign this savepoint a name. A subsequent ROLLBACK TO statement with the SQL savepoint name reverses any modifications that have been made in the meantime, without affecting the database operations that were executed within the transaction before the start of this subtransaction.

Caution

An SQL savepoint defined by a SAVEPOINT statement is not a savepoint.

Syntax

<savepoint_statement> ::= SAVEPOINT <sql_savepoint_name>

<rollback_to_statement> ::= ROLLBACK TO [SAVEPOINT] <sql_savepoint_name>

<sql_savepoint_name> ::= <identifier>

Explanation

SAVEPOINT Statement

The SAVEPOINT statement opens a subtransaction, that is, the database system records the current position (SQL savepoint) in the transaction and assigns it the name savepoint_name. The SQL savepoint is identified as active. This can be followed by any sequence of SQL statements. This sequence of SQL statements can contain additional SAVEPOINT statements.

The SQL savepoint names in a transaction must be different. If an SQL savepoint name is assigned twice within a transaction, the SQL savepoint in this transaction that was defined by the first SAVEPOINT statement becomes inactive.

ROLLBACK TO statement

A ROLLBACK TO statement reverses all database modifications that were made in the active transaction following the SAVEPOINT statement.

The SQL savepoint specified in the ROLLBACK TO statement must be an active SQL statement in the transaction. All SQL savepoints created after this SQL savepoint are inactive. All SQL savepoints created before this SQL savepoint remain active.

The specified SQL savepoint also remains active after the ROLLBACK TO statement has been executed, that is, the ROLLBACK TO statement can be executed in the same transaction more than once by specifying the same SQL savepoint name.

Further Information

The SAVEPOINT/ROLLBACK TO statement does not affect locks assigned to the transaction. In particular, these SQL statements do not release any locks. Locks are only released by COMMIT or ROLLBACK.

Subtransactions are particularly useful in keeping the effects of database procedures atomic, that is, it ensures that they either fulfill all their tasks or else have no effect. To this end, a SAVEPOINT statement is specified initially. If the subroutine could not fulfill its tasks, a ROLLBACK TO statement is used to reverse all the modifications made by the database procedure.

The COMMIT statement and the ROLLBACK statement close any open subtransactions implicitly.

 

Leaving content frame