CICS

CICS Temporary Storage Queue Lifecycle: Safe TSQ Cleanup and Production Support

Learn a safe CICS TSQ lifecycle for temporary storage queues, including queue naming, WRITEQ/READQ/DELETEQ TS, cleanup, diagnostics, and production support.

Terminal inputCICS taskValidationSafe response
Original DBala learning flow — a visual summary of this article’s practical decision path.

Short introduction

CICS Temporary Storage Queues (TSQs) are a practical way to hold short-lived data while a transaction is in progress. A program can write an item to a queue, read it again in a later program or pseudo-conversational task, update an item, and finally delete the queue. This is useful when a user moves through several screens and the application should not keep a task active while waiting for input.

The command syntax is not the difficult part. In production support, the important questions are: who owns the queue, when should it be deleted, what happens when a user abandons a transaction, and how will support identify an unexpected queue buildup? A TSQ that is never deleted can waste storage or create confusing behavior when queue names are reused. A TSQ deleted too early can cause a later screen to fail.

This article explains a support-friendly lifecycle for TSQs using a generic service-request example. Names and values are illustrative; adapt them to local CICS standards.

Real-world production use case

Imagine an online healthcare service-request inquiry. A representative enters a member identifier and request date range. The first CICS program validates the input and retrieves matching request summaries. The user can page forward, select one request, and view more detail on another screen.

The search may return more rows than fit on one screen. Rather than repeating the DB2 query on every page, the application stores the result keys and display fields in a TSQ. The queue name contains a generated correlation value, not the member identifier. The next transaction reads the appropriate item for the requested page. When the user selects an item, the detail program uses its stored request key to retrieve current data.

This design needs a clear lifecycle:

The result is responsive online navigation without holding a DB2 cursor or a CICS task open across user think time.

Step-by-step explanation

### 1. Choose the right queue type and data scope

CICS supports auxiliary and main temporary storage queues. The choice depends on local configuration, performance expectations, recovery needs, and storage policy. Application code should not assume that a queue behaves like a permanent database table. A TSQ is working data for an active business flow.

Store a compact, defined record. For a search result, that may be request ID, service date, status, and a short description. Avoid copying unrestricted sensitive detail merely because it is convenient. The program that displays a detail page can retrieve authoritative data again using the saved key and must still apply its normal authorization checks.

### 2. Create a collision-resistant queue name

A queue name must be unique enough for concurrent transactions. Do not use a predictable business key such as a member ID or account number by itself. Two representatives might search for the same member at the same time, and business identifiers may be sensitive.

A common pattern is an application prefix plus a generated session or correlation token. The token can be passed between pseudo-conversational screens in a protected application context or COMMAREA/channel design, according to site conventions. Keep the queue name within the limits and naming rules configured for the CICS environment.

For support, log the queue name, transaction ID, and a non-sensitive correlation ID when errors happen. Do not place personal data in diagnostic messages unnecessarily.

### 3. Write and read items deliberately

Use a predictable item numbering convention. For example, item 1 can be the first result row, item 2 the next row, and so on. Store the total row count separately, either in a control item or in the application state. Check RESP and RESP2 for every CICS command. A QIDERR on a read is not the same problem as an I/O issue; it may mean the queue was already cleaned up, the user session expired, or the wrong queue name was passed.

Do not assume that a successful WRITEQ TS means every later program can read the item. The later transaction must receive the correct queue name and item number, and it should handle missing data gracefully by returning the user to a fresh search rather than displaying stale information.

### 4. Delete the queue at the end of the business flow

Delete the queue once the user completes, cancels, or times out of the workflow. Include deletion in normal end paths and in controlled error handling. For a multi-screen flow, do not delete it immediately after the first response; establish clearly which transaction owns final cleanup.

A CICS task can end abnormally, a browser or terminal can disconnect, or a user can simply stop. Therefore, application deletion alone is not enough. Operations should have a documented retention and cleanup approach agreed with CICS administrators. The exact mechanism varies by site, so do not run broad queue deletion commands in production without an approved procedure.

### 5. Make support diagnostics actionable

When a TSQ operation fails, capture the operation, queue name or safe correlation value, item number, EIBRESP, EIBRESP2, transaction ID, and program name. Record counts can help diagnose a paging problem: rows found, items written, requested page, and requested item.

A clear message such as TSQ READ QIDERR: token=SRQ8A71 item=16 tran=SRQP is more useful than TEMP STORAGE ERROR. It helps support determine whether the issue is expired state, a navigation defect, an unexpected cleanup, or a configuration/resource problem.

Example COBOL CICS pattern

The following simplified example writes a result item, reads it later, and deletes the queue during cancellation. Production programs should use their site's error routines, copybooks, and security practices.

       WORKING-STORAGE SECTION.
       01  WS-TSQ-NAME              PIC X(08) VALUE 'SRQ8A71 '.
       01  WS-ITEM-NUMBER           PIC S9(4) COMP VALUE 1.
       01  WS-RESULT-ROW.
           05 WS-REQUEST-ID         PIC X(12).
           05 WS-SERVICE-DATE       PIC X(10).
           05 WS-REQUEST-STATUS     PIC X(01).
           05 WS-SHORT-DESC         PIC X(40).
       01  WS-RESP                  PIC S9(8) COMP.
       01  WS-RESP2                 PIC S9(8) COMP.

* Write one result row after validation.
EXEC CICS
WRITEQ TS
QUEUE(WS-TSQ-NAME)
FROM(WS-RESULT-ROW)
LENGTH(LENGTH OF WS-RESULT-ROW)
ITEM(WS-ITEM-NUMBER)
RESP(WS-RESP)
RESP2(WS-RESP2)
END-EXEC

IF WS-RESP NOT = DFHRESP(NORMAL)
PERFORM LOG-TSQ-ERROR
PERFORM SEND-TECHNICAL-ERROR-SCREEN
END-IF

* In the next pseudo-conversational transaction, read item 1.
EXEC CICS
READQ TS
QUEUE(WS-TSQ-NAME)
INTO(WS-RESULT-ROW)
LENGTH(LENGTH OF WS-RESULT-ROW)
ITEM(WS-ITEM-NUMBER)
RESP(WS-RESP)
RESP2(WS-RESP2)
END-EXEC

EVALUATE WS-RESP
WHEN DFHRESP(NORMAL)
PERFORM BUILD-RESULT-MAP
WHEN DFHRESP(QIDERR)
PERFORM SEND-SEARCH-EXPIRED-MESSAGE
WHEN OTHER
PERFORM LOG-TSQ-ERROR
PERFORM SEND-TECHNICAL-ERROR-SCREEN
END-EVALUATE

* On explicit cancel or final completion, remove all items.
EXEC CICS
DELETEQ TS
QUEUE(WS-TSQ-NAME)
RESP(WS-RESP)
RESP2(WS-RESP2)
END-EXEC.
```

In real code, the queue token is normally generated rather than hard-coded. Also confirm local standards for queue name format, error-copybook use, and whether the application uses a COMMAREA or channels and containers to carry the token.

Common mistakes

Practical checklist

Before supporting or releasing a CICS flow that uses TSQs, verify:

Summary

TSQs are useful for keeping a CICS conversation responsive across multiple screens, especially for short-lived result sets and paging. The safe pattern is to create a unique queue, store minimal working data, check each CICS response, and clean up deliberately on completion or cancellation.

For production support, the lifecycle matters as much as the command syntax. Clear ownership, safe queue names, diagnostics, and an approved approach to abandoned sessions make temporary storage easier to operate and troubleshoot. Treat the TSQ as temporary application state—not a database—and the design remains clearer for both CICS developers and support teams.

← Back to all articles