>>--EXEC SQL---WHENEVER---.-NOT FOUND--.----------------->
+-SQLERROR---+
+-SQLWARNING-+
>--.-CONTINUE--------.----END-EXEC---><
+-PERFORM label---+
+-GOTO stmt_label-+
| CONTINUE | Causes the next sequential statement in the source program to run. |
| PERFORM label | Identifies a paragraph or section of code to be performed when a certain error level is detected. |
| GOTO stmt_label | Identifies the place in the program that takes control when a certain error level is detected. |
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.