SQL/MP Programming Manual for COBOL85
Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL85—429326-004
9-7
Using the WHENEVER Directive
When more than one WHENEVER condition applies to an SQL statement, 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 PERFORM :ROW-NOT-FOUND-7000 END-EXEC.
EXEC SQL 
 WHENEVER SQLERROR PERFORM :SQL-ERROR-9000 END-EXEC.
EXEC SQL 
 WHENEVER SQLWARNING PERFORM :SQL-WARNING-8000 END-EXEC.
... 
Determining the Scope of a WHENEVER Directive
The order in which WHENEVER directives appear in the listing determines their scope. 
Some considerations follow:
•
A WHENEVER directive remains in effect until another WHENEVER directive for 
the same condition appears. If you want to execute a different routine when an 
error occurs, specify a new WHENEVER directive with a different PERFORM 
routine. 
For example, to insert a new row only when a row is not found, specify a new 
WHENEVER directive as follows:
EXEC SQL WHENEVER NOT FOUND PERFORM :INSERT-ROW END-EXEC.
The new WHENEVER directive remains in effect until it is disabled or changed.
•
If another program is called within the error handling code, the position of the 
called program in the listing order determines the WHENEVER directive in effect; 
the context of the calling program has no effect.
•
The listing order includes files copied into the program through a SOURCE 
directive. If a copied file contains a WHENEVER directive, that directive is in effect 
following the SOURCE directive.
•
SQL statements are not affected by the WHENEVER directive if they appear in the 
program before the WHENEVER directive enables condition checking.
•
Do not code WHENEVER directives inside IF statements. A COBOL terminator on 
a WHENEVER directive or any other nonexecutable statement, such as DECLARE 
CURSOR or CONTROL statement, does not affect execution.
Note. 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. 










