SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-22
Handling Parameters
The same considerations apply if your program must handle precision for date-time,
INTERVAL, FLOAT, or binary numeric values. The precision information is in the
PRECISION field of the SQLVAR entry.
This example checks for scale in an output value and sets the scale information to 3 for
numeric and decimal items. You would follow a similar procedure to handle a scaled
input parameter value, using the input SQLDA instead of the output SQLDA.
* Set DATA-LEN to (3,8) for numeric and to (3,12)
* for decimal if scale exists. DATA-TYPE between 127 and
* 150 is numeric:
IF DATA-TYPE OF SQLVAR OF OUT-SQLDA (INDEX) > 127
AND DATA-LEN OF SQLVAR OF OUT-SQLDA (INDEX) > 255
IF DATA-TYPE OF SQLVAR OF OUT-SQLDA (INDEX) < 150
* Move a binary 3 to upper byte and a binary 8 to lower byte:
MOVE 776 TO DATA-LEN OF SQLVAR OF OUT-SQLDA(INDEX)
ELSE
* Move a binary 3 to upper byte and a binary 12 to lower
* byte:
MOVE 780 TO DATA-LEN OF SQLVAR OF OUT-SQLDA (INDEX)
END-IF
To find the decimal equivalents for binary values, start Inspect and enter the
hexadecimal equivalent for the decimal value in each byte:
>INSPECT
* You are in INSPECT here
--display (%h0308) in d
776
--exit
* You are in your program here
... MOVE 776 TO DATA-LEN OF OUTPUT-SQLDA
Checking the PRECISION Field for Character Set ID
For character (including VARCHAR) parameters and variables, the PRECISION field
contains the character set ID. When a dynamic SQL statement executes, SQL/MP
checks the PRECISION field to ensure that the character set ID matches the expected
character set of the parameter, which is determined by the
COLUMNS.CHARACTERSET value.
If the character sets do not match, SQL/MP returns an error. If, however, the program
expects an UNKNOWN character set and the CHARACTERSET value for the
parameter indicates a single-byte character set, SQL/MP does not return an error.
Initializing the SQLDA Structure
When a program issues a DESCRIBE INPUT or DESCRIBE statement, the system
supplies values for all fields of the SQLDA except EYE-CATCHER, NUM-ENTRIES,
VAR-PTR, and IND-PTR. If an application supports parameters, it must explicitly