Exercises: Advanced CICS Programming

Exercise 30.1: TSQ Basics (Introductory)

Write a CICS program that demonstrates basic TSQ operations:

  1. Create a TSQ named with prefix 'TST' + EIBTRMID
  2. Write 10 items to the TSQ, each containing a sequence number (1-10) and a descriptive text
  3. Read item 5 directly by item number and display it
  4. Read all items sequentially using NEXT and display each one
  5. Update item 3 with new data using REWRITE
  6. Delete the entire TSQ
  7. Handle QIDERR, ITEMERR, and other RESP conditions

Requirements: - Use RESP on every EXEC CICS command - Display results using SEND TEXT (no BMS map needed for this exercise) - Include proper error handling for each TSQ operation

Exercise 30.2: Audit Trail with TDQ (Introductory)

Create a simple audit logging framework:

  1. Define an audit record structure: timestamp, terminal ID, transaction ID, user ID, action code, detail message
  2. Write a reusable paragraph (or LINK-able program) that writes audit records to an intrapartition TDQ named 'AUDT'
  3. Call this logging routine from multiple points in your program: transaction start, data lookup, data update, transaction end
  4. Handle QIDERR (queue not defined) gracefully — log the error but do not abend

Discussion: Why is TDQ preferred over TSQ for audit logging? What would happen if the audit records were written to a TSQ instead?

Exercise 30.3: Browse/Scroll Transaction (Intermediate)

Build a complete browse/scroll CICS transaction for a Product Catalog:

Screen Layout (PRODBRW):

Row 1:  PRODUCT CATALOG BROWSE                   Date  Time
Row 3:  Category: [____]  (blank = all)
Row 5:  S  Code     Description              Price     Qty
Row 6:  _  XXXXX    XXXXXXXXXXXXXXXXXXXXXXXXX 99999.99  9999
        ... (repeat for 12 rows) ...
Row 18: (blank)
Row 20: Items nn-nn of nnn
Row 22: S=Select  PF7=Back  PF8=Forward  PF3=Exit

Requirements: 1. Accept optional category filter on the search field 2. Query DB2 and load results into a TSQ (limit to 500 items) 3. Display 12 items per page with PF7/PF8 scrolling 4. Handle boundary conditions: already at top, already at bottom 5. 'S' in the selection field shows product detail (separate map) 6. PF3 from detail returns to browse at the same position 7. PF3 from browse deletes the TSQ and exits 8. Clean up TSQ on first entry (in case of previous abandoned session)

Deliverables: - BMS map definitions for browse and detail screens - Complete COBOL program with COMMAREA state machine - Error handling for all CICS and DB2 operations

Exercise 30.4: Asynchronous Processing (Intermediate)

Write two CICS programs that work together asynchronously:

Program 1 (ORDENTRY): An order entry transaction that: 1. Accepts order details (customer, product, quantity) from a BMS screen 2. Validates the order 3. INSERTs the order into a DB2 table 4. Uses START to trigger Program 2 for fulfillment processing 5. Displays "Order submitted. Confirmation will follow." to the user

Program 2 (ORDFULFIL): A fulfillment transaction that: 1. Uses RETRIEVE to get the order data 2. Checks inventory levels 3. Updates inventory 4. Writes a confirmation record to a TDQ 5. Optionally uses START to trigger a third transaction for email notification

Requirements: - Program 1 must not wait for Program 2 - If START fails, log the error but still confirm the order to the user (with a warning) - Program 2 must handle retrieval errors gracefully - Test what happens if Program 2's transaction ID is not defined

Exercise 30.5: Channel/Container Communication (Intermediate)

Refactor a COMMAREA-based LINK call to use channels and containers:

Original (COMMAREA version):

01  WS-VAL-COMMAREA.
    05  WS-VAL-ACCT-NUM    PIC X(10).
    05  WS-VAL-AMOUNT      PIC S9(11)V9(2) COMP-3.
    05  WS-VAL-TYPE         PIC X(2).
    05  WS-VAL-RC           PIC S9(4) COMP.
    05  WS-VAL-MSG          PIC X(80).

EXEC CICS LINK PROGRAM('VALIDATE')
    COMMAREA(WS-VAL-COMMAREA) LENGTH(101) END-EXEC

Refactored (Channel/Container version): 1. Create a channel named 'VALIDATE-CHAN' 2. Put the input data in a container named 'REQUEST' 3. LINK with CHANNEL instead of COMMAREA 4. Read the result from containers 'RETURN-CODE' and 'RETURN-MSG' 5. Handle CONTAINERERR if a container is missing

Discussion: What are the advantages of the channel/container version? When would you choose COMMAREA over channels?

Exercise 30.6: Multi-Screen Maintenance Transaction (Advanced)

Build a complete 3-screen employee maintenance transaction:

Screen 1 — Search: - Employee ID input field - Enter = lookup, PF3 = exit

Screen 2 — Edit: - Display employee data with editable fields: name, department, salary, status - Employee ID, hire date, and last-modified fields are read-only - PF5 = save (goes to confirmation), PF3 = cancel (back to search) - Validate all edited fields before proceeding

Screen 3 — Confirmation: - Display original and new values side by side for each changed field - Mark changed fields with an asterisk - Enter = commit changes, PF3 = cancel (back to edit) - Use optimistic locking on the UPDATE (include original values in WHERE clause) - Handle "record changed by another user" condition

Requirements: 1. Complete COMMAREA design with state machine 2. Three BMS map definitions 3. Full COBOL program with proper state management 4. Input validation (numeric fields, valid department codes, salary range) 5. Optimistic locking with conflict detection 6. HANDLE ABEND for error recovery 7. Audit logging via TDQ for all successful updates

Exercise 30.7: Error Recovery Scenario (Advanced)

You are given a CICS program that processes a financial transaction in three steps: 1. Debit source account (DB2 UPDATE) 2. Credit destination account (DB2 UPDATE) 3. Log the transaction (DB2 INSERT)

The program uses HANDLE ABEND to catch errors. Write the complete error recovery logic for the following scenarios:

Scenario Step That Fails Required Recovery
A Step 2 (credit) fails Reverse the debit, notify user
B Step 3 (log) fails Keep the transfer but flag for manual audit
C ASRA abend during Step 1 Log diagnostics, notify user
D AKCT (timeout) during Step 2 Cannot programmatically recover — explain why and what the DBA must do

Requirements: - Write the HANDLE ABEND handler - Write the compensation logic for each scenario - Explain why CICS SYNCPOINT might be needed (or not) in each case - Discuss why this pattern is fragile and how a stored procedure approach (Chapter 28) would be more robust

Exercise 30.8: Design Challenge (Advanced)

Design (but do not code) a complete CICS application for a library book checkout system:

Transactions needed: 1. BSRC — Book search (by title, author, or ISBN) 2. COUT — Checkout (scan library card, scan book) 3. CKIN — Check-in (scan book, calculate fines) 4. PHLD — Place hold (reserve a book) 5. MENU — Main menu navigating to all transactions

For each transaction, specify: - Number of screens and their purpose - COMMAREA structure - TSQ usage (if any) - TDQ usage (if any) - DB2 tables accessed - LINK vs XCTL relationships between programs - START usage for async operations (overdue notices, etc.) - Security requirements - Error handling strategy

Deliverable: A design document with screen flow diagrams, COMMAREA layouts, and program structure charts.