Specifying the action that the row cursor is to take when it reaches the end of the data
Your program must be coded to recognize and handle an end-of-data condition whenever you use a row cursor to fetch a row.
To determine whether the program has retrieved the last row of data, test the SQLIMSCODE field for a value of 100 or the SQLIMSSTATE field for a value of '02000'. These codes occur when a FETCH statement has retrieved the last row in the result segment and your program issues a subsequent FETCH. For example:
IF SQLIMSCODE = 100 GO TO DATA-NOT-FOUND.
An alternative to this technique is to code the WHENEVER NOT FOUND statement. The WHENEVER NOT FOUND statement causes your program to branch to another part that then issues a CLOSE statement. For example, to branch to label DATA-NOT-FOUND when the FETCH statement does not return a row, use this statement:
EXEC SQLIMS
WHENEVER NOT FOUND GO TO DATA-NOT-FOUND
END-EXEC.
For more information about the WHENEVER NOT FOUND statement, see Checking the execution of SQL statements.