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

Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
3-38
Using Indicator Variables With the INVOKE Directive
Example
A database contains an EMPTBL table consisting of the columns EMPNUM,
FIRST_NAME, LAST_NAME, and HIRE_DATE. The columns FIRST_NAME and
HIRE_DATE allow null. This example uses an INVOKE statement with the NULL
STRUCTURE clause:
EXEC SQL BEGIN DECLARE SECTION;
EXEC SQL INVOKE emptbl AS emptbl_rec NULL STRUCTURE;
struct emptbl_rec emptbl_rec1, emptbl_rec2;
...
EXEC SQL END DECLARE SECTION;
The SQL/MX C preprocessor generates this structure template immediately after the
INVOKE statement in the preprocessed program code:
/* Beginning of generated code for SQL INVOKE */
struct emptbl_rec {
unsigned short empnum;
struct {
short indicator;
char valu[16];
} first_name;
char last_name[21];
struct {
short indicator;
char valu[11];
} hire_date;
};
The SQL/MX C preprocessor supplies only the structure template. You must supply
the variable declarations for this struct type of the form:
struct emptbl_rec emptbl_rec1, emptbl_rec2;
Your program code would then include statements with host variables of the form:
...
EXEC SQL OPEN get_emptbl_rec;
...
EXEC SQL FETCH get_emptbl_rec INTO
:emptbl_rec1.empnum,
:emptbl_rec1.first_name.valu
INDICATOR :emptbl_rec1.first_name.indicator,
:emptbl_rec1.last_name,
:emptbl_rec1.hire_date.valu
INDICATOR :emptbl_rec1.hire_date.indicator;
...
For columns that allow null, the target host variable names begin with the appropriate
struct variable, followed by the particular null structure struct variable, and end
with either the indicator or the valu within the generated null structure.
C