SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-9
Developing a Dynamic SQL Application
* STORE THE VALUE IN AN INPUT BUFFER
* POINTED TO BY IN-SQLDA.
* EXECUTE THE STATEMENT USING EACH SUCCESSIVE VALUE.
EXEC SQL EXECUTE S1 USING DESCRIPTOR :IN-SQLDA END-EXEC.
* END OF LOOP
Using Indicator Parameters
A program uses an indicator parameter to indicate that a null value was entered for a
parameter. The indicator parameter follows the parameter in the SQL statement as
shown in the next example:
INSERT INTO =employee VALUES (1000, ?p INDICATOR ?i );
If a user enters a null value for ?P, the program should set ?I to a value less than zero.
If a user enters a nonnull value for ?P, the program should set ?I to 0. Both ?P and ?I
are in the names buffer, so the program can prompt the user for a null value.
Developing a Dynamic SQL Application
The simplest type of dynamic SQL program does not have any input parameters or
output parameters. This type of program processes statements such as CREATE
TABLE or DROP INDEX, which do not require input parameters.
These features add complexity to dynamic SQL programs:
Support for input or output parameters. For example, a SELECT statement can
add complexity to a dynamic SQL program. The program cannot determine the
number of SELECT columns and input parameters until run time.
Support for null values and indicator parameters and variables.
This subsection includes information about how to support parameters and null values
in dynamic programs. The topics might not all apply to your application.
In general, the steps in a dynamic SQL application are:
1. Declare a host variable for the SQL statement to be submitted.
2. Declare the SQLCA and SQLSA data structures.
3. If you plan to support input or output parameters in the SQL statement, perform
these steps:
a. Declare the SQLDA, names buffer, if desired, and collation buffer, if desired, to
describe the parameters.
b. Define buffers for parameter values of different data types.