ODBC Server Reference Manual
Stored Procedures
HP NonStop ODBC Server Reference Manual—429151-002
5-23
Developing a Stored Procedure in COBOL
"SELECT EMPNUM,FIRST_NAME,LAST_NAME,".
05 FILLER PIC X(40) VALUE
"DEPTNUM,SALARY FROM =EMPLOYEE ".
05 FILLER PIC X(40) VALUE
"WHERE DEPTNUM = 9000 BROWSE ACCESS ".
EXEC SQL SOURCE CODECOB (ERRWS) END-EXEC.
EXEC SQL END DECLARE SECTION END-EXEC.
/
*********************************************************
* COBOL PROGRAM WORKING-STORAGE *
*********************************************************
01 SP-VARIABLES.
05 SP-DATA PIC X VALUE SPACE.
88 NO-MORE-DATA VALUE "Y".
05 SPE-23-MAX-ENTRIES PIC S9(2) VALUE 5.
05 WS-MAX-LEN PIC 9(8) COMP VALUE 3000.
05 WS-RC PIC 9(6) COMP VALUE 32450.
88 SPELIB-OK VALUE 32450.
01 I PIC S9.
One item to note is that the variable WS-RC has been initialized to the value
32450. This is the value returned by the SPELIB library and shell functions to
indicate a successful completion (SPELIB_OK). This value is defined in the C “h”
file, spelibh, but this file cannot be accessed from a COBOL program, so it is
declared explicitly.
2. Set up the LINKAGE SECTION and PROCEDURE DIVISION for the parameters
passed to this stored procedure when it is called from the main program. The
buffer size is dependent on the stored procedure and must be at least as large as
the max_buffer_len parameter that is set when the stored procedure is registered
with the NonStop ODBC Server. In this example, the buffer size is set to 3000.
LINKAGE SECTION.
*-----------------------------------------------------------
* Parameters passing between the shell routines when this
* stored procedure is called.
*-----------------------------------------------------------
01 SP-MAX-LEN PIC 9(9) COMP.
01 SP-BUFFER PIC X(3000).
01 SP-ENV PIC X(500).
01 SP-REPLY PIC 9(4) COMP.
01 SP-RC PIC 9(4) COMP.
/
*-----------------------------------------------------------
* Standard parameters for every stored procedure.
*-----------------------------------------------------------
PROCEDURE DIVISION USING SP-ENV,
SP-MAX-LEN,