SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Host Variables in COBOL Programs
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
4-19
Using Indicator Variables in a COBOL Program
Using Indicator Variables in a COBOL Program
Null in an SQL column indicates that a value is either unknown or is not applicable. A
host language program uses an indicator variable to insert null. It also uses an
indicator variable to test for null or a truncated output value.
An indicator variable is an exact numeric variable associated with the host variable that
sets or receives the actual column value. The INVOKE directive automatically declares
indicator variables for columns that allow null.
A host language program can use an indicator variable to:
Insert values into a database with an INSERT or UPDATE statement.
Test for null or a truncated value (in the case of character data) after retrieving a
value from a database with a SELECT INTO or FETCH statement.
Inserting Null
To insert values into columns that allow null with an INSERT or UPDATE statement,
you must set the indicator variable to a value less than zero for null or zero for a
nonnull value before executing the statement.
Examples
A database contains a RETIREES table consisting of the columns EMPNUM and
RETIRE_DATE (which allows null). This INSERT statement uses an indicator variable
to insert null into the RETIRE_DATE column:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 RETIREE-REC.
02 NEW-EMPNUM PIC 9(4) COMP.
02 RETIRE-DATE PIC X(10).
02 RETIRE-IND PIC S9(4) COMP.
EXEC SQL END DECLARE SECTION END-EXEC.
...
PROCEDURE DIVISION.
...
SYNC The clause is ignored.
USAGE The USAGE options correspond to SQL data types:
COMPUTATIONAL (COMP) or BINARY to SQL type NUMERIC
or PICTURE 9’s COMP to an integer type (SMALLINT,
INTEGER, or LARGEINT).
DISPLAY to SQL type CHARACTER (for PIC X) or DECIMAL
(for PIC 9).
The INDEX and PACKED-DECIMAL options are not allowed.
VALUE The clause is ignored.
Table 4-4. Interpretation of COBOL Data Description Clauses (page 2 of 2)
COBOL