SAP CL SQL CONNECTION



Get Example source ABAP code based on a different SAP table
  


• CL_SQL_CONNECTION ABAP_CLASS

ABAP_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:
CL_SQL_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 the corresponding connection or continue using it 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 AB_SQL , Native SQL, and AMDP.
If the value abap_true is 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. All database changes not yet committed using a database commit are discarded here. The instance can no longer be used after this and statements that are already linked 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.



Latest notes:

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 NEW instead of calling the method GET_ABAP_CONNECTION with the value DEFAULT .
For detailed information about database connections, see database connections.
ABAP_HINT_END



Example ABAP Coding

Specification of a service connection to the standard database for a prepared statement.
ABEXA 00870
ABAP_EXAMPLE_END