Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP - Database Accesses →  ADBC - ABAP Database Connectivity →  CL_SQL_STATEMENT - Execution of SQL Statements 

Queries

Queries can be executed using the instance method

  • EXECUTE_QUERY of the CL_SQL_STATEMENT class.

The method has an obligatory input parameter STATEMENT of type string that must be passed to a syntactically correct SELECT statement. As with DML statements, the method SET_PARAM can be used to bind ABAP data objects to place holders ?.

As the result of a query, a reference to an object of the CL_SQL_RESULT_SET class is returned in the return value RESULT_SET. The methods of this object allow access to the resulting set of the query. To keep the resulting set beyond the end of a database LUW, the input parameter HOLD_CURSOR of the EXECUTE_QUERY method can be provided with "X".

The class CL_SQL_RESULT_SET of the result object provides the following instance methods for reading in the resulting sets in ABAP data objects:

  • SET_PARAM, NEXT, and CLOSE

    These methods provide access to individual rows and columns of the resulting set. With SET_PARAM, compatible ABAP Objects must be assigned to the columns from left to right by passing the method corresponding data references for each individual column. With NEXT the rows of the resulting set are addressed one after another. The return value is 1 if the row can be addressed and 0 if it cannot be. Reading out is completed using CLOSE. If the parameter binding between two calls of NEXT is to be changed, the method CLEAR_PARAMETERS must be called first.
  • SET_PARAM_STRUCT, NEXT, and CLOSE

    These methods provide access to individual rows and columns of the resulting set. With SET_PARAM_STRUCT, a completely compatible ABAP structure must be assigned to the rows of the resulting set by passing the method corresponding data references. An internal table that specifies the names and sequence of the columns to be read out can be passed to the parameter CORRESPONDING_FIELDS. For the remaining methods the same applies as for SET_PARAM.
  • SET_PARAM_TABLE, NEXT_PACKAGE, and CLOSE

    These methods provide access to individual rows and columns of the resulting set. With SET_PARAM_TABLE, a completely compatibly structured internal table must be assigned to the rows of the resulting set by passing the method a corresponding data reference. As with SET_PARAM_STRUCT, there is a CORRESPONDING_FIELDS parameter to specify which columns are to be transported. Here NEXT_PACKAGE is used instead of NEXT. It reads out at most the number of rows that are passed to the input parameter UPTO. If no value is passed to UPTO, all the rows are read out. At each call of NEXT_PACKAGE, the rows read are appended to the internal table without deleting the previous contents and the number of rows read is returned in the return value ROWS_RET. The same applies for changing parameter binding and CLOSE as for SET_PARAM.

Other versions: 7.31 | 7.40 | 7.54


Note

The optional input parameter IND_REF of the SET_PARAM method can be passed from a data reference to an indicator variable of type INT2 of the ABAP Dictionary. Here,above the value -1, it is possible that it will be displayed if a zero value existed on the database.

Examples

Refer to