ABAP - Keyword Documentation →  ABAP - Reference →  Processing External Data →  ABAP Database Accesses →  Open SQL →  Open SQL - Reads → 

OPEN CURSOR

Quick Reference

Syntax

OPEN CURSOR [WITH HOLD] @dbcur|@DATA(dbcur) FOR
  [WITH
    +cte1 AS ( SELECT subquery_clauses )[,
    +cte2 AS ( SELECT subquery_clauses )
    ...]]
  SELECT mainquery_clauses
  [UNION ...]
  [additional_options].


Addition:

... WITH HOLD

Effect

The Open SQL statement OPEN CURSOR opens a database cursor for the result set of the main query defined after FOR and links a cursor variable dbcur with this database cursor. The results set of the main query can be read with the statement FETCH.

The main query is specified after FOR as follows:

The following can be specified for the cursor:

A line of the results set is always assigned to an opened database cursor as a cursor position. After the statement OPEN CURSOR, the database cursor is positioned in front of the first line of the results set.

In a single program, a maximum of 17 database cursors can be open simultaneously across the Open SQL interface. If more than 17 database cursors are opened, the runtime error DBSQL_TOO_MANY_OPEN_CURSOR occurs. An open database cursor can be closed using the statement CLOSE CURSOR. In addition, an open database cursor is closed for a database commit or a database rollback.

If a cursor variable dbcur of an open database cursor is assigned to another cursor variable or passed as a parameter, the latter is associated with the same database cursor at the same position. A cursor variable of an open database cursor can also be passed to procedures that have been called externally, to enable the database cursor to be accessed from there.

Notes

Example

See FETCH.

Addition

... WITH HOLD

Effect

If the addition WITH HOLD is specified, the database cursor is not closed by a database commit executed using Native SQL.

The addition WITH HOLD can be used only in reads performed on the standard database. It cannot be specified together with the addition CONNECTION.

Notes



Continue
OPEN CURSOR - mainquery_clauses
FETCH
CLOSE CURSOR
Example Reading Data Through the Cursor