Chapter 25: Advanced CICS Programming -- Key Takeaways
Chapter Summary
Advanced CICS programming extends the foundational transaction processing skills from Chapter 24 into the full range of CICS services that production applications require. This chapter covered CICS file control for accessing VSAM files under CICS management, temporary storage (TS) and transient data (TD) queues for inter-task communication and data staging, program control commands for building multi-program transaction architectures, interval control for scheduled and deferred processing, channel and container programming as the modern successor to COMMAREA, CICS web services for integrating mainframe transactions with distributed systems, and CICS security for controlling access to transactions and resources.
CICS file control provides COBOL programs with access to VSAM KSDS, ESDS, and RRDS files through EXEC CICS commands such as READ, WRITE, REWRITE, DELETE, and BROWSE (STARTBR, READNEXT, READPREV, ENDBR). Unlike batch COBOL file I/O, CICS file control operates within the transaction processing environment, providing record-level locking, automatic recovery, and concurrent access by multiple tasks. We examined how CICS manages file resources through the File Control Table (FCT) and how the program interacts with files through EXEC CICS commands without ever issuing OPEN or CLOSE.
Queue management through temporary storage (TS) and transient data (TD) queues provides essential infrastructure for inter-task communication, scratch-pad storage, and asynchronous processing. Program control commands LINK, XCTL, and RETURN enable complex transactions to be decomposed into multiple cooperating programs, each focused on a specific function. Interval control commands START, RETRIEVE, and DELAY provide scheduled execution and timer-based processing. The chapter then covered channel and container programming, which replaces the size-limited COMMAREA with a named, structured data-passing mechanism that supports large data volumes and multiple data items. Finally, we addressed CICS web services for exposing CICS transactions as web service endpoints and CICS security through resource-level and command-level checking.
Key Concepts
- CICS file control commands (READ, WRITE, REWRITE, DELETE, STARTBR, READNEXT, READPREV, ENDBR) provide VSAM file access within the CICS transaction environment without COBOL OPEN or CLOSE statements.
- READ with UPDATE locks the record for exclusive access until a REWRITE, DELETE, or UNLOCK releases it, preventing concurrent modification by other tasks.
- Browse operations use STARTBR to position the browse cursor, READNEXT or READPREV to retrieve successive records, and ENDBR to end the browse session.
- Temporary storage (TS) queues store data that persists across task invocations and can be read by any task that knows the queue name; they are commonly used for multi-page screen data and scratch-pad storage.
- WRITEQ TS writes an item to a temporary storage queue, READQ TS reads an item by item number, and DELETEQ TS deletes the entire queue.
- Transient data (TD) queues provide one-time-read data streams; intrapartition TD queues can trigger automatic task initiation when a threshold item count is reached, and extrapartition TD queues interface with external data sets.
- LINK invokes another CICS program at a lower logical level, passing a COMMAREA or channel, and returns control to the linking program when the linked program completes.
- XCTL transfers control to another CICS program at the same logical level; the transferring program is released from storage and cannot be returned to.
- RETURN terminates the current program; with TRANSID it establishes the next transaction to be invoked when the user presses a key; without TRANSID it returns to the linking program or ends the transaction.
- START initiates a new transaction asynchronously, optionally at a specified time or after a specified interval, with optional data passed via a FROM clause or channel.
- RETRIEVE in the started transaction receives the data passed by the START command, enabling asynchronous inter-transaction data communication.
- Channels are named containers that replace COMMAREA for passing data between programs; they support multiple named containers, each holding data of any size, removing the 32KB COMMAREA limit.
- PUT CONTAINER and GET CONTAINER commands store and retrieve data in named containers within a channel, and the channel is passed on LINK, XCTL, or RETURN commands.
- CICS web services allow CICS transactions to be exposed as SOAP or RESTful service providers, with the CICS web services assistant generating the necessary pipeline configurations and data mappings.
- CICS security uses resource-level security (checking access to files, programs, transactions, and queues) and command-level security (checking authorization to issue specific EXEC CICS commands), integrated with the z/OS security manager (RACF, ACF2, or Top Secret).
Common Pitfalls
- Holding record locks across user interactions: Reading a record with UPDATE and then sending a screen to the user holds the lock for the entire think time. Other tasks attempting to access the same record will wait or receive a BUSY condition. Release locks before sending screens.
- TS queue name collisions: If multiple users run the same transaction and write to a TS queue with a hardcoded name, they overwrite each other's data. Include the terminal ID or a unique identifier in the queue name to avoid collisions.
- Not deleting TS queues when finished: Temporary storage queues persist until explicitly deleted. Abandoned queues accumulate and waste auxiliary temporary storage, eventually degrading system performance.
- XCTL when LINK is needed: Using XCTL when the calling program needs to resume after the called program completes results in loss of control. Use LINK when you need to return; use XCTL only for permanent transfer.
- Exceeding the 32KB COMMAREA limit: The traditional COMMAREA is limited to approximately 32KB. Attempting to pass larger data structures causes unpredictable results. Migrate to channels and containers for large data volumes.
- START without proper RETRIEVE: A transaction initiated by START must issue RETRIEVE to obtain the passed data. If the data format or length does not match between START FROM and RETRIEVE INTO, data corruption occurs.
- Ignoring file control RESP codes: CICS file operations can return conditions such as NOTFND, DUPREC, NOSPACE, and DISABLED. Failing to check and handle these responses leads to abends and data integrity problems.
- Web service data transformation errors: When exposing CICS programs as web services, mismatches between the COBOL data structure and the WSDL/schema definition cause runtime transformation failures. Always validate the generated service definitions against the COBOL program's data layout.
Quick Reference
* File control - READ with UPDATE
EXEC CICS READ
FILE('CUSTFILE')
INTO(WS-CUST-REC)
RIDFLD(WS-CUST-KEY)
UPDATE
RESP(WS-RESP)
END-EXEC
* File control - REWRITE after UPDATE
EXEC CICS REWRITE
FILE('CUSTFILE')
FROM(WS-CUST-REC)
RESP(WS-RESP)
END-EXEC
* File control - Browse
EXEC CICS STARTBR
FILE('CUSTFILE')
RIDFLD(WS-START-KEY)
RESP(WS-RESP)
END-EXEC
PERFORM UNTIL WS-RESP NOT =
DFHRESP(NORMAL)
EXEC CICS READNEXT
FILE('CUSTFILE')
INTO(WS-CUST-REC)
RIDFLD(WS-CUST-KEY)
RESP(WS-RESP)
END-EXEC
END-PERFORM
EXEC CICS ENDBR
FILE('CUSTFILE')
END-EXEC
* Temporary storage queue
EXEC CICS WRITEQ TS
QUEUE(WS-TS-QNAME)
FROM(WS-DATA)
LENGTH(LENGTH OF WS-DATA)
END-EXEC
EXEC CICS READQ TS
QUEUE(WS-TS-QNAME)
INTO(WS-DATA)
ITEM(1)
END-EXEC
EXEC CICS DELETEQ TS
QUEUE(WS-TS-QNAME)
END-EXEC
* Program control - LINK with COMMAREA
EXEC CICS LINK
PROGRAM('CUSTVAL')
COMMAREA(WS-COMMAREA)
LENGTH(LENGTH OF WS-COMMAREA)
END-EXEC
* Program control - XCTL
EXEC CICS XCTL
PROGRAM('CUSTMNU')
COMMAREA(WS-COMMAREA)
LENGTH(LENGTH OF WS-COMMAREA)
END-EXEC
* Channel and container
EXEC CICS PUT CONTAINER('CUSTDATA')
CHANNEL('CUST-CHAN')
FROM(WS-CUST-REC)
END-EXEC
EXEC CICS LINK
PROGRAM('CUSTPROC')
CHANNEL('CUST-CHAN')
END-EXEC
EXEC CICS GET CONTAINER('RESULT')
CHANNEL('CUST-CHAN')
INTO(WS-RESULT)
END-EXEC
* Interval control - START
EXEC CICS START
TRANSID('RPTX')
FROM(WS-RPT-PARMS)
LENGTH(LENGTH OF WS-RPT-PARMS)
AFTER HOURS(1)
END-EXEC
What's Next
Having completed the two major pillars of enterprise COBOL programming -- DB2 for relational data access and CICS for online transaction processing -- Part 5 continues with Chapter 26 on IMS (Information Management System), which covers hierarchical database access and IMS transaction management. Together, DB2, CICS, and IMS represent the three subsystems that COBOL programmers most commonly encounter in mainframe enterprise environments, and proficiency with all three opens the widest range of career opportunities in mainframe development.