CICS COBOL Program Example


In this chapter, we will discuss about creating COBOL + CICS + DB2 (SENDTEXTP) with a transaction (MPK7). Creating sample COBOL CICS program has the below steps –

  1. Writing the CICS + COBOL Program
  2. Compile the COBOL + CICS program
  3. Define the transaction entry (PCT) in CICS
  4. Define the program entry (PPT) in CICS
  5. Issue new copy in CICS Region
  6. Run program in CICS region

1. Code COBOL + CICS program -

A CICS program is written in COBOL with CICS commands. These commands must be enclosed within:

EXEC CICS ... END-EXEC.

Scenario - Display welcome message at the middle of the screen.

----+----1----+----2----+----3----+----4----+----5----+----6----+-
       IDENTIFICATION DIVISION.
       PROGRAM-ID.  SENDTXTP.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 WS-DATA.
         05 FILLER           PIC X(900) VALUE SPACE.
         05 WS-MESSAGE       PIC X(40) VALUE
                     'Welcome to Mainframestechhelp'.
       01 WS-LENGTH        PIC 9(4) COMP.

       PROCEDURE DIVISION.
           MOVE 940 TO WS-LENGTH.
           EXEC CICS SEND TEXT
              FROM(WS-DATA)
              LENGTH(WS-LENGTH)
              ERASE 
           END-EXEC.
		   
           EXEC CICS   
              RETURN   
           END-EXEC.   
           GOBACK.

2. Compile the COBOL + CICS program -

Since the program contains CICS commands, it must be compiled with the CICS translator before the COBOL compiler processes it. Go through the topic - COBOL + CICS Program Compilation Process .

3. Define the transaction entry (PCT) in CICS -

After compilation, the transaction must be defined in CICS. Go through the topic - Define Transaction in CICS Region .

4. Define the program entry (PPT) in CICS -

After compilation, the program must be defined in CICS. Go through the topic - Define Application Program in CICS Region .

5. Issue new copy in CICS Region -

After entries are defined, issue a new copy to the module to pickup the load module and set it ready for the execution using the below command -

CEMT SET PROG(prog-name) NEWC
CEMT Command CEMT Command

6. Run program in CICS region -

Once the new copy is successful, enter the transaction and hit "enter" to execute the program as shown below -

RUN Program1 RUN Program2