Executing SQL statements by using a row cursor

You can use row cursors to execute FETCH statements.

Execute a FETCH statement to copy data from a row of the result segment into one or more host variables.

The following example shows a FETCH statement that retrieves selected fields from the hospital segment:

EXEC SQLIMS 
  FETCH C1 INTO :HOSPCODE, :HOSPNAME, :WARDNAME, :PATNAME 
END-EXEC.

When your program executes the FETCH statement, IMS positions the cursor on a row in the result segment. That row is called the current row. IMS then copies the current row contents into the program host variables that you specify on the INTO clause of FETCH. This sequence repeats each time you issue FETCH, until you process all rows in the result segment.