>>--EXEC SQL---WHENEVER---.-NOT FOUND--.-----------------> +-SQLERROR---+ +-SQLWARNING-+ >--.-CONTINUE--------.----END-EXEC--->< +-PERFORM label---+ +-GOTO stmt_label-+
The following example shows the WHENEVER statement in use:
EXEC SQL WHENEVER sqlerror PERFORM errormessage1 END-EXEC EXEC SQL DELETE FROM staff WHERE staff_id = 'hello' END-EXEC EXEC SQL DELETE FROM students WHERE student_id = 'hello' END-EXEC EXEC SQL WHENEVER sqlerror CONTINUE END-EXEC EXEC SQL INSERT INTO staff VALUES ('hello') END-EXEC DISPLAY 'Sql Code is: ' SQLCODE EXEC SQL WHENEVER sqlerror PERFORM errormessage2 END-EXEC EXEC SQL INSERT INTO staff VALUES ('hello again') END-EXEC STOP RUN. errormessage1 SECTION. display "SQL DELETE error: " sqlcode EXIT. errormessage2 SECTION. display "SQL INSERT error: " sqlcode EXIT.
Comments:
The WHENEVER statement specifies the default action after running an Embedded SQL statement on each of the following conditions: NOT FOUND, SQLERROR, SQLWARNING.
The scope of a WHENEVER statement is related to the position of statements in the source program, not in the run sequence. The default is CONTINUE for all three conditions.