Ansicht
Dokumentation

ABAPEXEC_CURSOR - EXEC CURSOR

ABAPEXEC_CURSOR - EXEC CURSOR

General Data in Customer Master   Vendor Master (General Section)  
This documentation is copyright by SAP AG.
SAP E-Book

- OPEN, FETCH, CLOSE

In embedded Native SQL, similar statements to those in can be specified to read data using a database cursor.

EXEC SQL.
  OPEN dbcur FOR SELECT ...
ENDEXEC.

Effect

Opens a database cursor dbcur. For dbcur, a flat character-like host variable can be specified.

Note

The number of database cursors open simultaneously is restricted by the platform. Any attempts to open too many database cursors raise an exception of the class CX_SY_NATIVE_SQL_ERROR.

EXEC SQL.
  FETCH NEXT dbcur INTO ...
ENDEXEC.

Effect

Uses an open database cursor dbcur to read data to the host variables specified after INTO.

EXEC SQL.
  CLOSE dbcur
ENDEXEC.

Effect

Closes an opened database cursor dbcur.

If no row can be read using FETCH, sy-subrc is set to 4 by ENDEXEC. After a FETCH statement, the system field sy-dbcnt is set to the number of rows read up to that point using the relevant cursor. If an overflow occurs because the number or rows is greater than 2,147,483,647, sy-dbcnt is set to -1.

Note

It depends on the database system whether the database cursor in the database is closed implicitly after the extraction of the final row of the result set or not. For this reason, it is advisable to use the statement CLOSE dbcur explicitly.

Example

Reading of multiple rows from the database table SPFLI using cursor handling and host variables in static Native SQL. If rows are found, sy-subrc is set to 0 and sy-dbcnt is increased by one for each row read.








Vendor Master (General Section)   PERFORM Short Reference  
This documentation is copyright by SAP AG.

Length: 2724 Date: 20240616 Time: 103617     sap01-206 ( 46 ms )