Get Example source ABAP code based on a different SAP table
Database Connections and Transactions Every active database connection creates a separate transaction context or is linked with its own database LUW>. This means that database changes on one connection can be committed or rolled back independently of changes on other database connections. In this way, for example, log data can be stored in and committed on a secondary connection without modifying the database LUW of the standard connection. Database changes can be committed or rolled back as follows specifically for database connections:
The statements COMMIT CONNECTION >> and ROLLBACK CONNECTION>> trigger targeted database commits> or database rollbacks> on specific connections.
In ADBC, the instance methods COMMIT> > and ROLLBACK>> of the class CL_SQL_CONNECTION>> trigger database commits> or database rollbacks> for the connection of the current connection object.
In static Native SQL, the statements COMMIT WORK> and ROLLBACK WORK> after EXEC SQL> trigger database commits> or database rollbacks> for the current connection.
When a database connection is made inactive implicitly at the end of an ABAP_ISESS , a database commit> is triggered.
When a database connection is closed explicitly in Native SQL, a database rollback> is triggered. In addition, there are the statements COMMIT WORK> > and ROLLBACK WORK>>, as well as the implicit database commits> and database rollbacks>, that act on all active connections. A secondary connection or service connection is always set to inactive when its database changes are committed or rolled back. A connection deactivated in this way can, however, still be used in the same ABAP_ISESS without being opened explicitly, not just in AB_SQL , but also in Native SQL or AMDP. The first time an inactive secondary connection or service connection previously active in the current ABAP_ISESS is reused, it is made active again and a new database LUW is opened.
Warning Extreme care must be taken when using SQL SET TRANSACTION> statements to set the transaction behavior of the current database connection. The transaction behavior set using these statements is preserved across the entire current database LUW, which can cause unexpected or critical situations when the database connection is reused. The default behavior of the transactions must be restored before the end of the database LUW. When the SAP HANA database> is accessed, special methods must be called for setting the transaction behavior> instead of using the SQL SET TRANSACTION> statements directly. In this case, the default transaction behavior is restored automatically at the end of the database LUW. No automatic resets can currently be performed for other database platforms.
Latest notes:
All AB-SQL , Native SQL, and AMDP reads made on a shared active database connection of an ABAP_ISESS work in the same database LUW.
The static Native SQL statement SET CONNECTION>> is ignored by the database LUWs of the connections involved.
Secondary connections and service connections in an ABAP_ISESS cannot be used in called programs, which means that a called program always activates its own connection and hence its own database LUW, even if the same connection name is used.
Secondary connections, more specifically service connections, can be used to implement independent database LUWs on a secondary database or on the standard database. Care must be taken to avoid lock situations here.
Working with multiple database connections, namely independent database LUWs, can produce lock situations in which only one work process is involved: a program changes a database row on the first connection and tries to change the same row on a second connection. This results in the program waiting for the lock of the first database LUW, without this first LUW ever being able to continue. This situation can only be resolved by ending the work process. This is done automatically for dialog processes, but it must be done manually for background jobs. It is therefore not advisable to change the same table within the a single program using multiple database connections. ABAP_HINT_END
Example ABAP Coding
If the statement COMMIT CONNECTION default> were not used, the following program section would produce a lock situation because the standard connection ( AB_SQL here) and a service connection (Native SQL here) would be used in independent database LUWs to access the same row of a database table. ABEXA 01192 ABAP_EXAMPLE_END