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

Dynamic SQL With Descriptor Areas
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
10-20
Deallocate the Prepared Statement and the SQL
Descriptor Areas
:hv_jobcode = VARIABLE_DATA,
:hv_jobcode_i = INDICATOR_DATA;
if (hv_jobcode_i < 0)
printf("\nJobcode is unknown");
else
printf("\nJobcode is: %hu", hv_jobcode);
}
...
} /* end for */
... /* process the item descriptor values */
* First, get the count of the number of output values.
EXEC SQL
GET DESCRIPTOR 'out_sqlda' :num = COUNT
END-EXEC.
* Second, get the i-th output values and save.
PERFORM VARYING i FROM 1 BY 1 UNTIL i > num
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:sqlda-type = TYPE,
:sqlda-name = NAME
END-EXEC.
* Test type or name to determine the host variable.
* Assign data value to a compatible host variable.
...
IF sqlda-name = "LAST_NAME"
EXEC SQL
GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv-last-name = VARIABLE_DATA
END-EXEC.
DISPLAY "Last name is: " hv-last-name
...
ELSE
IF sqlda-name = "JOBCODE"
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv-jobcode = VARIABLE_DATA,
:hv-jobcode-i = INDICATOR_DATA
END-EXEC.
IF hv-jobcode-i < 0
DISPLAY "Jobcode is unknown"
ELSE
DISPLAY "Jobcode is: " hv-jobcode
...
END-PERFORM.
* Process the item descriptor values
...
Deallocate the Prepared Statement and the SQL Descriptor
Areas
When you are finished with the dynamic SQL statement, deallocate the resources used
by the prepared statement and the SQL descriptor areas. See the DEALLOCATE
PREPARE statement in the SQL/MX Reference Manual.
COBOL