SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-26
Prompting the User for Input Values
Using the Names Buffer to Prompt for Input Parameter
Values
You can use the names buffer to prompt the user for input parameter values, in which
case the names buffer contains the names of the input parameters. You can also use
the names buffer to display column names, in which case the names buffer contains
the names of the columns.
The data returned to the names buffer is in this form:
len-1 name-1 len-2 name-2 ... len-n name-n
In this case, name-1 represents the first parameter or column name, name-2 the
second, and name-n the last. The length information is a 2-byte integer (SQL data
type PIC S9(4) COMP). All names with a length of an odd number of characters are
padded with a blank to make the length an even number. When you display the names,
you might want to check for this blank padding. Names for output expressions or
unnamed input parameters appear as a null string with a length of 0.
To determine the names in the names buffer programmatically, you can write a routine
to return the names structure when given the address of the column information
desired. After the DESCRIBE INPUT or DESCRIBE statement executes, the VAR-PTR
field of each SQLVAR entry in the input or output SQLDA contains the address of the
length field associated with the name of the corresponding parameter or column in the
names buffer.
ELSE
* Check for VARCHAR data type; store length and value in
* separate sub-fields:
IF DATA-TYPE OF SQLVAR OF IN-SQLDA(INDEX) = 64
ACCEPT VAL OF PVARCHAR OF PARAMS(INDEX)
IF DATA-LEN OF IN-SQLDA(INDEX) > 58
MOVE 58 TO DATA-LEN OF SQLVAR OF IN-SQLDA(INDEX)
END-IF
* If you want SQL to check whether the string the user
* entered will fit into the database column, you can also
* determine the length of the user-supplied string and move
* that length to DATA-LEN OF SQLVAR OF IN-SQLDA(INDEX) and to
* LEN OF PVARCHAR OF PARAMS(INDEX).
ELSE
* Check for 16-bit integer:
IF DATA-TYPE OF SQLVAR OF IN-SQLDA(INDEX) <= 131
ACCEPT PSMLINT OF PARAMS(INDEX)
ELSE ...
* Continue to check for and store all possible data types.
Example 10-1. Evaluating Input Parameter Values (page 2 of 2)