SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-85
WHENEVER Declaration
WHENEVER Declaration
Considerations for WHENEVER
C Examples of WHENEVER
COBOL Examples of WHENEVER
The WHENEVER declarative statement specifies an action to take when an error,
warning, or no-rows-found condition occurs. The preprocessor inserts code after every
embedded SQL statement to check values of SQLSTATE and jump to the appropriate
routine to handle the error, warning, or no-rows-found condition.
Use WHENEVER only in embedded SQL programs in C or COBOL.
condition
specifies the condition to test for:
NonStop SQL/MX tests for condition after each DDL and DML statement for
which the WHENEVER declaration is in effect. To end testing, specify WHENEVER
with the same condition but no action.
In a SELECT through a cursor, NOT FOUND means no rows or all rows qualify. In
statements with a WHERE clause, NOT FOUND means no rows satisfy the WHERE
clause. In a FETCH after a series of fetches, NOT FOUND means all rows were
fetched.
WHENEVER condition condition-action
condition is:
NOT FOUND | SQLERROR | SQL_WARNING
condition-action is:
CONTINUE
| GOTO target
| CALL C-function
| PERFORM COBOL-routine
NOT FOUND A no-rows-found condition
SQLERROR An error
SQL_WARNING A warning
C/COBOL