SQL/MP Programming Manual for COBOL85
Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL85—429326-004
10-10
Declaring a Host Variable
Declaring a Host Variable
In a Declare Section in the Data Division, declare a host variable to serve as the buffer
or “container” for the SQL statement:
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 STATEMENT-BUFFER PIC X(256) VALUE SPACES.
EXEC SQL END DECLARE SECTION END-EXEC.
Declaring the SQLCA and SQLSA Data Structures
In the Data Division, declare the SQLCA and SQLSA data structures using INCLUDE
directives:
EXEC SQL INCLUDE SQLCA END-EXEC.
EXEC SQL INCLUDE SQLSA END-EXEC.
The SQLSA stores information about the statement. (In contrast, the SQLDA stores
information about parameters.)
Defining Storage for Input and Output Parameters
This subsection describes how to allocate storage for parameters. The discussion
starts with a description of the SQLDA structure and associated buffers.
SQLDA Structure, Names Buffer, and Collation Buffer
SQL/MP uses the SQL descriptor area (SQLDA) to return information about input
parameters and output parameters in dynamic SQL statements. The SQLDA also
stores pointers to these optional data buffers:
•
The names buffer, which stores the names of input parameters or lists the names
of selected columns.
•
The collation buffer, which receives copies of any collations used by columns in the
query.
You can use the SQLDA data structure in:
•
A DESCRIBE INPUT statement to return information about input parameters.
•
A DESCRIBE statement to return information about output columns or copies of
any collations used by the columns
•
The USING DESCRIPTOR clause of a FETCH statement to retrieve rows from an
SQL table.
•
The USING DESCRIPTOR clause of an EXECUTE statement to execute a
dynamic SQL statement.
The sizes of the SQLDA and names buffer depend on the number of input parameters
or output parameters referenced in dynamic SQL statements. Your program can have