SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
COBOL Sample Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
C-10
Using SQL Descriptor Areas in Dynamic SQL
 PROCEDURE DIVISION.
 START-LABEL.
 DISPLAY "This example uses SQL descriptor areas".
 EXEC SQL WHENEVER SQLERROR GOTO sqlerrors END-EXEC.
* Initialize the output variable in SELECT list.
 DISPLAY "Enter the columns to be retrieved,"
 & " separated by commas: ".
 ACCEPT in-columns.
 DISPLAY hv-sql-stmt.
* Allocate SQL descriptor area for input parameters.
 MOVE 1 TO hv-desc-max.
 EXEC SQL
 ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :hv-desc-max
 END-EXEC.
* Allocate SQL descriptor area for output values.
 MOVE 6 TO hv-desc-max.
 EXEC SQL
 ALLOCATE DESCRIPTOR 'out_sqlda' WITH MAX :hv-desc-max
 END-EXEC.
* Prepare dynamic SQL statement.
 MOVE hv-sql-stmt TO hv-prepare-stmt.
 EXEC SQL
 PREPARE sqlstmt FROM :hv-prepare-stmt
 END-EXEC.
* Describe the SQL descriptor area for input parameters.
 EXEC SQL
 DESCRIBE INPUT sqlstmt USING SQL DESCRIPTOR 'in_sqlda'
 END-EXEC.
* Describe the SQL descriptor area for SELECT values.
 EXEC SQL
 DESCRIBE OUTPUT sqlstmt USING SQL DESCRIPTOR 'out_sqlda'
 END-EXEC.
* Initialize the input parameter in the WHERE clause
 DISPLAY "Enter the employee number to be retrieved: ".
 ACCEPT in-empnum.
* Set the value of the input parameter in 
* the input SQL descriptor area
 MOVE 1 TO hv-desc-value.
 EXEC SQL
 SET DESCRIPTOR 'in_sqlda' VALUE :hv-desc-value 
 VARIABLE_DATA = :in-empnum
 END-EXEC. 
Example C-4. Using Descriptor Areas With DESCRIBE (page 2 of 4)










