Transaction management is at the core of CICS operations. A CICS transaction processes a request using a task to run one or more programs. Understanding how CICS manages transactions—from initiation through execution to completion—is essential for building robust, reliable CICS applications. This guide covers the transaction lifecycle, ACID properties, task management, and transaction control mechanisms.
A CICS transaction is a unit of work identified by a four-character transaction ID (TRANSID). Each transaction request triggers the execution of one or more application programs to process the request. Transactions can be initiated from various sources:
The transaction ID matches a transaction resource definition that specifies:
A CICS transaction follows a well-defined lifecycle from initiation to completion:
A transaction begins when CICS receives a request:
CICS creates a task (similar to a thread) to execute the transaction:
The transaction executes one or more programs:
A transaction completes in one of two ways:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475IDENTIFICATION DIVISION. PROGRAM-ID. TRANSMGT01. AUTHOR. Mainframe Master. DATE-WRITTEN. 2024. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-CUSTOMER-NUMBER PIC X(10). 01 WS-CUSTOMER-NAME PIC X(50). 01 WS-BALANCE PIC S9(9)V99 COMP-3. 01 WS-RESPONSE PIC S9(8) COMP. 01 WS-END-OF-TRANSACTION PIC X(1) VALUE 'N'. PROCEDURE DIVISION. MAIN-PROCESSING. * Transaction starts here when user enters transaction ID * Step 1: Get input from terminal EXEC CICS RECEIVE INTO(WS-CUSTOMER-NUMBER) LENGTH(10) RESP(WS-RESPONSE) END-EXEC. IF WS-RESPONSE NOT EQUAL DFHRESP(NORMAL) PERFORM ERROR-HANDLER EXEC CICS RETURN END-EXEC END-IF. * Step 2: Read customer record EXEC CICS READ FILE('CUSTFILE') INTO(WS-CUSTOMER-NAME) RIDFLD(WS-CUSTOMER-NUMBER) RESP(WS-RESPONSE) END-EXEC. IF WS-RESPONSE NOT EQUAL DFHRESP(NORMAL) PERFORM ERROR-HANDLER EXEC CICS RETURN END-EXEC END-IF. * Step 3: Process business logic PERFORM PROCESS-CUSTOMER. * Step 4: Update customer record EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-CUSTOMER-NAME) RIDFLD(WS-CUSTOMER-NUMBER) RESP(WS-RESPONSE) END-EXEC. IF WS-RESPONSE NOT EQUAL DFHRESP(NORMAL) PERFORM ERROR-HANDLER EXEC CICS RETURN END-EXEC END-IF. * Step 5: Transaction completes successfully * CICS automatically commits (syncpoint) when program returns EXEC CICS RETURN END-EXEC. PROCESS-CUSTOMER. * Business logic processing * This is part of the transaction unit of work CONTINUE. ERROR-HANDLER. * Error occurred - transaction will be rolled back EXEC CICS WRITE OPERATOR TEXT('Transaction error occurred') END-EXEC. * When program returns, CICS will rollback all changes
CICS transactions provide ACID (Atomicity, Consistency, Isolation, Durability) properties, ensuring data integrity and reliability:
Either all changes in a transaction occur, or none occur:
Example: In a money transfer, if debiting one account succeeds but crediting the other fails, the debit is rolled back.
A transaction moves data between consistent states:
Example: During a transfer, the total money in both accounts remains constant, even though temporarily one account is debited before the other is credited.
Concurrent transactions execute as if they run serially:
Example: Two transactions updating the same account are isolated—one completes before the other sees the changes.
Committed changes survive system failures:
Example: After a successful transfer, the new balances persist even if the system crashes immediately after.
Each transaction request creates a task—CICS's unit of execution:
CICS can run multiple tasks simultaneously:
123456789101112131415161718WORKING-STORAGE SECTION. 01 WS-TASK-INFO. 05 WS-TASK-ID PIC X(4). 05 WS-TRANSACTION-ID PIC X(4). 05 WS-USER-ID PIC X(8). 05 WS-TERMINAL-ID PIC X(4). PROCEDURE DIVISION. * Get task information EXEC CICS ASSIGN TASKID(WS-TASK-ID) TRANSID(WS-TRANSACTION-ID) USERID(WS-USER-ID) TERMID(WS-TERMINAL-ID) END-EXEC. * Use task information for logging or security * Each task has unique identifiers
CICS provides several mechanisms to control transaction execution:
Transactions can be assigned different priorities:
Transactions can be routed to different CICS regions:
Transactions can have timeout limits:
Transactions complete through several mechanisms:
Transaction completes when the program issues RETURN:
123456789PROCEDURE DIVISION. * Process transaction PERFORM PROCESS-DATA. * Transaction completes successfully * CICS automatically commits (syncpoint) before return EXEC CICS RETURN END-EXEC. * Program never reaches here - control returns to CICS
Transaction can commit changes explicitly:
123456789101112131415PROCEDURE DIVISION. * Make changes EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-RECORD) RIDFLD(WS-KEY) END-EXEC. * Commit changes explicitly EXEC CICS SYNCPOINT RESP(WS-RESPONSE) END-EXEC. * Changes are now committed * Can continue processing or return
Transaction can explicitly rollback changes:
123456789101112131415161718PROCEDURE DIVISION. * Make changes EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-RECORD) RIDFLD(WS-KEY) END-EXEC. * Check if rollback needed IF WS-ERROR-CONDITION * Rollback all changes EXEC CICS SYNCPOINT ROLLBACK RESP(WS-RESPONSE) END-EXEC EXEC CICS RETURN END-EXEC END-IF. * Continue processing if no error
Transaction abends on errors:
A single transaction can contain multiple units of work:
123456789101112131415161718192021222324252627PROCEDURE DIVISION. * First unit of work EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-RECORD1) RIDFLD(WS-KEY1) END-EXEC. * Commit first unit of work EXEC CICS SYNCPOINT RESP(WS-RESPONSE) END-EXEC. * Second unit of work EXEC CICS REWRITE FILE('CUSTFILE') FROM(WS-RECORD2) RIDFLD(WS-KEY2) END-EXEC. * Commit second unit of work EXEC CICS SYNCPOINT RESP(WS-RESPONSE) END-EXEC. * Transaction can continue or return * Each syncpoint commits one unit of work
Imagine you're playing with building blocks and want to build a tower:
When you start building (that's like starting a transaction), you gather all the blocks you need (that's like getting resources). You start stacking blocks one by one (that's like making changes to data).
If you successfully build the tower, you say "Done!" and the tower stays built (that's like committing - all your changes are saved). But if you accidentally knock it over while building, you say "Oops!" and start over (that's like rolling back - all your changes are undone).
The important thing is: either the whole tower gets built, or it doesn't - you can't have a half-built tower (that's atomicity). And if your friend is also building a tower at the same time, you each work on your own tower without interfering (that's isolation).
Transaction Management in CICS is like managing how you build your tower - making sure everything either works completely or gets undone completely, and making sure everyone can build their towers at the same time without problems!
Write a COBOL program that:
Hint: Use READ, REWRITE, and RETURN commands. Check RESP codes after each command.
Enhance your transaction to:
Write a transaction that:
Question: What happens if the first update succeeds but the second fails?
Explain how each ACID property applies to a money transfer transaction:
1. What are the ACID properties of a CICS transaction?
2. What happens when a CICS transaction completes normally?
3. What is a task in CICS?
4. How can you explicitly rollback a transaction?
5. What is isolation in ACID properties?
6. What happens if a transaction abends?