SQL/MX Guide to Stored Procedures in Java (G06.24+, H06.03+)

Invoking SPJs in NonStop SQL/MX
HP NonStop SQL/MX Guide to Stored Procedures in Java523727-004
5-10
Input and Output Descriptors
number of formal OUT and INOUT parameters because each output parameter must
be represented by a single dynamic parameter in the CALL statement.
Example of Using Input and Output Descriptors
To code an embedded SQL program to use a dynamic CALL statement with SQL
descriptor areas:
1. Allocate input and output SQL descriptor areas.
Allocate an input SQL descriptor area for dynamic input parameters associated
with the IN or INOUT mode, and allocate an output descriptor area for dynamic
output parameters associated with the OUT or INOUT mode:
EXEC SQL ALLOCATE DESCRIPTOR 'in_sda';
EXEC SQL ALLOCATE DESCRIPTOR 'out_sda';
For the syntax of the ALLOCATE DESCRIPTOR statement, see the SQL/MX
Reference Manual.
2. Prepare the CALL statement.
Store the CALL statement in a host variable and then prepare the CALL statement.
The PREPARE statement checks the statement syntax, determines the data types
of parameters, compiles the CALL statement, and associates the CALL statement
with a statement name that you can use in a subsequent EXECUTE statement:
/* Build the CALL statement in a char buffer. */
strcpy(hv_sql_stmt,
"CALL samdbcat.persnl.adjustsalary(?,?,?)");
/* IN, IN, OUT */
/* Prepare the statement. */
EXEC SQL PREPARE sqlstmt FROM :hv_sql_stmt;
For the syntax of the PREPARE statement, see the SQL/MX Reference Manual.
3. Describe the input and output parameters.
The DESCRIBE statement stores information about the dynamic input or output
parameters of a prepared CALL statement in an SQL descriptor area. Use these
DESCRIBE statements to populate the SQL input and output descriptor areas:
°
DESCRIBE INPUT initializes the input SQL descriptor area based on the
dynamic input parameters (associated with the IN or INOUT mode) for a
prepared CALL statement:
EXEC SQL DESCRIBE INPUT sqlstmt
USING SQL DESCRIPTOR 'in_sda';
°
DESCRIBE OUTPUT stores descriptions in the output SQL descriptor area of
dynamic output parameters (associated with the OUT or INOUT mode) from a
prepared CALL statement: