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.
Carrying state across the gap: COMMAREA
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.- EIBCALEN is the length of the commarea passed in. Zero means this is the first time — the standard test for 'is this a fresh start?'.
- RETURN TRANSID(…) COMMAREA(…) ends the task, tells CICS which transaction to run next time this terminal sends data, and hands forward the state.
- DFHCOMMAREA in the LINKAGE SECTION is how the incoming state arrives.
- Modern alternatives — a channel and containers — carry more than the traditional 32KB commarea limit and are typed. New work should prefer them where the site allows.
The EIB: what CICS tells your program
| Field | Contains |
|---|---|
| EIBCALEN | Length of the commarea passed in |
| EIBAID | Which key the user pressed — Enter, PF3, PF12, Clear |
| EIBTRNID | The transaction ID that started this task |
| EIBTRMID | The terminal ID |
| EIBDATE / EIBTIME | When the task started |
| EIBRESP / EIBRESP2 | The outcome of the last CICS command |
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
IF EIBCALEN = 0 PERFORM 1000-SEND-FIRST-SCREENELSE MOVE DFHCOMMAREA TO WS-STATE PERFORM 2000-PROCESS-INPUTEND-IFEXEC CICS RETURN TRANSID('ACCT') COMMAREA(WS-STATE)END-EXECTry 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
It does not. Each task gets a fresh copy. Anything that must persist goes in the commarea or a container.
Without it, a first entry reads an uninitialised commarea and behaves unpredictably.
The user sees a raw abend code. With RESP you can show a sentence they understand.
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
- Most screens in an application follow one template, and you will copy it. Understanding the template is more valuable than memorising commands.
- Sites increasingly front CICS with web services and APIs; the same programs run underneath, called differently.
- The commarea often carries an application-wide standard header. Find yours before writing a new program.
Key terms
Check your understanding.
Take this lesson's quiz and save your progress. Free.