SQL/MP Programming Manual for COBOL85

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL85429326-004
10-8
Developing a Dynamic SQL Application
name of the parameter in NAMESBUF, the input names buffer. The prepared
statement is named S1.
EXEC SQL PREPARE S1 FROM :INTEXT END-EXEC.
EXEC SQL
DESCRIBE INPUT S1 INTO :IN-SQLDA NAMES INTO :NAMESBUF
END-EXEC.
5. The program enters a loop and prompts the user to supply values for successive
execution of the statement:
* BEGINNING OF LOOP
* PROMPT THE USER FOR A VALUE USING THE
* PARAMETER NAME FROM THE NAMES BUFFER.
...
* 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.