Support for ESQL structures and arrays as indicator variables

The current ESQL/C preprocessor supports the use of arrays as indicator variables but not the use of structures as indicator variables. In ESD #8, it is now possible to use ESQL/C structures as indicator variables. For more information, see “New array indicator feature in ESQL/C”.

The ESQL/COBOL preprocessor is also enhanced to support both array and structure indicator variables. For this feature to work correctly in COBOL, 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

Following is an example of how to declare indicator structure in ESQL/C:

EXEC SQL BEGIN DECLARE SECTION;
/* Destination variables for fetches, using a struct.*/
 struct _hostvar {
        int m_titleid;
        char m_title[65];
        char m_pubname[41];
        char m_pubcity[21];
        char m_pubstate[3];
        char m_notes[201];
        float m_purchase;
 } host_var1;

/* An indicator structure for above variables. */
struct _indicvar {
       short i_titleid;
       short i_title;
       short i_pubname;
       short i_pubcity;
       short i_pubstate;
       short i_notes;
       short i_purchase;
 } indic_var1;
EXEC SQL END DECLARE SECTION;

Following is an example of how to declare indicator arrays, and how to execute a query using indicator arrays in ESQL/COBOL:

* 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.
....

Following is an example of how to declare indicator structures, and how to execute a query using indicator structures in ESQL/COBOL:

* 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 in ESQL/C and ESQL/COBOL:

Error messages

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

Table 5: 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.

Limitations

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