SQL/MP Programming Manual for COBOL85

Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL85429326-004
9-6
Using the WHENEVER Directive
To do this, include an INVOKE SQLCODEX statement in each program or nested
program in which you want an SQLCODEX data item.
2. Attach level-88 items to the SQLCODEX data item.
3. Declare the SQLCA structure.
However, this approach is not recommended, because SQLCODEX is not part of the
ANSI Database—Embedded SQL Standard. Rather, omit the INCLUDE SQLCA
directive from each program or nested program to prevent the compiler from declaring
the SQLCODE data item implicitly so that you can declare it explicitly and attach level-
88 items to it.
Using the WHENEVER Directive
The WHENEVER directive specifies an action that a program takes, depending on the
result of subsequent DML, DCL, and DDL statements. WHENEVER provides tests for
these conditions:
An error occurred.
A warning occurred.
No rows were found.
You must specify a WHENEVER directive in the Procedure Division after a section or
paragraph name. When you specify this directive, the COBOL85 compiler inserts
statements that perform run-time checking after an SQL statement using the
SQLCODE variable. You do not have to explicitly check the SQLCODE value.
Although using WHENEVER directives is simpler than writing a routine to test
SQLCODE, you still must code the error routines. Typically, you code the routines once
and save them in a library file to be copied into your programs as needed. You can use
the COBOL SOURCE directive to copy the error routines into your program.
This table indicates the COBOL85 compiler pseudocode that checks SQLCODE and
the order in which the checks are made:
action-specification is one of:
PERFORM :host-identifier ;
GOTO :host-identifier ;
GO TO :host-identifier;
CONTINUE ;
Order Condition Compiler Pseudocode
1 NOT FOUND
IF SQLCODE = 100
THEN action-specification
2 SQLERROR
IF SQLCODE < 0
THEN action-specification
3SQLWARNING
IF SQLCODE > 0 AND SQLCODE NOT = 100
THEN action-specification