Pseudo-Conversational Programming in CICS Explained
Learn why CICS programs end after each screen, how EXEC CICS RETURN TRANSID with a COMMAREA keeps state between turns, and the conversational mode it replaces.

A person typing into a screen is the slowest component in the system. A clerk who reads an order, looks at a customer's file and types a quantity may take thirty seconds between pressing Enter and the next key. If the program waited that whole time holding its storage and its locks, a region with a thousand users would run out of resources quickly. Pseudo-conversational programming solves this by letting the program end after each screen and start again when the user replies. This post explains the pattern for CICS Transaction Server for z/OS 6.1 on z/OS 3.1 and shows it in COBOL.
The conversational model and why it fails
A conversational program sends a screen with a SEND MAP command and then issues a RECEIVE MAP that waits for the user. The task stays alive, holding its working storage and any file or record locks, until the user answers. For one user that is fine. For many it is costly: each idle task occupies memory and a slot in the region's task limit, and a lock held on a record stops everyone else from updating it while the clerk goes for coffee.
Conversational programs are simple to write, since the program runs from top to bottom and local variables remember everything. That simplicity is why they still appear in small systems and in teaching examples. In production they are generally forbidden.
The pseudo-conversational model
A pseudo-conversational program looks conversational to the user and is not. The program sends a screen and ends, naming the transaction that should start when the user presses Enter. While the user thinks, no task exists at all. When the key is pressed, CICS starts a new task running the named transaction, and that task reads the input and carries on.
EXEC CICS RETURN
TRANSID('ORD1')
COMMAREA(WS-COMMAREA)
LENGTH(LENGTH OF WS-COMMAREA)
END-EXEC.RETURN with TRANSID is the heart of the pattern. It ends the current task, and it tells CICS to attach the transaction ORD1 to this terminal for the next input. COMMAREA hands a block of data from this task to the next one. A plain RETURN with no TRANSID ends the conversation, and the terminal goes back to waiting for a fresh transaction ID.
State without a task
Since no program stays in storage, everything you want to remember between turns must travel in the communication area or sit in some store. The commonest choice is the COMMAREA, which the next task receives in its linkage section, and a later post in this cluster covers it in detail. The program decides what turn it is by testing whether it received any commarea.
LINKAGE SECTION.
01 DFHCOMMAREA.
05 CA-STATE PIC X.
05 CA-ORDER-ID PIC X(6).
PROCEDURE DIVISION.
IF EIBCALEN = 0
PERFORM FIRST-TIME
ELSE
MOVE DFHCOMMAREA TO WS-COMMAREA
PERFORM PROCESS-INPUT
END-IF.EIBCALEN is a field in the execute interface block, the EIB, that CICS fills before the program starts. It holds the length of the commarea passed in. A value of zero means no commarea, so this is the first time the transaction has run for this user, and the program sends the initial screen. A non-zero value means the user has replied, and the program processes the input.
A complete small example
Here is a program that asks for an order number and then shows a message in a second turn. It uses SEND TEXT and RECEIVE to avoid map definitions, which a later post covers.
IDENTIFICATION DIVISION.
PROGRAM-ID. ORDPROG1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-COMMAREA PIC X(1) VALUE 'S'.
01 WS-INPUT PIC X(20).
01 WS-INPUT-LEN PIC S9(4) COMP VALUE 20.
01 WS-MSG PIC X(40).
LINKAGE SECTION.
01 DFHCOMMAREA PIC X(1).
PROCEDURE DIVISION.
IF EIBCALEN = 0
MOVE 'ENTER ORDER NUMBER AND PRESS ENTER' TO WS-MSG
EXEC CICS SEND TEXT FROM(WS-MSG) LENGTH(35) ERASE
END-EXEC
EXEC CICS RETURN TRANSID('ORD1')
COMMAREA(WS-COMMAREA) LENGTH(1)
END-EXEC
ELSE
EXEC CICS RECEIVE INTO(WS-INPUT)
LENGTH(WS-INPUT-LEN)
END-EXEC
MOVE 'ORDER RECEIVED' TO WS-MSG
EXEC CICS SEND TEXT FROM(WS-MSG) LENGTH(14) ERASE
END-EXEC
EXEC CICS RETURN END-EXEC
END-IF.First pass: EIBCALEN is 0, the program sends the prompt and returns with TRANSID('ORD1') and a one-byte commarea. The user types an order number. Second pass: EIBCALEN is 1, the program receives the input, sends the confirmation and returns without a TRANSID, ending the conversation. The terminal shows the following.
ORDER RECEIVEDIn a real program the second pass would validate the number and read a file. The skeleton does not change.
The cost: you must design for restart
Every turn begins from nothing. That has three consequences you should plan for.
First, the program must be tolerant of unexpected input. A user may press a function key you did not expect, or clear the screen and type a different transaction ID. Each turn must check what arrived, not assume.
Second, state must be small and must be rebuilt, not trusted. If a record read in the first turn changes before the second, the second turn should reread and check a version or timestamp before updating, since another task could have changed it in the interval. This pattern, optimistic concurrency, replaces the locks that a conversational program would have held.
Third, the commarea limit applies: a commarea may be up to 32,500 bytes, and larger state belongs in a temporary storage queue or a channel with containers. Keep the commarea to what the next turn truly needs.
When conversational is still fine
A short, rarely used administrative transaction used by two operators does not need the pattern, and a program that holds a terminal for a few seconds does little harm. Programs started by other programs, with no terminal, are not conversational either. The pseudo-conversational rule exists for terminal-driven transactions with many concurrent users and long think times, and that describes most production CICS work.
Designing the turns as a state machine
The cleanest way to structure a pseudo-conversational program is as a small state machine. The commarea carries a state code, and the program has one paragraph per state. State S means the first screen was sent and the program awaits an order number. State C means the order was displayed and the program awaits a confirm or cancel key. State D means the work is done. On each entry the program reads the state, runs only the matching paragraph, sets the next state and returns with TRANSID. This keeps the logic flat and makes it easy to test each state with a prepared commarea, because you do not have to walk through earlier screens to reach a later one.
Three details prevent grief. Always validate the state code, so a corrupted or stale commarea sends the user back to the first screen instead of running the wrong paragraph. Treat the attention identifier in EIBAID as input: a PF3 key should end the transaction cleanly from any state, and CLEAR should do the same. And never trust the data the user sends back to match what you sent, since a terminal can be reset or a different session can reuse the same terminal.
Locks and the long think time
Because the task ends between turns, any record lock taken in the first turn is released at the end of that turn. The second turn cannot assume that the record is unchanged. The common pattern is to save a version marker, such as a last-update timestamp, in the commarea at read time and compare it with the record's current value at update time. If they differ, show the user the new data and ask again. This is optimistic concurrency, and the price is a rare retry, which is far cheaper than holding a lock through a coffee break.
Resource usage shows the benefit. A conversational design with 500 users in the middle of a screen needs 500 tasks and the storage behind them. The pseudo-conversational design needs a task only for the milliseconds each user's program runs, so the same region serves the same users with a handful of tasks at any instant. We do not quote a ratio because it depends on think time and transaction rate, but the mechanism is plain.


