Skip to content
Tutorials Center
My learning

Topics

Lesson 14 of 38 ยท Modern COBOL and Mainframes

CICS and Online Transactions

A COBOL programmer's introduction to CICS - transactions and tasks, EXEC CICS commands, BMS maps, SEND and RECEIVE MAP, pseudo-conversational design with COMMAREA, file access, RESP codes and LINK or XCTL.

Batch jobs answer questions overnight. But when a bank teller checks a balance or a booking agent reserves a seat, the answer must appear in under a second, while thousands of other users do the same thing. On IBM mainframes this online work is handled by CICS (Customer Information Control System), a transaction server that runs COBOL programs on demand. Its fixed vocabulary: a user types a four-character transaction ID such as ACCT, CICS starts a task that runs the program attached to that ID, the program reads and writes data, sends a screen back and ends.

You do not need a mainframe to understand the concepts, and they carry over to modern web back ends: a request arrives, a short program handles it, state is kept elsewhere.

Programs that call CICS

A CICS COBOL program is ordinary COBOL with EXEC CICS ... END-EXEC commands where you would use file I/O or ACCEPT/DISPLAY. There is no OPEN, no STOP RUN: CICS owns the files and the terminal, and the program ends with EXEC CICS RETURN. A translator turns each command into a call to CICS before compilation, much like the Db2 precompiler (embedded SQL).

COBOL
       WORKING-STORAGE SECTION.
       01  WS-RESP       PIC S9(8) COMP.
       01  WS-ACCT-KEY   PIC X(8).
           COPY ACCTREC.
       LINKAGE SECTION.
       01  DFHCOMMAREA   PIC X(20).
       PROCEDURE DIVISION.
           EXEC CICS READ FILE('ACCTFILE')
                     INTO(ACCT-RECORD)
                     RIDFLD(WS-ACCT-KEY)
                     RESP(WS-RESP)
           END-EXEC
           EVALUATE WS-RESP
               WHEN DFHRESP(NORMAL)    PERFORM SHOW-ACCOUNT
               WHEN DFHRESP(NOTFND)    PERFORM NO-SUCH-ACCOUNT
               WHEN OTHER              PERFORM CICS-ERROR
           END-EVALUATE
           EXEC CICS RETURN END-EXEC.

Two details to notice:

  • RESP(field) captures the outcome of the command in a numeric field, and DFHRESP(NORMAL), DFHRESP(NOTFND) and others give readable names for its values. Always use RESP; the old HANDLE CONDITION and GO TO style is hard to follow. Without either one, an error ends the task with an abend such as AEIM (not found).
  • DFHCOMMAREA in the Linkage Section receives data from the previous invocation.

The CICS translator also inserts the EIB (Execute Interface Block) with fields like EIBCALEN (length of the COMMAREA passed in), EIBAID (which key the user pressed: Enter, PF3, ...), EIBTRMID (terminal id) and EIBDATE/EIBTIME.

Screens: BMS maps

Terminal screens are described with BMS (Basic Mapping Support) macros assembled into a mapset. A map defines fields with positions, lengths and attributes (protected, unprotected, bright, numeric only). The assembler also creates a COBOL copybook for the map's data: for a field ACCTNO you get ACCTNOL (length), ACCTNOF (flag), ACCTNOA (attribute) and ACCTNOI/ACCTNOO (input/output data).

You then talk to the screen with two commands:

COBOL
           EXEC CICS SEND MAP('ACCTMAP') MAPSET('ACCTSET')
                     FROM(ACCTMAPO) ERASE
           END-EXEC
           ...
           EXEC CICS RECEIVE MAP('ACCTMAP') MAPSET('ACCTSET')
                     INTO(ACCTMAPI)
           END-EXEC

SEND MAP shows the screen with the data you moved into the output area; RECEIVE MAP reads what the user typed. Terminals send data only when the user presses a key such as Enter or PF3. Web-based systems usually replace BMS maps with JSON services, but the "request, work, reply" pattern is the same.

Pseudo-conversational design

A conversational program would keep its task alive while waiting for the user to type, tying up memory for seconds or minutes of think time. CICS shops avoid that. In a pseudo-conversational design, the program sends the screen and ends the task, passing a small COMMAREA to itself for the next step:

COBOL
           EXEC CICS RETURN TRANSID('ACCT')
                     COMMAREA(WS-STATE)
                     LENGTH(LENGTH OF WS-STATE)
           END-EXEC

When the user presses Enter, CICS starts a new task of transaction ACCT, with the saved state in DFHCOMMAREA. The program uses EIBCALEN to tell which step it is on:

COBOL
           IF EIBCALEN = 0
               PERFORM SEND-FIRST-SCREEN
           ELSE
               MOVE DFHCOMMAREA TO WS-STATE
               PERFORM PROCESS-INPUT
           END-IF

EIBCALEN = 0 means a fresh start, with nothing passed. The program holds no memory between requests; everything it needs travels in the COMMAREA, a temporary-storage queue or a file.

sequenceDiagram
    participant U as User at terminal
    participant C as CICS
    participant P as Program ACCT
    U->>C: types ACCT, Enter
    C->>P: new task (EIBCALEN = 0)
    P->>U: SEND MAP, RETURN TRANSID COMMAREA
    Note over P: task ends, no memory held
    U->>C: fills account number, Enter
    C->>P: new task (COMMAREA restored)
    P->>U: SEND MAP with result, RETURN

Between the two screens no task exists; only the COMMAREA carries the state.

Files, queues and other commands

Command Purpose
READ FILE, WRITE, REWRITE, DELETE Keyed access to VSAM files defined to CICS (indexed files); READ ... UPDATE locks the record for a REWRITE
STARTBR, READNEXT, ENDBR Browse a file sequentially
WRITEQ TS, READQ TS Temporary storage queue: scratch data between tasks
LINK PROGRAM('X') COMMAREA(...) Call another program and come back; like CALL (CALL)
XCTL PROGRAM('X') Transfer control, no return
START TRANSID Start another task, possibly later
SYNCPOINT / SYNCPOINT ROLLBACK Commit or undo the unit of work, covering files and Db2
ABEND ABCODE('XXXX') End the task abnormally
ASKTIME, FORMATTIME Get and format the date and time

Since each task is short and many run at once, a record read for update is locked until the task ends or syncpoints, so keep the interval between READ UPDATE and REWRITE short and never wait for the user in between.

Rules to live by

  • No STOP RUN, GOBACK or COBOL file I/O; use EXEC CICS RETURN and CICS file commands.
  • The program must be re-entrant: do not change Working-Storage that is shared between tasks. CICS gives each task its own copy of Working-Storage in COBOL, so the rule mostly means "don't use EXTERNAL/static tricks".
  • Test RESP after every command and map unexpected codes to a clear error screen.
  • Keep programs small. Slow tasks delay other users.

A small model of the idea

The Python stand-ins below model what CICS does: start a short task per request, restore the state from the COMMAREA, and keep the server memory free in between. They are labelled stand-ins; nothing here uses CICS.

Python Stand-in: pseudo-conversational account lookup with a COMMAREA

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: why a conversational task wastes memory

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The first block prints a prompt, the account details and then the not-found message; the second prints 30000, 80.0 and a ratio of 375, which is why mainframe sites insist on pseudo-conversational code.

Common mistakes

  1. Using STOP RUN or file READ inside a CICS program.
  2. No RESP, so a missing record abends the task.
  3. Putting too much in the COMMAREA (limit is 32,500 bytes in the classic interface; use channels and containers or a queue for more).
  4. Holding READ UPDATE locks across a screen interaction.
  5. Forgetting EIBCALEN = 0: the first run then reads garbage from DFHCOMMAREA.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does a pseudo-conversational program do after sending a screen?

    The task ends so no resources are held while the user thinks; the next input starts a new task.
  2. 2. What does EIBCALEN = 0 tell the program?

    A zero length COMMAREA means a fresh start of the transaction.
  3. 3. Which clause captures the result of an EXEC CICS command?

    RESP(field) stores the response code; compare it with DFHRESP(...) names.
  4. 4. Which command transfers control to another program and does not come back?

    XCTL passes control without returning; LINK is a call-and-return.

Summary

  • CICS runs short transactions on demand; a COBOL program uses EXEC CICS commands instead of file I/O and STOP RUN.
  • BMS maps describe screens; SEND MAP and RECEIVE MAP exchange data with the terminal.
  • Pseudo-conversational design ends the task between screens and carries state in a COMMAREA.
  • Always code RESP, keep locks short, and use LINK/XCTL for program-to-program flow.

Next: JSON, XML and object-oriented COBOL