SQL/MP Programming Manual for COBOL

Host Variables
HP NonStop SQL/MP Programming Manual for COBOL529758-003
2-23
Using Indicator Variables With the INVOKE Directive
INDICATOR is the indicator variable. The SQL data type of an indicator variable is
SMALLINT. The corresponding COBOL data type is PIC S9(4) COMP. VALUE is the
host variable corresponding to the column value.
This example uses the NULL STRUCTURE clause, which causes columns that can
contain null values to be declared as group items. This INVOKE directive contains a
NULL STRUCTURE clause:
EXEC SQL INVOKE BTABLE NULL STRUCTURE END-EXEC.
The generated record description is:
* Record Definition for table \SYS1.$VOL1.SUBV1.BTABLE
* Definition current at 12:41:11 - 06/11/94
01 BTABLE.
02 ZCHAR-NULL-OK.
03 INDICATOR PIC S9(4) COMP.
03 VALUE PIC X(10).
02 ZNUM-NULL-OK.
03 INDICATOR PIC S9(4) COMP.
03 VALUE PIC S9(4) COMP.
Example 2-4 on page 2-24 declares and uses qualified host variable names and
indicator variable names and shows the following:
Host variable declaration with an INVOKE statement that specifies the suffix -I for
indicator variables. The invoked record declaration is included as a comment in the
example.
Host variable indicator variable used in the SELECT statement. The columns that
might contain a null value require the indicator variable following the host variable
to receive information about null values.
Indicator variable testing for a possible null value. If the value of the indicator
variable following the select is less than 0, the associated column's value is NULL.
The example retrieves four columns of an order detail table. The table is similar to the
ODETAIL table of the sample database except that the UNIT_PRICE and
QTY_ORDERED columns allow null values.