SQL/MP Programming Manual for COBOL

Dynamic SQL Operations
HP NonStop SQL/MP Programming Manual for COBOL529758-003
10-36
Constructing a Reply Message
includes. As each value is read, you concatenate the corresponding text to form the
statement.
Example
Suppose that an application screen describes a personnel record. If any column does
not have a value, the user can enter N. LIST-MSG is the name of the request message
you defined. The code in these examples checks the EMPNUM field in
LIST-MSG and, if required, concatenates the text “EMPNUM” to the statement you are
constructing:
One way to concatenate text in the statement is to use the STRING verb:
01 STATEMENT PIC X(256) VALUE SPACES.
...
MOVE "SELECT" TO STATEMENT.
...
IF EMPNUM OF LIST-MSG NOT = "N"
STRING "EMPNUM" DELIMITED BY SIZE
INTO STATEMENT
END-STRING
ELSE IF EMPNAME OF LIST-MSG NOT = "N"
...
ELSE ...
Another way to concatenate text is to use PERFORM VARYING:
01 STATEMENT PIC X(256) VALUE SPACES.
01 INDX PIC 999 COMP.
...
MOVE "SELECT" TO STATEMENT.
...
IF EMPNUM OF LIST-MSG NOT = "N"
PERFORM VARYING INDX FROM 256 BY -1
UNTIL STATEMENT (INDX:1) NOT = SPACE
END-PERFORM
MOVE "EMPNUM" TO STATEMENT(INDX + 2:)
ELSE IF EMPNAME OF LIST-MSG NOT = "N"
...
ELSE ...
In either of these examples, the statement could now contain the string SELECT
EMPNUM. You continue to construct the entire statement based on the values the user
entered.
Constructing a Reply Message
When you construct the reply message after the database request has been
processed, you assign the output values to the reply message instead of formatting
and displaying the values. You must define a reply message for every possible set of
columns in the reply. The first field in the reply message record must contain the reply
code to communicate with the SCREEN COBOL requester.