Dynamic operations offer a way to execute SQL commands that cannot
be completely defined until run time. You accept part or all of
an SQL command that can be dynamically preprocessed from the user, then
use one of the following techniques to preprocess and execute the
command:
You can use the PREPARE command to preprocess a command, then
execute it later during the same transaction using the EXECUTE command.
The PREPARE and EXECUTE commands must be in the same program or
subprogram.
You can use the EXECUTE IMMEDIATE command to preprocess and
execute an SQL command in one step.
The data manipulation commands you can dynamically preprocess from
an ALLBASE/SQL COBOL program are: DELETE, INSERT, and UPDATE.
Refer to the ALLBASE/SQL Reference Manual for a list of
other commands you can dynamically preprocess.
In the following example, an SQL command entered by the program
user is handled by using the PREPARE and EXECUTE commands. The
command to be dynamically preprocessed is stored in a host variable
named DYNAMICCOMMAND, declared to be 1024 bytes long, the
maximum length of a dynamically preprocessed SQL command.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 DYNAMICCOMMAND PIC X(1024).
EXEC SQL END DECLARE SECTION END-EXEC.
.
.
.
PROCEDURE DIVISION
The program accepts an SQL command from the
user and moves it into DYNAMICCOMMAND for
preprocessing.
EXEC SQL PREPARE DYNAMCOMMAND FROM :DYNAMICCOMMAND END-EXEC.
Later during the same transaction, the prepared
command is executed as follows:
EXEC SQL EXECUTE DYNAMCOMMAND END-EXEC.
|
Dynamic preprocessing from a COBOL program is addressed in Chapter 10.