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. An indicator variable is always a 2-byte integer (short).

Examples

Example 1 This is an example of declaring indicator arrays:

EXEC SQL BEGIN DECLARE SECTION;
   /* Destination variables for fetches, using an */
   /* array.*/
   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 array for all variables. */
   short indic_var[7];

EXEC SQL END DECLARE SECTION;

Example 2 This is an example of declaring indicator structures:

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;

Example 3 This is an example of executing a query on indicator arrays or indicator structures:

EXEC SQL
SELECT titleid, title, pubname, city, state, notes,
        purchases
   INTO :host_var1 INDICATOR :indic_var1
   FROM T1, T2
   WHERE ....

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.