SQL Programming Manual for TAL

Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL527887-001
7-4
Specifying Input Parameters and Output Variables
Restrictions for Record Layout
If possible, avoid having any fields in your requester or server messages that are an
odd number of bytes long. There are some subtle differences in the way
SCREENÊCOBOL and TAL generate fields in records when fields contain an odd
number of bytes. Therefore, take special care that the field layout in the TAL server
matches the layout in the SCREEN COBOL requester. Therefore, to avoid problems,
follow these guidelines:
Use DDL to describe the request and reply messages and then use the TAL and
COBOL85 forms of the structures derived from the DDL.
In the SCREEN COBOL requester, avoid constructing messages by listing several
data items in the SEND statement; instead, the requester should send a single
structure to the server.
Specifying Input Parameters and Output Variables
A dynamic SQL statement can contain input parameters. Input parameters might
denote criteria to be used in a WHERE clause, values to be inserted into the database,
or values used to update or delete database records. Input parameters are specified in
the statement as either a question mark (?) or a question mark plus a name (?VAL). An
input parameter can appear in an SQL expression wherever a constant can appear.
The program uses the DESCRIBE INPUT statement with an input SQLDA structure to
get information about the input parameters and obtain pointers to the input values.
NonStop SQL returns data to a program through output variables. Output variables are
user-defined areas in the program. Output variables can be host variables or individual
data buffers to which the program’s output SQLDA structure points. Output variables
usually contain columns returned from a SELECT statement. A program uses the
DESCRIBE statement with an output SQLDA structure to get information about the
output variables.
This sequence shows a typical context for input parameters and output variables in
dynamic SQL operations. If you know in advance which columns will be selected, you
can use this sequence.
HOSTVAR ':=' "SELECT empnum, salary FROM =employee
WHERE SALARY > ?sal"; ! input parameter ?sal
!.. dynamically compile the statement, use DESCRIBE INPUT
! to get information about input parameters, prompt the
! user and read in the value for ?sal, declare and open
! a cursor for the statement.
...
EXEC SQL
FETCH cursor INTO :enum, :salary; ! output variables
! :enum and :dept