SQL/MP Programming Manual for COBOL

Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL529758-003
9-8
Using the WHENEVER Directive
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.
Enabling and Disabling WHENEVER Checking
You can enable and disable the WHENEVER directive for different parts of your
program. For example, you might want to handle SQL errors by checking SQLCODE
after an SQL statement instead of using WHENEVER SQLERROR. Example 9-1 on
page 9-9 shows how to enable and disable the WHENEVER directive.