Ansicht
Dokumentation

ABENADBC_QUERY - ADBC QUERY

ABENADBC_QUERY - ADBC QUERY

BAL Application Log Documentation   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.
SAP E-Book

- Queries

Queries can be executed using the following instance method from class CL_SQL_STATEMENT:

  • EXECUTE_QUERY

The method has a mandatory input parameter STATEMENT of type string, to which a syntactically correct SELECT statement must be passed. 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 class CL_SQL_RESULT_SET is returned in the return value RESULT_SET. The methods of this object allow access to the result set of the query. To preserve the result set beyond the end of a database LUW, the input parameter HOLD_CURSOR of the method EXECUTE_QUERY can be filled with "X".

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

  • SET_PARAM, NEXT, and CLOSE
These methods provide access to individual rows and columns of the result set. SET_PARAM must be used to assign compatible ABAP data objects to the columns from left to right by passing corresponding data references for each column to this method. NEXT is used to address the rows of the result set one after another. The return value is 1 if the row can be addressed and 0 if not. Reads are closed using CLOSE. If the parameter binding between two calls of NEXT is to be modified, the method CLEAR_PARAMETERS must be called first.
  • SET_PARAM_STRUCT, NEXT, and CLOSE
These methods provide access to individual rows of the result set. SET_PARAM_STRUCT must be used to assign a fully compatible ABAP structure to the rows of the result set by passing corresponding data references to the method. An internal table that specifies the names and order of the columns to be read can be passed to the parameter CORRESPONDING_FIELDS. For the remaining methods, the same applies as to SET_PARAM.
  • SET_PARAM_TABLE, NEXT_PACKAGE, and CLOSE
These methods provide access to multiple rows of the result set. SET_PARAM_TABLE must be used to assign a fully compatibly structured internal table to the rows of the result set by passing a corresponding data reference to the method. As with SET_PARAM_STRUCT, a CORRESPONDING_FIELDS parameter is used to specify which columns are to be transported. Here, NEXT_PACKAGE is used instead of NEXT and reads at most the number of rows that are passed to the input parameter UPTO. If no value is passed to UPTO, all rows are read. In each call of NEXT_PACKAGE, the rows read are appended to the internal table without deleting the previous content and the number of rows read is returned in the return value ROWS_RET. The same applies when changing parameter bindings and to CLOSE as to SET_PARAM.

Notes

  • A data reference to an indicator variable with the built-in type INT2 from the ABAP Dictionary can be passed to the optional input parameter IND_REF of the method SET_PARAM. In this data reference, the value -1 indicates whether a null value existed on the database.
  • For security reasons, it is better parameterize a query using the placeholder ? rather than concatenating dynamic content. This is also a way of preventing SQL injections. If the statement only contains static content from the program and dynamic content from outside the program is possible only in operand positions using placeholders and the statement cannot be modified from outside.
  • In assignments between fields in database tables and ABAP data objects, a mapping takes place between the ABAP types and the database types. The ABAP types should match the database types. If they do not match, conversions must be made in the Native SQL interface. These conversions are platform-dependent and can raise exceptions.
  • The method EXECUTE_QUERY can also be used to call stored procedures. In databases that meet the requirements, internal tables, for example, can then be bound to the result set. This is not possible with the method EXECUTE PROCEDURE (see the example under this method).

Example

Use of ADBC to read rows sequentially from a database table filled previously using to a work area.

Example

Use of ADBC to read rows from to a database table filled previously with to an internal table.

The program ADBC_QUERY allows interactive queries that are executed using ADBC to be entered.






ROGBILLS - Synchronize billing plans   BAL_S_LOG - Application Log: Log header data  
This documentation is copyright by SAP AG.

Length: 5936 Date: 20240427 Time: 064743     sap01-206 ( 121 ms )