ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-25
Developing a Stored Procedure in COBOL
Call initialization, if needed, then execute the main logic.
*********************************************************
* MAIN PROGRAM
*********************************************************
0000-MAIN.
IF SP-FIRST-TIME = "Y"
PERFORM 1000-INITIALIZE.
PERFORM 2000-PROCESS-REQUEST.
PERFORM 3000-END-PROCESS.
MOVE WS-RC TO SP-RC.
MOVE WS-MAX-LEN TO SP-MAX-LEN.
EXIT PROGRAM.
Encode initialization. Call the shell function ENCODE_INIT.
*--------------------------------------------------------
* The reply buffer needs to be set up by calling
* ENCODE_INIT.
*--------------------------------------------------------
ENTER C "ENCODE_INIT" IN C-PROC USING
SP-ENV,
WS-MAX-LEN,
SP-BUFFER,
SP-REPLY
GIVING WS-RC.
IF NOT SPELIB-OK
PERFORM 9000-LIB-ERROR
EXIT PROGRAM.
The purpose of the remaining code is to select employee data for department
9000. The steps involved are to encode a row descriptor for the rows to be
returned, open the cursor for selecting the data from the table, and then
encode the row data for each row to be returned.
The first step is to encode the row descriptor:
*--------------------------------------------------------
* Call ENCODE_ROW_DESCRIPTOR to set up IPC message with
* column colnames
*--------------------------------------------------------
ENTER C "ENCODE_ROW_DESCRIPTOR" IN C-PROC USING
SP-ENV,
WS-MAX-LEN,
SDAO23,
SP-BUFFER,
SP-REPLY
GIVING WS-RC.
IF NOT SPELIB-OK
PERFORM 9000-LIB-ERROR
EXIT PROGRAM.