Professional Documents
Culture Documents
• A stored procedure is a program which runs inside a DB2 subsystem and can
update DB2 objects. It can be in any language, but for our purposes will be
written in Cobol. It can be called from application programs which connect with
DB2 including MVS batch, CICS and web applications. Pre-defined. parameters
are passed to and from the stored procedure.
Figure 1:
• Stored procedures are compiled and then linkedited into special loadlibs. There
are some specific compile and link parameters required for stored procedures.
The PPS production loadlib for stored procedures is
A3257.PPS.PROD.SPLOAD. The DBRM members are saved in
A3257.PPS.PROD.SPDBRM. In Endevor the stored procedure processing
group is COBSP.
• The loadlib for stored procedures must be defined to DB2 in STEPLIB of the
DB2xSPAS job (SPAS means Stored Procedure Address Space)
• After a stored procedure has been recompiled, it is necessary to stop and restart
the procedure using the DB2 COMMANDS dialog (DB2.7). Occasionally after an
abend it may be necessary to restart a stored procedure in the same way.
Example:
-STOP PROCEDURE(SFHRSDD.SFIIDSVR)
-START PROCEDURE(SFHRSDD.SFIIDSVR)
• Any DB2 COBOL program can call a stored procedure which has been correctly
defined, compiled and bound using an "EXEC SQL CALL" command.
• Other non-COBOL applications can call the stored procedure using the DB2
syntax for the application type.
Figure 2:
EXEC SQL
CALL SFIIDSVR(:PRM-CALL-TYPE-IN
,:PRM-SYSTEM-NAME-IN
,:PRM-USERID-IN
,:PRM-TIME-IN
,:PRM-SYSTEM-IID-IN
,:PRM-INDIVIDUAL-ID-IN
,:PRM-REFERRED-ID-IN
,:PRM-STATUS-IN
,:PRM-ACCESS-FLAG-IN
,:PRM-CLOAKED-FLAG-IN
,:PRM-ISA-DATA-IN
,:PRM-QUALS-COUNT-IN
,:PRM-QUALIFIERS-IN
,:PRM-STATUS-OUT
,:PRM-RETURN-CODE-OUT
,:PRM-RETURNEE-COUNT-OUT
,:PRM-RETURNEE-DATA-OUT)
END-EXEC.
Programs Called By Stored Procedures
• A stored procedure may call another program which may not itself be a stored
procedure using a regular call statement (not EXEC SQL CALL). All programs
called by stored procedures must also reside in the stored procedure loadlib.
These called programs are compiled using the COBSP processing group, with
DBRM saved in the stored procedure DBRM library and linkedited to the stored
procedure loadlib.
Tri-Use Programs
• In some cases, a program may be called by a stored procedure, but also called
by a CICS or batch program. These are called tri-use programs. They are
compiled and bound 3 times: once for batch, once for CICS and once as a stored
procedure. In each case, the DBRM information is stored in a separate
DBRMLIB, eg. A1555.AIS.PROD.DBRMLIB for batch,
A1555.AIS.PROD.C ICSDBRM for CICS and A1555.AIS.PROD.SPDBRM for
stored procedure. The Endevor processing type for tri-use programs is COB3.
• Tri-use programs must also be bound 3 times pointing to the appropriate DBRM
library. For batch, the called program is bound into the plan for the calling
program(s). For CICS the called program is bound into a package with a CICS
collection ID, eg. PP2ACOLL. For stored procedure use, the called program is
bound into a package with a stored procedure collection ID, eg. SP2ACOLL.
Debugging Stored Procedures
• Cobol Displays can be added to stored procedures. Adding the following line to the
very beginning of a program will control the output DD of the displays:
PROCESS OUTDD(xxxxxxxx). It is recommended that xxxxxxxx be the name of the
program. Then the displays can be seen in the xxxxxxxx output DD of the
DB2xSPAS job.
• Abends: When a stored procedure abends, there may be information about the
abend in the SYSOUT output DD of the DB2xSPAS job. However, if a CICS
program calls a stored procedure and the EXEC SQL CALL statement gets an error
SQLCODE, that information will appear in the output of the CICS job.
• When SFIIDSVR abends, the EXEC SQL CALL statement from UCIID100 will
usually get a -430 SQLCODE. Frequently, after that, ANY call to SFIIDSVR will
result in a -471 SQLCODE which says that the stored procedure is stopped. This
means that a -START PROCEDURE command must be issued for the stored
procedure before it can be used again.
Triggers
• Triggers are defined using a "CREATE TRIGGER" DDL statement. A trigger can
contain statements to act on a table, or it can call a stored procedure to do the
operations.
• In the ID system, there are 3 triggers defined for the SF0INM table, one for
inserts, one for updates and one for deletes. Below is the DDL for defining the
insert trigger.
Figure 3:
Of these, SFIDICFU and SFTBLEDT are tri-use, that is they can be called from
either a stored procedure or a regular CICS or batch program.
• SFINMTR is called from the triggers for the SF0INM table. Its purpose is to update
the IDB_MIN_INM_SOURCE in the SF0IDB table with the minimum value for the
source field in all SF0INM records for the ID.
o It is defined to DB2 in DDLLIB member SPINM00C.
• SFIIDSVR is a utility for updating ID system tables. It is currently called from CICS
programs and also from web applications.
o It is defined to DB2 in DDLLIB member SPIDS00C - see Figure 1 above.
o The input and output parameters are laid out in copylib member SFPRMIDS.
See Figure 4 below.
o Copylib member SFLNKIDS is used as a work area for formatting the
parameters.
o SFIIDSVR is called by UCIID100 and UCIID200 (see Figure 2 above) which
are CICS programs called from both the PPS and ID systems. These two
programs format the parameters and interpret the results for the programs
which called them.
Figure 4:
UCIID100 UCIID200
SFIIDSVR
SFIIDUID SFIIDMTC SFIIDNUM SFIIDCHK SFIDIDBU SFIDINMU SFIDIDQU SFIDIXBU SFIDISAU SFIDVRED