0% found this document useful (0 votes)
236 views6 pages

Developing COBOL Stored Procedures

Developing COBOL stored procedures involves 5 key steps: 1) Set up the WLM environment and language environment. 2) Define the stored procedure in DB2. 3) Create the COBOL source code for the stored procedure. 4) The source code includes identification, environment, working storage, linkage, and procedure divisions. 5) The calling program makes a simple call to the stored procedure, passing variables defined in its working storage section.

Uploaded by

Vivek Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
236 views6 pages

Developing COBOL Stored Procedures

Developing COBOL stored procedures involves 5 key steps: 1) Set up the WLM environment and language environment. 2) Define the stored procedure in DB2. 3) Create the COBOL source code for the stored procedure. 4) The source code includes identification, environment, working storage, linkage, and procedure divisions. 5) The calling program makes a simple call to the stored procedure, passing variables defined in its working storage section.

Uploaded by

Vivek Mishra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Developing COBOL stored Procedures

There are a sequence of steps which should be done for developing COBOL stored procedures -

1) Set WLM environment


2) Set Language Environment
3) Define Stored procedure to DB2
4) Create Stored Procedure Source Code
5) Calling Program set up

1) & 2) are initial setup and once they are done, no need to repeat them again. [Application programmers can
skip it].

Let's go through the next 3 options


Define Stored procedure to DB2
So once a stored procedure is defined, Next step is to create its COBOL source code.

Create Stored Procedure Source Code

Now first a few things to remember -


1) The source code of COBOL stored procedure is like a COBOL subprogram
2) LINKAGE-SECTION will receive values from calling PGM.
3) Procedure Division using statement would be having list of variables being accepted.

At a Pseudocode Level a Stored Procedure can be described like this -

*Declare Identification division and Environment Division [No file Section needed].
* Working-Storage Section - Variables, SQLCA & DCLGEN for DB2 table to be accessed.
* Linkage-Section - List of Variables passed by Calling PGM.
* Procedure Division - Procedure Division Using would be having list of variables passed, logic to fetch data
from DB2 using SQL.

A sample Program has been posted below:-

IDENTIFICATION DIVISION.
PROGRAM-ID. EMPDTL1C.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-PARMAREA.
02 WS-EMPNO PIC X(06).

-----------------------------------------------------------------
VARIABLES FOR ERROR-HANDLING
-----------------------------------------------------------------
01 ERROR-MESSAGE.
02 ERROR-LEN PIC S9(4) COMP VALUE +960.
02 ERROR-TEXT PIC X(80) OCCURS 12 TIMES
INDEXED BY ERROR-INDEX.
77 ERROR-TEXT-LEN PIC S9(9) COMP VALUE +80.

-----------------------------------------------------------------
SQLCA AND DCLGENS FOR TABLES
-----------------------------------------------------------------
EXEC SQL INCLUDE SQLCA END-EXEC.

EXEC SQL INCLUDE EMP END-EXEC.

LINKAGE SECTION.
01 PEMPNO PIC X(6).
01 PFIRSTNME.
49 PFIRSTNME-LEN PIC S9(4) COMP.
49 PFIRSTNME-TEXT PIC X(12).
01 PMIDINIT PIC X(1).
01 PLASTNAME.
49 PLASTNAME-LEN PIC S9(4) COMP.
49 PLASTNAME-TEXT PIC X(15).
01 PWORKDEPT PIC X(3).
01 PHIREDATE PIC X(10).
01 PSALARY PIC S9(7)V9(2) COMP-3.
01 PSQLCODE PIC S9(9) COMP.
01 PSQLSTATE PIC X(5).
01 PSQLERRMC.
49 PSQLERRMC-LEN PIC S9(4) COMP.
49 PSQLERRMC-TEXT PIC X(250).

PROCEDURE DIVISION USING PEMPNO, PFIRSTNME, PMIDINIT, PLASTNAME,


PWORKDEPT, PHIREDATE, PSALARY, PSQLCODE,PSQLSTATE, PSQLERRMC.
----------------------------------------------------------------
MAIN PROGRAM ROUTINE
-----------------------------------------------------------------
1000-MAINLINE.
EXEC SQL
SET CURRENT SQLID = USER
END-EXEC.
PERFORM 2000-PROCESS THRU 2000-EXIT.
GOBACK.
1000-MAIN.
EXIT.
2000-PROCESS.
MOVE PEMPNO TO WS-EMPNO.
DISPLAY 'WS-EMPNO = ' WS-EMPNO.

EXEC SQL
SELECT
FIRSTNME,
MIDINIT,
LASTNAME,
WORKDEPT,
HIREDATE,
SALARY
INTO
:PFIRSTNME
,:PMIDINIT
, :PLASTNA ME
, :PWORKDEPT
, :PHIREDATE
, :PSALARY
FROM EMP
WHERE EMPNO = :WS-EMPNO
END-EXEC.

DISPLAY '++ SQLCODE AFTER SELECT = ' SQLCODE.


MOVE SQLCODE TO PSQLCODE.
MOVE SQLSTATE TO PSQLSTATE.
MOVE SQLERRMC TO PSQLERRMC.

EVALUATE SQLCODE
WHEN 0
CONTINUE
WHEN OTHER
PERFORM 9000-DBERROR THRU 9000-EXIT
END-EVALUATE.

2000-EXIT.
EXIT.

-----------------------------------------------------------------
9000-DBERROR - GET ERROR MESSAGE
-----------------------------------------------------------------
9000-DBERROR.
CALL 'DSNTIAR' USING SQLCA ERROR-MESSAGE ERROR-TEXT-LEN.
IF RETURN-CODE = ZERO
PERFORM 9999-ERROR-DISPLAY THRU 9999-EXIT
VARYING ERROR-INDEX FROM 1 BY 1
UNTIL ERROR-INDEX GREATER THAN 12.
GOBACK.
9000-EXIT.
EXIT.

-----------------------------------------------------------------
9999-ERROR-DISPLAY
-----------------------------------------------------------------
9999-ERROR-DISPLAY.
DISPLAY ERROR-TEXT (ERROR-INDEX).
9999-EXIT.
EXIT.

*****************************************************************************
Calling Program Set up
Well We don't need to do much in calling program except making call to stored procedure

EXEC SQL
CALL EMPDTL1C( :PEMPNO
,:PFIRSTNME
,:PMIDINIT
,:PLASTNAME
,:PWORKDEPT
,:PHIREDATE
,:PSALARY
,:PSQLCODE
,:PSQLSTATE
,:PSQLERRMC
)
END-EXEC.

Note :- All the variables used above in CALL statement need to be declared in WORKING-STORAGE Section.

You might also like