CICSintermediate
COMMAREA for Inter-Program Communication
Understand how COMMAREA passes data between CICS programs and preserves state across pseudo-conversational transaction turns.
A CICS task's working storage does not survive the task. So a multi-screen transaction needs somewhere to keep what the user already entered.
COMMAREA is a claim ticket you hand back to a coat check between visits — the attendant (CICS) holds onto your coat (the data) between your comings and goings, and hands it right back to you the next time you show up with the matching ticket, even though you left the building in between.
Key Concepts
1
COMMAREA is the classic answer, and it does two jobs.
2
Job one: passing data between programs.
EXEC CICS LINK PROGRAM('PGMB')
COMMAREA(WS-PARM-AREA)
LENGTH(200)
END-EXEC.3
PGMB picks it up through a special register in its LINKAGE SECTION:
4
LINKAGE SECTION.
01 DFHCOMMAREA.
05 LS-CUSTOMER-ID PIC X(9).
05 LS-ACTION PIC X.5
LINK returns to the caller afterwards. XCTL transfers control and does not come back — the difference
being whether you want the caller's storage kept alive.
LINKXCTL
6
Job two, and the important one: state across screens. A pseudo-conversational transaction ends its task
between screens. The next keystroke starts a fresh task with fresh storage.
7
EXEC CICS RETURN
TRANSID('INQC')
COMMAREA(WS-STATE)
LENGTH(100)
END-EXEC.8
CICS holds that data while the user reads the screen. When they press enter, the new task starts and finds
it in DFHCOMMAREA.
DFHCOMMAREA
9
So the flow is: build the screen, save what you need, end the task, and pick the state up again when the
user responds. The region is not holding anything open in between.
10
Check the length before trusting it.
IF EIBCALEN = 0
PERFORM FIRST-TIME-INITIALISE
ELSE
PERFORM CONTINUE-FROM-COMMAREA
END-IF.11
EIBCALEN is zero on the very first invocation, when nobody has passed anything. Reading DFHCOMMAREA
then addresses storage you were not given, and the failure is unpredictable rather than clean. This check
is the first thing in almost every CICS program.
EIBCALENDFHCOMMAREA
12
The comparison with channels and containers. A COMMAREA is one contiguous block with a layout every
program in the chain must agree on, historically capped at 32K.
13
Adding a field means recompiling every program that shares the copybook, and any program that was missed
reads the new layout at the old offsets. Channels and containers exist to avoid exactly that, which is the
next topic.
14
What the interviewer is probing.1. "What is a COMMAREA?" Probing: the mechanism. Stalls: "A variable." Moves up: a block
of storage passed between programs or across pseudo-conversational turns, which is how state
survives when the task does not.
15
2. "What is the size limit worth knowing?" Probing: the practical constraint. Stalls:
"None." Moves up: roughly 32KB, which is exactly why channels and containers exist.
16
3. "How do you tell the first invocation from a later one?" Probing: the idiom. Stalls: "A
flag in the file." Moves up: EIBCALEN is zero on the first entry, because no COMMAREA was passed
yet.
17
4. "What is the danger of a COMMAREA layout change?" Probing: the hazard. Stalls: "None."
Moves up: both sides must be recompiled together — a mismatch reads fields at the wrong offsets
and produces plausible-looking garbage.