Here’s Logic to Access CICS from DB2 Stored Procedure

There are 2 ways we can access CICS from DB2 stored procedure.

  1. Accessing CICS Systems Through EXCI
  2. Accessing CICS Systems Through Stored Procedure DSNACICS

Method:1 Preparing CICS and WLM for EXCI

Prior to executing a stored procedure that invokes EXCI, you must define the following resources on the resource definition screen in the CICS region where the CICS program will execute: connections, sessions, transaction, program, and any files accessed.

You can perform the resource definition (RDO) process using the CEDA transaction. We have included access to a VSAM file.

The VSAM file is defined to CICS via the RDO since we access the file from the CICS transaction. Therefore, there is no need to add a DD statement for the VSAM file to the startup JCL for the address space.

We defined all the RDO entries for our test case in group SG247083, which is a copy of the resource group DFH$EXCI supplied with CICS.

All of the RDO definitions that are used by EXCI must be defined in the same group. RDO definitions can be maintained by using the CEDA transaction in CICS.

Here are the steps we followed to define the resources to CICS. We used a CICS Transaction Server V3.1 system for out testing.

CICS Resource Definitions

Connections definition – Issue the following command to define a connection:


The required fields and the values we chose were as follows. For each field, you can use an abbreviation by specifying only those characters shown in capital letters.

The values we chose for each field are shown in bold.

  • CONnection – XCTG
  • Group – SG247083 (this is carried over from the CEDA command). Once the first resource has been defined, the group is automatically defined.
    • Description – This is optional.
    • ACcessmethod – IRC (Abbreviation: IR)
    • PRotocol – Exci (Abbreviation: E)
    • Conntype – Generic (Abbreviation: G)

Sessions definition – Issue the following command to define a session:

The required fields and the values we chose were as follows:

  • Sessions – XCTGSESS
  • Connection – XCTG, which refers to the definition of the connection.
  • Protocol – Exci (Abbreviation: E)
  • RECEIVECount – 4 (should be some non-zero number)

Program definition – You need one entry for the CICS program called by the stored procedure. Issue the following command to define program EMPEXC2C:

The required fields and the values we chose were as follows:

  • PROGram – EMPEXC2C
  • Language – COBOL (Abbreviation: CO)

Transaction definition – You need one entry for the CICS transaction ID that is associated with the CICS program to be executed.

The transaction definition refers to the CICS program DFHMIRS, which is a stub for the EXCI call.

Program DFHMIRS will then execute the CICS program you specify in the CICS LINK statement in your stored procedure. Issue the following command to define transaction DPT1:


The required fields and the values we chose were as follows:

  • TRANSaction – DPT1

You need to specify a profile with parameter INBFMH=ALL as in DFHCICSA, otherwise the transactions fail with abend code AXFQ.

VSAM file definition – Issue the following command to define VSAM file Sg247083.DEPT with a DDname of DEPTNAME:


  1. File – DEPTNAME
  2. DSNAME – SG247083.DEPT.CL, which is the VSAM cluster name
  3. Install the group SG247083: CEDA I GROUP(SG247083)
  4. ISC parameter – Verify that the SIT parameter ISC is set to YES.
  5. RRMS parameter – Verify that the SIT parameter RRMS is set to YES. CICS supports the MVS resource recovery services (RRS) in applications that use the external CICS interface.
  6. Remember that changes made to program EMPEXC2C only become active in CICS after executing the following command in CICS to pull in the latest version of program EMPEXC2C:

WLM Definitions:

We recommend that you define a separate WLM application environment for your EXCI transactions to minimize the impact that problems with CICS systems can have on your stored procedures. We chose to name the environment DB9AEXCI.

The load library that contains the EXCI stub program DFHMIRS needs to be included in the startup JCL for the WLM procedure.

The name of the load library typically ends in SDFHEXCI.

Coding a Stored Procedure to Use EXCI:

Stored procedure EMPEXC1C includes an EXEC CICS LINK statement to invoke the new transaction defined in the RDO entry as described in the section above.

                   TRANSID  ('DPT1')
                   APPLID   ('SCSCPAPB')
                   LENGTH   (WS-COMM-LEN)
                   RETCODE (EXCI-EXEC-RETURN-CODE)

When the LINK statement is executed, CICS loads program DFHMIRS, the EXCI mirror program, which in turn will load the program that is passed in the PROGRAM field of the LINK statement, which is EMPEXC2C in our case.

This program then reads the commarea that is passed, uses the DEPTNO field in the commarea, and reads file DEPTNAME to obtain the department name, which is then passed back in the commarea.

The fields WS-COMM-AREA and WS-COMM-LEN represent the commarea, and the length of the commarea that is passed from the stored procedure to the CICS program EMPEXC2C.

Method: 2: Preparing a Stored Procedure to Use EXCI

Stored procedures that use EXCI to call CICS programs must include a CICS translation step in the program preparation process.

The CICS program needs to be prepared using standard CICS preparation JCL. Refer to the link for more details in the IBM doc.

Related Posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.