ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Native SQL →  ADBC - ABAP Database Connectivity → 

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 is employed to use additional database connections:

The following can be passed to the method GET_CONNECTION of this class:

Both of these items 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.

The additional parameter SHARABLE specifies how the active connection is shared when used with Open SQL, Native SQL, and AMDP. If the parameter is used with the value abap_false, the secondary or service connection can be used only exclusively using the connection object. The value abap_true specifies a shared connection.

To create a connection object for the standard connection, an instance of CL_SQL_CONNECTION can be created using CREATE OBJECT or the instance operator NEW.

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.

Note

Detailed information about database connections can be found here.

Example

Specifies a service connection to the standard database for a prepared statement.

TRY.
    DATA(con) = cl_sql_connection=>get_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.



Continue
ADBC - Database LUWs