EasyManua.ls Logo

HP NonStop SQL/MP

HP NonStop SQL/MP
331 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Error and Status Reporting
HP NonStop SQL/MP Programming Manual for C429847-008
9-6
Using the WHENEVER Directive
Using the WHENEVER Directive
The WHENEVER directive specifies an action that a program takes depending on the
results of subsequent DML, DCL, and DDL statements. WHENEVER provides tests for
these conditions:
An error occurred.
A warning occurred.
No rows were found.
When you specify a WHENEVER directive, the C compiler inserts statements that
perform run-time checking after an SQL statement using the sqlcode variable.
Table 9-1 lists the C compiler pseudocode generated to check sqlcode and the order
in which the checks are made.
action-specification is one of:
CALL :host-identifier ;
GOTO :host-identifier ;
GO TO :host-identifier;
CONTINUE ;
When more than one WHENEVER condition applies to an SQL statement, NonStop
SQL/MP processes the conditions in order of precedence. 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.
These WHENEVER directives check for the error, warning, and not-found conditions:
EXEC SQL WHENEVER NOT FOUND CALL :row_not_found;
EXEC SQL WHENEVER SQLERROR CALL :sql_error;
EXEC SQL WHENEVER SQLWARNING CALL :sql_warning;
...
Table 9-1. C Compiler Pseudocode for Checking the sqlcode Variable
Order Condition Compiler Pseudocode
1 NOT FOUND if (sqlcode == 100) action-specification;
2 SQLERROR if (sqlcode < 0) action-specification;
3 SQLWARNING if (sqlcode > 0) && (sqlcode != 100)
action-specification;
Note. NonStop SQL/MP sometimes returns values other than 100 for a not-found condition.
For example, SQL error 8230 indicates that a subquery did not return any rows, and SQL error
8423 indicates that an indicator variable was not specified for a null output value.

Table of Contents

Related product manuals