Opening a row cursor

After you declare a row cursor, you must tell IMS that you are ready to process the first row of the result segment. This action is called opening the cursor.

To open a row cursor, execute the OPEN statement in your program. IMS then uses the SELECT statement within DECLARE CURSOR to identify a set of rows. If you use parameter markers in the search condition of that SELECT statement, you must specify the values for the parameter makers with the USING clause. IMS uses the current value of the variables to select the rows. The result segment that satisfies the search condition might contain zero, one, or many rows.

An example of an OPEN statement is:

EXEC SQLIMS 
  OPEN C1
END-EXEC.

An example of an OPEN statement when the prepared SELECT statement has parameter markers. Assume that the prepared SELECT statement has a parameter marker in the WHERE clause:

SELECT HOSPCODE, HOSPAME FROM PCB01.HOSPITAL
WHERE HOSPNAME = ? 

Use the OPEN statement with the USING clause to set the value of the parameter marker from host variable PARM1:

EXEC SQLIMS 
OPEN C1 USING :PARM1
END-EXEC.