OPEN CURSOR [WITH HOLD] dbcur FOR
SELECT result
FROM source
[[FOR ALL ENTRIES IN itab] WHERE sql_cond]
[GROUP BY
group] [HAVING group_cond]
[ORDER BY sort_key].
This statement opens a database cursor for the selection defined after FOR, and links a cursor variable dbcur with this database cursor. For dbcur, a declared variable with the specific predefined data type cursor must be entered. A database cursor dbcur that has already been opened cannot be opened again. A line of the resulting set is always assigned to an opened database cursor as a cursor position. After the OPEN CURSOR statement, the database cursor is positioned in front of the first line of the resulting set.
After FOR, the syntax of a SELECT statement can be entered, which contains all the additions of the normal SELECT statement, except for INTO and APPENDING. In the addition result, the addition SINGLE can also not be used after SELECT.
Only a limited number of database cursors can be open at the same time. 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, the latter is linked to the same database cursor at the same position. A cursor variable of an open database cursor can also be transferred to procedures that have been called externally, to enable the database cursor to be accessed from there.
It is not recommended to assign cursor variables to each other, but rather to set them exclusively using
the statements OPEN CURSOR and CLOSE CURSOR.
... WITH HOLD
If the addition WITH HOLD is specified, the database cursor is not closed in an explicitly triggered database commit or database rollback, for example
Native SQL. The addition WITH HOLD cannot be specified if the cursor is to be opened for a
secondary database connection.