ADBC - CL_SQL_CONNECTION
The SQL statements that are represented by objects of the CL_SQL_STATEMENT and CL_SQL_PREPARED_STATEMENT classes work by default with the standard AS ABAP database. The following class can be used to enable additional database connections or to make settings for database connections (including the standard connection):
The following can be passed to the method GET_ABAP_CONNECTION of this class:
- The value DEFAULT for the standard connection of the current work process.
- The name of a secondary connection from the column CON_NAME of the database table DBCON.
- The name of a service connection prefixed with R/3*.
All of these instances are case-sensitive. The method attempts to activate or reuse the corresponding connection and, if successful, creates an instance of CL_SQL_CONNECTION as a connection object and returns the corresponding reference.
A further method, GET_CONNECTION, has the additional parameter SHARABLE, which can be used to share a secondary connection or service connection with ABAP SQL, Native SQL, and AMDP.
- If the value
abap_trueis passed to the parameter, GET_CONNECTION works like GET_ABAP_CONNECTION and the connection is shared.
- If the value
abap_false(default) is passed to the parameter, the secondary connection or service connection can be used exclusively by using the connection object.
References to instances of CL_SQL_CONNECTION can be passed to the parameter CON_REF of the instance constructor of CL_SQL_STATEMENT or CL_SQL_PREPARED_STATEMENT. Instances created in this way execute their SQL statements on the database connection represented by the instance of CL_SQL_CONNECTION.
The instance method CLOSE of CL_SQL_CONNECTION closes the current secondary connection or service connection. This rolls back all database changes not yet committed using a database commit. The instance can no longer be used after this and statements that are already associated with the connection become invalid. CLOSE is ignored in instances that represent the standard connection.
To handle database LUWs using ADBC, the class CL_SQL_CONNECTION contains the methods COMMIT and ROLLBACK, which raise a database commit or database rollback respectively. Furthermore, CL_SQL_CONNECTION contains methods for setting the transaction behavior of the current database connection. When an SAP HANA database is accessed, these methods must be used instead of the corresponding SQL SET TRANSACTION statements.
- To create a connection object for the
standard connection, an instance of CL_SQL_CONNECTION can be created directly using CREATE
OBJECT or the instance operator
NEWinstead of calling the method GET_ABAP_CONNECTION with the value DEFAULT.
- Detailed information about database connections can be found here.
Specifies a service connection to the standard database for a prepared statement.
TRY. DATA(con) = cl_sql_connection=>get_abap_connection( `R/3*my_conn` ). DATA(sql) = NEW cl_sql_prepared_statement( statement = `INSERT INTO demo_update VALUES( ?, ?, ?, ?, ?, ? )` con_ref = con ). ... sql->close( ). con->close( ). CATCH cx_sql_exception INTO DATA(exc). cl_demo_output=>display( exc->get_text( ) ). ENDTRY.