SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Dynamic SQL With Descriptor Areas
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
10-18
Execute the Prepared Statement
...
EXEC SQL EXECUTE sqlstmt USING SQL DESCRIPTOR 'in_sqlda';
...
MOVE "UPDATE employee"
- " SET salary = salary * 1.1"
- " WHERE jobcode = CAST(? AS NUMERIC(4) UNSIGNED)"
- " AND salary < CAST(? AS NUMERIC(8,2) UNSIGNED)"
TO hv-sql-statement.
...
MOVE 2 TO desc-max.
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda'
WITH MAX :desc_max
END-EXEC.
...
EXEC SQL PREPARE sqlstmt FROM :hv-sql-statement END-EXEC.
EXEC SQL DESCRIBE INPUT sqlstmt
USING SQL DESCRIPTOR 'in_sqlda'
END-EXEC.
...
* Input the values for the jobcode and salary parms.
ACCEPT in-jobcode.
ACCEPT in-salary.
...
MOVE 1 TO desc-value.
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc-value
VARIABLE_DATA = :in-jobcode
END-EXEC.
MOVE 2 TO desc-value.
EXEC SQL SET DESCRIPTOR 'in_sqlda' VALUE :desc-value
VARIABLE_DATA = :in-salary
END-EXEC.
...
EXEC SQL EXECUTE sqlstmt
USING SQL DESCRIPTOR 'in_sqlda'
END-EXEC.
Execute the Prepared Statement
You have allocated the input and output SQL descriptor area, described parameters,
and set input values in SQL descriptor areas. You are ready to execute the prepared
SQL statement. The EXECUTE statement names both the input SQL descriptor area
and the output SQL descriptor area (if needed).
Use this general syntax:
For complete syntax, see the EXECUTE statement in the SQL/MX Reference Manual.
EXECUTE SQL-statement-name
USING SQL DESCRIPTOR in-descriptor-name
INTO SQL DESCRIPTOR out-descriptor-name;
COBOL