SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-136
COBOL Examples of EXECUTE
This example uses extended statement names:
...
strcpy(stmt,"ins_cust1");
EXEC SQL PREPARE :stmt FROM :stmt_buffer;
EXEC SQL EXECUTE :stmt;
...
strcpy(stmt,"ins_cust2");
EXEC SQL PREPARE :stmt FROM :stmt_buffer;
EXEC SQL EXECUTE :stmt;
COBOL Examples of EXECUTE
Prepare and execute an UPDATE statement with dynamic input parameters:
...
MOVE "UPDATE SALES.CUSTOMER SET CREDIT = ?
& " WHERE CUSTNUM = CAST(? AS NUMERIC(4) UNSIGNED)"
TO stmt-buffer.
...
EXEC SQL PREPARE upd_cust FROM :stmt-buffer END-EXEC.
...
* Input values for parameters into host variables
ACCEPT in-credit.
...
ACCEPT in-custnum.
...
EXEC SQL EXECUTE upd_cust
USING :in-credit, :in-custnum
END-EXEC.
...
Prepare a statement, allocate input and output descriptor areas, describe the input
and output descriptor areas, and execute the statement by using the content of the
descriptor areas:
...
MOVE "SELECT * FROM EMPLOYEE"
& " WHERE EMPNUM = CAST(? AS NUMERIC(4) UNSIGNED)"
TO stmt-buffer.
...
EXEC SQL PREPARE S1 FROM :stmt-buffer END-EXEC.
...
MOVE 1 TO desc-max.
EXEC SQL ALLOCATE DESCRIPTOR 'in_args'
WITH MAX :desc-max END-EXEC.
MOVE 6 TO desc-max.
EXEC SQL ALLOCATE DESCRIPTOR 'out_cols'
WITH MAX :desc-max END-EXEC.
...
EXEC SQL DESCRIBE INPUT S1
USING SQL DESCRIPTOR 'in_args'
END-EXEC.
EXEC SQL DESCRIBE OUTPUT S1
USING SQL DESCRIPTOR 'out_cols'