SQL/MP Programming Manual for COBOL

Error and Status Reporting
HP NonStop SQL/MP Programming Manual for COBOL529758-003
9-10
Using the WHENEVER Directive
Using an Aggregate Function
All aggregate functions except COUNT return a null value when operating on an empty
set. If a host variable receives the null value as the result of an aggregate function, you
must specify an indicator variable and test the result of the indicator variable.
Otherwise, SQL/MP returns a “no indicator variable provided” condition instead of a “no
rows found” condition. A WHENEVER NOT FOUND directive does not detect this
condition.
Example 9-2 on page 9-11 illustrates the use of WHENEVER directives that detect
error and warning conditions. For the INSERT statement, the SQLERROR directive is
processed first. This directive has a higher precedence, although the SQLWARNING
directive is specified first in the source code.