SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-27
Allocating and Filling in Output Variables
Allocating and Filling in Output Variables
To allocate space for output variables, you perform essentially the same set of 
operations described for allocating space for input parameters except that the pointers 
point to the output SQLDA and names buffer. To get the descriptions of the output 
variables into the output SQLDA, you use the DESCRIBE statement instead of 
DESCRIBE INPUT:
EXEC SQL DESCRIBE statement or :statement-hostvar
 INTO :osqlda^ptr
 NAMES INTO :onamesbuf^ptr.namestr;
DESCRIBE places the descriptions of the column values to be output from the 
database into the location in memory pointed to by OSQLDA^PTR and the names of 
the columns into the location pointed to by ONAMESBUF^PTR. For code to allocate 
memory, see Allocating Memory for the Values.
 on page 7-20.
Handling Scale
If your program must handle numeric values with scale, you will need to read scale 
information from the output SQLDA. DESCRIBE places this information in bits 0:7 of 
the DATA^LEN field in the SQLVAR array. If you can ignore scale, you can set the 
DATA^LEN field to 0, causing data truncation; otherwise, you will need to save the 
scale information and write a procedure to handle scale.
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.
Displaying Output
To display output from the database after the cursor FETCH, you perform these tasks:
1. Set pointers to the beginning of the first SQLVAR array and to the beginning of the 
names buffer.
2. Get the number of output columns from the SQLDA.
3. Write the column name to the output file using the names buffer pointer (only if you 
are doing a repetitive display of the column names).
4. Read the DATA^TYPE field from the SQLVAR array to get the data type of the 
column value to be written.
5. Retrieve the value from the location pointed to by the VAR^PTR field in the 
SQLVAR array. Format the value and write it to output. The steps to use depend on 
the data type of the value.










