SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-20
Handling Parameters
Calculating the Lengths of the Names and Collation Buffers
Use the names buffer to store the names of your input parameters (after a DESCRIBE
INPUT operation) or the names of selected columns (after a DESCRIBE operation).
SQL/MP returns a name to the names buffer as a VARCHAR item. A column name is
qualified with the table name. The HP COBOL compiler processes the name as a
group item defined as:
02 LEN PIC 9(4) COMP.
02 VAL PIC X(value-of-len).
A name with an odd number of characters is padded with a trailing blank to make the
length an even number. The HP COBOL compiler determines the length in bytes of the
names buffer:
names-buffer-length =
( EVEN ( max-name-length + 11 ) ) * sqlvar-count
The 11 bytes added to name-string-size are derived from the length field
(2 bytes), table name (8 bytes), and period separator (1 byte), rounded to an even
number.
The names buffer contains null strings for unnamed input parameters. For an output
expression, the names buffer contains a null string.
The collation buffer receives copies of any collation objects used by columns in the
query. SQL/MP returns a collation object to the collation buffer as a VARCHAR item.
The HP COBOL compiler processes a collation as a group item defined as:
02 LEN PIC 9(4) COMP.
02 VAL PIC X(value-of-len).
The HP COBOL compiler determines the length in bytes of the collation buffer:
collation-buffer-length =
( max-collation-size + 4 ) * sqlvar-count
The 4 bytes added to max-collation-size is the length (LEN) field in the
VARCHAR item.
Handling Parameters
If the SQL statement has parameters, the INPUT-NUM field (for input parameters) or
OUTPUT-NUM field (for output parameters) of the SQLSA does not equal 0. If the
statement has parameters, you must change the descriptions in the SQLDA to point to
appropriate host variables. Change the corresponding data types and set up the
SQLDA structure to point to the storage for variables referenced by the query. In
addition, depending on your application, you must check and possibly set several
SQLDA fields related to null values and scaled data.
Loop through the SQLVAR array in the input (for input parameters) or output (for output
parameters) SQLDA structure. Loop n times, where n is the number of parameters