SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Exception Handling and Error Conditions
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
13-9
Precedence of Multiple WHENEVER Declarations
SQL_WARNING condition: An SQL warning occurred. SQLSTATE does not
indicate a no-data or an error condition. SQLCODE is greater than zero and not
equal to 100.
You must specify the WHENEVER declaration in your program before the SQL
statements to which it applies. Use this general syntax:
WHENEVER { NOT FOUND | SQLERROR | SQL_WARNING }
{ CONTINUE
| GOTO host-label-identifier
| CALL C-function
| PERFORM COBOL-routine }
For complete syntax, see the WHENEVER Declaration in the SQL/MX Reference
Manual.
This example uses WHENEVER declarations to check for the NOTFOUND,
SQLERROR, and SQL_WARNING conditions.
Examples
/* global C declarations */
...
EXEC SQL WHENEVER NOT FOUND GOTO data_not_found;
EXEC SQL WHENEVER SQLERROR GOTO end_prog;
EXEC SQL WHENEVER SQL_WARNING CONTINUE;
EXEC SQL WHENEVER NOT FOUND CALL handle_nodata;
...
* global COBOL declarations
...
EXEC SQL WHENEVER NOT FOUND GOTO data-not-found END-EXEC.
EXEC SQL WHENEVER SQLERROR GOTO end_prog END-EXEC.
EXEC SQL WHENEVER SQL_WARNING CONTINUE END-EXEC.
EXEC SQL WHENEVER NOT FOUND PERFORM handle-nodata END-EXEC.
...
Precedence of Multiple WHENEVER Declarations
When more than one WHENEVER declaration applies to an SQL statement, NonStop
SQL/MX processes the conditions in order of precedence:
1. NOT FOUND
2. SQLERROR
3. SQL_WARNING
For example, an SQL error and an SQL warning can occur for the same statement, but
the error condition has a higher precedence and is processed first.
Determining the Scope of a WHENEVER Declaration
The order in which WHENEVER declarations appear in the listing determines their
scope:
C
COBOL