ODBC Server Reference Manual

Stored Procedures
HP NonStop ODBC Server Reference Manual429151-002
5-22
Developing a Stored Procedure in COBOL
b. Send in a request from the client to execute the stored procedure.
Coding a Stored Procedure in COBOL
This subsection covers Steps 1 and 2 from “Developing a Stored Procedure in COBOL”
in greater detail, using the sample code in the file SP23COB for the stored procedure
DEPT9000 and the file SAMPLEC for the main routine of the sample server.
1. Set up the stored procedure name and point to the shell routines.
The PROGRAM-ID is set to the name to be used when configuring the stored
procedure into the sample server. The CONFIGURATION SECTION must include
a reference to the shell functions (SHELLO) or to SPELIBO if you are calling the
SPELIB functions directly.
IDENTIFICATION DIVISION.
*
*---------------------------------------------------------
* Program is the stored procedure name.
*---------------------------------------------------------
PROGRAM-ID. DEPT9000.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SPECIAL-NAMES.
*---------------------------------------------------------
* The shell routine is included via the object file
*---------------------------------------------------------
FILE "SHELLO" IS C-PROC.
Set up the WORKING-STORAGE section, including any SQLDA structures for
returning row data or for handling parameters. In this example, a SQLDA is defined
for returning five columns from the employee table. The WORKING-STORAGE
section should also include any host variables and other working variables. In this
example, there is a SELECT statement for returning the employee data for
department 9000.
WORKING-STORAGE SECTION.
*********************************************************
* INCLUDE SQLCA AND SQLSA *
*********************************************************
EXEC SQL INCLUDE SQLCA END-EXEC.
EXEC SQL INCLUDE SQLDA (SDAO23, 5, SDAN23, 30) END-EXEC.
*********************************************************
* DECLARE HOST VARIABLES *
*********************************************************
01 SP-STMT PIC X(120) VALUE SPACES.
01 SELECT-STMT.
05 FILLER PIC X(40) VALUE