ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-26
Developing a Stored Procedure in COBOL
Before looking at the code to open the cursor and return the row data, it is
helpful to examine the code to set up the varptrs in the SQLDA structure for the
column data to be returned. This code is explained more fully in the NonStop
SQL/MP Programming Reference Manual for your programming language:
*--------------------------------------------------------
* Initialize before SELECT
* - set up var_ptr to point to the selected columns
* In this example, allocate var_ptr for 5 columns
*--------------------------------------------------------
MOVE 1 TO I.
ENTER TAL SQLADDR
USING EMPNUM OF EMP-REC
GIVING VAR-PTR OF SQLVAR OF SDAO23 ( I )
COMPUTE I = I + 1.
This code is repeated for each column.
The code to open the cursor and then return the row data, using the shell
function ENCODE_ROW_DATA, follows:
EXEC SQL OPEN CUR23 END-EXEC.
MOVE SPACE TO SP-DATA.
PERFORM 2020-FETCH-DATA
UNTIL NO-MORE-DATA.
2020-FETCH-DATA.
EXEC SQL
FETCH CUR23 USING DESCRIPTOR :SDAO23
END-EXEC.
*--------------------------------------------------------
* Call ENCODE_ROW_DATA to set up the IPC message with
* the row of data being returned.
*--------------------------------------------------------
IF SQLCODE = 0
ENTER C "ENCODE_ROW_DATA" IN C-PROC USING
SP-ENV,
WS-MAX-LEN,
SDAO23,
SP-BUFFER,
SP-REPLY
GIVING WS-RC
ELSE
IF SQLCODE = 100
MOVE "Y" TO SP-DATA.
IF NOT SPELIB-OK
PERFORM 9000-LIB-ERROR
EXIT PROGRAM.