The following example demonstrates using prepare and execute in method 2. In this example, the user is prompted to enter a where clause that determines which rows in the titles table to update. For example, entering “1.1” increases the price by 10 percent.
01 CUST-TYPE PIC X.
88 BIG-CUSTOMER VALUE "B".
88 OTHER-CUSTOMER VALUE "O".
. . .
exec sql begin declare section end-exec
01 MULTIPLIER PIC S9(2) COMP.
01 CMD-1 PIC X(50).
01 SRC-COND PIC X(50).
01 SQLSTR1 PIC X(200).
exec sql end declare section end-exec
MOVE "UPDATE titles SET
" price = price + (price * ? / 100)
WHERE "
TO CMD-1.
DISPLAY "ENTER SEARCH CONDITION:".
ACCEPT SRC-COND.
STRING CMD-1 SRC-COND DELIMITED BY SIZE
INTO SQLSTR1.
exec sql prepare statement1 from :SQLSTR1
end-exec.
IF BIG-CUSTOMER
MOVE 10 TO MULTIPLIER
ELSE
MOVE 25 TO MULTIPLIER.
exec sql execute statement1 using :MULTIPLIER
end-exec.