Skip to content

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


The class CL_SQL_PREPARED_STATEMENT is a subclass of CL_SQL_STATEMENT. It makes it possible to execute a SQL statement passed to it multiple times with different parameters.

For this purpose, the instance constructor contains a mandatory input parameter STATEMENT of type string that must be passed to an SQL statement with correct syntax. The SQL statement can contain placeholder ?, as is the case with the methods of CL_SQL_STATEMENT.

Using the methods inherited from CL_SQL_STATEMENT, the placeholders can be linked to parameters and the instantiated SQL statement can be executed. In doing so, the SQL statement is not passed to the corresponding method.

After the work process has been switched (see implicit database commit), a prepared statement can no longer be used.

If a prepared statement is no longer needed, it should be closed using instance method close so that all resources that are needed in the database are released.

Other versions: 7.31 | 7.40 | 7.54


  • Unlike in JDBC, the use of ? placeholders in ADBC is not restricted to prepared statements. In ADBC, the use of prepared statements is not a prerequisite for using placeholders to stop SQL injections. Prepared statements are used only to improve performance in ADBC.

  • As with CL_SQL_STATEMENT, CL_SQL_PREPARED_STATEMENT should not be used to execute transaction control statements.


Inserts multiple rows in a database table using a prepared statement in ADBC. The tables are first emptied using ABAP SQL and then read using ABAP SQL. The values of the columns are determined by binding the components of temporary structures created using NEW to ? placeholders.

DELETE FROM demo_update. 

    DATA(sql) = NEW cl_sql_prepared_statement( 
      `INSERT INTO demo_update VALUES( ?, ?, ?, ?, ?, ? )` ). 

    sql->set_param_struct( NEW demo_update( 
      client = sy-mandt id = 'X' 
      col1 = 1 col2 = 2 col3 = 3 col4 = 4 ) ). 
    sql->execute_update( ). 

    sql->set_param_struct( NEW demo_update( 
      client = sy-mandt id = 'Y' 
      col1 = 5 col2 = 6 col3 = 7 col4 = 8 ) ). 
    sql->execute_update( ). 

    sql->close( ). 
  CATCH cx_sql_exception INTO DATA(exc). 
    cl_demo_output=>display( exc->get_text( ) ). 

       FROM demo_update 
       INTO TABLE @DATA(result). 

cl_demo_output=>display( result ).

Executable Example

ADBC, Prepared Statement