Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 4: CICS COBOL Programming


CICS COBOL Example

Here is a complete CICS COBOL program that you can study end to end. It is a small employee inquiry: it asks for an employee id, reads the employee file, and shows the employee name. PF3 ends the task.

What this program does

  • First call (EIBCALEN = 0): it sends a prompt asking for the employee id, then returns with a commarea.
  • Later calls: it receives the typed id, reads EMPFILE, and sends back the employee name or a not-found message.
  • If the user presses PF3, the task ends at once.
  • It uses basic mapping support (SEND TEXT / RECEIVE). Formatted screens with BMS maps come in Module 5.

The complete program

IDENTIFICATION DIVISION.
PROGRAM-ID. EMPINQ.
* Employee inquiry - ask for id, display name.
DATA DIVISION.
WORKING-STORAGE SECTION.
COPY DFHAID.
01  WS-COMMAREA.
       05  WS-FIRST-FLAG            PIC X VALUE 'Y'.
01  WS-RESP                     PIC S9(8) COMP.
01  WS-MSG                       PIC X(60).
01  WS-EMP-ID                    PIC X(6).
01  WS-EMP-REC.
       05  WS-EMP-NO                 PIC X(6).
       05  WS-EMP-NAME               PIC X(30).
       05  FILLER                   PIC X(44).
LINKAGE SECTION.
01  DFHCOMMAREA                 PIC X(1).
PROCEDURE DIVISION.
0000-MAIN.
IF EIBCALEN = ZERO
            MOVE 'ENTER EMPLOYEE ID (6 CHARS) AND PRESS ENTER:'
              TO WS-MSG
            EXEC CICS SEND TEXT
                FROM(WS-MSG)
                LENGTH(48)
                ERASE
          END-EXEC
            EXEC CICS RETURN
                TRANSID(EIBTRNID)
                COMMAREA(WS-COMMAREA)
                LENGTH(1)
          END-EXEC
END-IF.
EXEC CICS RECEIVE
            INTO(WS-EMP-ID)
            LENGTH(6)
            RESP(WS-RESP)
      END-EXEC.
IF EIBAID = DFHPF3
            MOVE 'GOODBYE.' TO WS-MSG
            EXEC CICS SEND TEXT FROM(WS-MSG) LENGTH(8)
          END-EXEC
            EXEC CICS RETURN
          END-EXEC
END-IF.
EXEC CICS READ
            FILE('EMPFILE')
            INTO(WS-EMP-REC)
            RIDFLD(WS-EMP-ID)
            RESP(WS-RESP)
      END-EXEC.
IF WS-RESP = DFHRESP(NORMAL)
            STRING 'EMPLOYEE NAME: ' WS-EMP-NAME
                DELIMITED BY SIZE INTO WS-MSG
          END-STRING
ELSE
            MOVE 'EMPLOYEE NOT FOUND. TRY AGAIN.' TO WS-MSG
END-IF.
EXEC CICS SEND TEXT
            FROM(WS-MSG)
            LENGTH(60)
            ERASE
      END-EXEC.
EXEC CICS RETURN
            TRANSID(EIBTRNID)
            COMMAREA(WS-COMMAREA)
            LENGTH(1)
      END-EXEC.

How to build and run it

  • Build it with the three-step job from the earlier pages: translator (DFHECP1$), compiler (IGYCRCTL), linkage editor (IEWL).
  • Define the program to CICS with CEDA DEFINE PROGRAM(EMPINQ), and define a transaction id (for example EMPI) pointing to it.
  • Make sure EMPFILE is defined to CICS and the load library is in the region's DFHRPL.
  • Type the transaction id at a terminal, enter an employee id, and press ENTER. Press PF3 to end.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant