OPEN
Basic form 2
OPEN CURSOR [WITH HOLD] c FOR SELECT ... .
Effect
Opens a database cursor c in a
database table or view for a
SELECT command. The variable c
must be of the type CURSOR . You can use any SELECT
command that returns a table, but not a single record, as a result.
When the cursor has been opened, the dataset specified with
SELECT can be read with FETCH
until the cursor is closed.
OPEN CURSOR belongs to the Open SQL
command set.
If you attempt to open a cursor that has already been opened, you get a
runtime error.
The following events close a cursor:
The CLOSE CURSOR command.
The Open SQL command.
COMMIT WORK
A database commit in Native SQL . In this
case, a cursor opened with WITH HOLD is not closed.
The Open SQL command
ROLLBACK WORK
A database rollback in Native SQL
A screen change, in particular the commands
CALL SCREEN ,
CALL DIALOG ,
CALL TRANSACTION ,
MESSAGE
A Remote Function Call .
Example
Open the database cursor C1 in the database
table SFLIGHT for the SELECT command
-
SELECT * FROM SFLIGHT WHERE CARRID = 'LH '.
-
TABLES SFLIGHT.
DATA C1 TYPE CURSOR.
OPEN CURSOR C1 FOR
SELECT * FROM SFLIGHT WHERE CARRID = 'LH '.
Notes
In the above example, the OPEN command contains no
INTO clause . With cursor
processing, you must always specify the target area for the selected
data in the FETCH command.
The OPEN CURSOR command allows you to open several cursors at
the same time in a table. Unlike with SELECT , you thus have
several independent access paths to this table.
Since you can open only a restricted number of cursors at the same
time, you should close cursors that are no longer required with
CLOSE CURSOR .
Since the OPEN statement does not support
authorization checks , you must program
these yourself.
Related
SELECT ,
FETCH und
CLOSE .
Index
© SAP AG 1996