SQL/MP Programming Manual for COBOL

Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL529758-003
9-6
Using the WHENEVER Directive
PERFORM SQL-WARNING-8000
...
Using the SQLCODEX Data Item
You can use level-88 items with an SQLCODE data item, such as:
1. Substitute an SQLCODEX data item for the SQLCODE data item.
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 HP COBOL 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.