Mainframe Path Start learning free
Core7 min readLesson 2 of 4

Pseudo-conversational programming

Between sending a screen and getting a reply, a CICS program does not wait — it ends. When the user presses Enter, a new task starts and picks up where the last one left off. This is the central idea in CICS application design.

Why it works this way

A conversational program would sit in storage holding its region resources while a human reads the screen. With a thousand users, that is a thousand idle tasks holding storage and locks. Ending the task instead means the region holds nothing between interactions — which is how the same hardware serves far more users.

Conversational vs pseudo-conversational
Conversational
Send screenWait for the userTask alive the whole timeResources heldDoes not scale
Pseudo-conversational
Send screenTask endsNothing heldNew task on replyScales to thousands

Carrying state across the gap: COMMAREA

The standard shape of a pseudo-conversational program
       WORKING-STORAGE SECTION.
       01  WS-COMMAREA.
           05  WS-NEXT-STEP     PIC X(01).
           05  WS-ACCT-ID       PIC X(10).
           05  WS-SAVED-DATA    PIC X(200).
       LINKAGE SECTION.
       01  DFHCOMMAREA          PIC X(211).

       PROCEDURE DIVISION.
           IF EIBCALEN = ZERO
               * first time in — no commarea passed
               PERFORM 1000-SEND-FIRST-MAP
           ELSE
               MOVE DFHCOMMAREA TO WS-COMMAREA
               EVALUATE WS-NEXT-STEP
                   WHEN '1' PERFORM 2000-HANDLE-ENQUIRY
                   WHEN '2' PERFORM 3000-HANDLE-UPDATE
                   WHEN OTHER PERFORM 9000-INVALID
               END-EVALUATE
           END-IF

           EXEC CICS RETURN
               TRANSID('PAY1')
               COMMAREA(WS-COMMAREA)
               LENGTH(LENGTH OF WS-COMMAREA)
           END-EXEC.

The EIB: what CICS tells your program

FieldContains
EIBCALENLength of the commarea passed in
EIBAIDWhich key the user pressed — Enter, PF3, PF12, Clear
EIBTRNIDThe transaction ID that started this task
EIBTRMIDThe terminal ID
EIBDATE / EIBTIMEWhen the task started
EIBRESP / EIBRESP2The outcome of the last CICS command
Handling a not-found instead of abending
           EXEC CICS READ
               FILE('ACCTFILE')
               INTO(WS-ACCT-RECORD)
               RIDFLD(WS-ACCT-ID)
               RESP(WS-RESP)
           END-EXEC

           EVALUATE WS-RESP
               WHEN DFHRESP(NORMAL)
                   PERFORM 2200-SHOW-ACCOUNT
               WHEN DFHRESP(NOTFND)
                   MOVE 'ACCOUNT NOT FOUND' TO MSGO
               WHEN OTHER
                   PERFORM 9000-CICS-ERROR
           END-EVALUATE

Example, line by line

COBOL + CICSWhat it means
IF EIBCALEN = 0
First time in: no COMMAREA was passed, so there is no saved state.
PERFORM 1000-SEND-FIRST-SCREEN
Show the empty screen.
ELSE
Not the first time: the user has typed something.
MOVE DFHCOMMAREA TO WS-STATE
Restore the state saved at the end of the previous task.
PERFORM 2000-PROCESS-INPUT
Read the screen and do the work.
END-IF
EXEC CICS RETURN TRANSID('ACCT')
End this task now, and start ACCT again when the user next presses a key…
COMMAREA(WS-STATE)
…passing the saved state to that next task.
END-EXEC

Try it yourself

TRY IT YOURSELF

Which EIB field tells the program whether a COMMAREA was passed in?

Show a hint

It holds the COMMAREA length.

Show the solution

EIBCALEN — zero means no COMMAREA, so this is the first time in.

Common mistakes

Assuming WORKING-STORAGE survives between tasks

It does not. Each task gets a fresh copy. Anything that must persist goes in the commarea or a container.

Not checking EIBCALEN

Without it, a first entry reads an uninitialised commarea and behaves unpredictably.

Omitting RESP and letting CICS abend

The user sees a raw abend code. With RESP you can show a sentence they understand.

Putting large data in a commarea

There is a size limit and it is copied on every interaction. Use a channel, or keep a key and re-read.

What you will see at work

Key terms

Check your understanding.
Take this lesson's quiz and save your progress. Free.

Take the lesson quiz
← What CICS is and how work arrivesThe commands and abends you will meet →