Arrays and structures as indicator variables

For tables with a large number of columns, you can use arrays and structures as a set of host variables that is referenced in a SQL statement. For this feature to work correctly, you must declare the indicator array or indicator structure elements with a PIC S9(4) clause and a COMP-5 clause. As with ESQL/C, use of structures and arrays as indicator variables removes the time consuming process of coding singleton indicator variables in ESQL/COBOL for every nullable column of every Embedded SQL statement in the application.

Examples

Example 1 This is an example of declaring indicator arrays and executing a query on the indicator arrays:

* Declare variables
....
01 HOST-STRUCTURE-M1.
   03 M-TITLE PIC X(64).
   03 M-NOTES PIC X(200).
   03 M-PUBNAME PIC X(40).
   03 M-PUBCITY PIC X(20).
   03 M-PUBSTATE PIC X(2).

01 INDICATOR-TABLE.
   03 I-NOTES-ARR PIC S9(4) COMP-5 OCCURS 5 TIMES.
....


* Execute query
....
EXEC SQL
SELECT substring(title, 1, 64), notes, pub_name,
            city, state
     INTO :HOST-STRUCTURE-M1:I-NOTES-ARR
     FROM titles, publishers
     WHERE titles.pub_id = publishers.pub_id
     AND title_id = :USER-TITLEID
END-EXEC.
....

Example 2 This is an example declaring indicator structures and executing a query on the indicator structures:

* Declare variables
....
01 HOST-STRUCTURE-M1.
   03 M-TITLE PIC X(64).
   03 M-NOTES PIC X(200).
   03 M-PUBNAME PIC X(40).
   03 M-PUBCITY PIC X(20).
   03 M-PUBSTATE PIC X(2).

01 INDICATOR-STRUCTURE-I1.
   03 I-TITLE PIC S9(4) COMP-5. 
   03 I-NOTES PIC S9(4) COMP-5.
   03 I-PUBNAME PIC S9(4) COMP-5.
   03 I-PUBCITY PIC S9(4) COMP-5.
   03 I-PUBSTATE PIC S9(4) COMP-5.
....

* Execute query
....
EXEC SQL
SELECT substring(title, 1, 64), notes, pub_name, city,
       state
    INTO :HOST-STRUCTURE-M1:INDICATOR-STRUCTURE-I1
    FROM titles, publishers
    WHERE titles.pub_id = publishers.pub_id
    AND title_id = :USER-TITLEID
END-EXEC.

Usage

When using structs and arrays as indicator variables:

Error messages

Table 6-1 describes the Embedded SQL internal error messages created to handle host variable versus indicator variable mismatch errors for this feature.

Table 6-1: New internal error messages

Message ID

Message text

Severity

Fix

M_INVTYPE_V

Incorrect type of indicator variable found in the structure.

Fatal

Make sure that the same indicator variable is used in the hostvar and indicator declarations.

M_INVTYPE_VI

Mismatch between number of structure elements in the indicator structure and hostvar structure.

Fatal

Declare the same number of elements in the indicator structure and hostvar structure.

M_INVTYPE_VII

Mismatch between number of elements in the indicator array and hostvar structure.

Fatal

Declare the same number of elements in the indicator array and hostvar structure.

Limitation

You cannot mix singleton host variables or singleton indicator variables with hostvar structures, and indicator arrays or structures.