SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-4
Specifying Input Parameters and Output Variables
THEN STATEMENT := STATEMENT &' EMPNUM ';
...
The statement now contains the string SELECT EMPNUM. You continue to
construct the entire statement based on the values the user entered.
6. After the database request has been processed, construct the reply message.
Instead of formatting and displaying the output values, you assign the values to the
reply message. The first field in the reply message record must contain the reply
code to communicate with the SCREEN COBOL requester.
7. Call REPLY to send the reply message to the requester (screen program).
WRITECOUNT := SIZEOF(REPLY_MSG);
STATUS := REPLY (WADDR(REPLY_MSG), WRITECOUNT);
IF STATUS <> OK_CONDITION THEN ... { process error }
Restrictions for Record Layout
If possible, you should 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 Pascal lay out fields in records when fields with an odd number
of bytes are included in a record. You must take special care that the field layout in the
Pascal server matches the layout in the SCREEN COBOL requester.
To avoid problems, follow these guidelines:
•
Use DDL to describe the request and reply messages and then use the COBOL 74
and Pascal 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 (?P1). 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.
SQL returns data to the 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. The program uses the
DESCRIBE statement with an output SQLDA structure to get information about the
output variables.