SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-21
Handling Parameters
from INPUT-NUM or OUTPUT-NUM, respectively. On each iteration, follow these
steps:
1. Check the DATA-TYPE field. If necessary, adjust the data type and reset DATA-
LEN and PRECISION accordingly. For an example of this, see Example 10-1 on
page 10-25.
2. Allocate an amount of memory equal to DATA-LEN for the parameter.
3. Initialize EYE-CATCHER, NUM-ENTRIES, VAR-PTR, and IND-PTR in the SQLDA
structure.
4. Use the NULL-INFO field to tell whether a parameter can contain a null value. Use
the IND-PTR field to tell is the associated value is actually null.
5. To display column headings for output parameters (as SQLCI does), loop through
the names buffer to read the corresponding name for each column and display the
column names.
If you know the number and data types of your parameter values, you can set
DATA-TYPE, DATA-LEN, and VAR-PTR.
The next subsections provide more information about each of these steps.
Checking the DATA-TYPE Field
The DATA-TYPE field in the SQLDA indicates the data type of the parameter. Check
the DATA-TYPE field to decide how to store input parameter values and how to display
output column values. When you evaluate data types, check for these numeric ranges:
You might need to change the value of the DATA-TYPE field if the data type of the
parameter you declared is compatible with the data type SQL uses.
Checking the DATA-LEN Field
If your program must handle numeric values with scale, you need to read scale
information from the output SQLDA. DESCRIBE places this information in bits 0
through 7 of the DATA-LEN field in the SQLVAR entry.
If you can ignore scale, you can set bits 0 through 7 of the DATA-LEN field to 0,
causing data truncation. Otherwise, COBOL data types handle scale. To determine
whether scale is present, check whether DATA-LEN is greater than 255. If it is, the
upper byte has a nonzero value, and scale information is present.
0 – 63 CHARACTER data
64 – 127 VARCHAR data
128 – 191 VARCHAR data
192 – 212 Date-time or INTERVAL data