WRITEQ TD
WRITEQ TD
The CICS WRITEQ TD statement is used to write data to a transient data queue (TDQ) in CICS. TDQs are used for temporary data storage and are often used for inter-program communication, logging, or batch job processing.
Unlike Temporary Storage Queues (TSQs), TDQs can be predefined in the CICS region and can be associated with an external destination like a printer, spool, or database.
Syntax -
EXEC CICS WRITEQ TD
QUEUE('queue-name')
FROM(data-area)
LENGTH(length)
[SYSID(system-name)]
[RESP(response-field)]
[RESP2(response-field2)]
END-EXEC.
- QUEUE('queue-name') - Specifies the name of the transient data queue to write data to.
- FROM(data-area) - Defines the data area containing the information to be stored in the queue.
- LENGTH(length) - Specifies the length of the data to be written to the queue.
- SYSID(system-name) - Specifies the system name to which the request is directed.
- RESP(response-variable) - Optional. It captures the response code of the WRITEQ TD operation and used to check if the command executed successfully or encountered an error.
- RESP2(response2-variable) - Optional. It captures the response2 code of the WRITEQ TD operation when the error occured.
How it works?
- The WRITEQ TD command writes data to a specified transient data queue (TDQ).
- If the TDQ is an intrapartition queue, the data remains in CICS memory until it is processed.
- If the TDQ is an extrapartition queue, the data is sent to an external destination (e.g., printer, disk file).
- Once written, the data cannot be retrieved or modified (No rewrite).
- TDQs are automatically processed based on their configuration.
Short Examples -
Scenario - Writing a New Item to a Temporary Storage Queue
...
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-QUEUE-NAME PIC X(4) VALUE 'TDQA'.
01 WS-CUST-RECORD.
05 WS-CUST-ID PIC X(10).
05 WS-CUST-NAME PIC X(30).
05 WS-CUST-ADDRESS PIC X(50).
05 WS-CUST-PHONE PIC X(15).
05 WS-CUST-BAL PIC 9(15).
01 WS-RESP PIC S9(4) COMP.
PROCEDURE DIVISION.
EXEC CICS WRITEQ TD
QUEUE(WS-QUEUE-NAME)
FROM(WS-CUST-RECORD)
LENGTH(WS-LENGTH)
RESP(WS-RESP)
END-EXEC.
IF WS-RESP = DFHRESP(NORMAL) THEN
...
ELSE
...
END-IF.
...
The queue name TDQA is assigned to WS-QUEUE-NAME. The message in WS-CUST-RECORD is written to the TDQ using WRITEQ TD. The response code is checked to confirm whether the write operation was successful.
Error Conditions -
Eror Condition | RESP | RESP2 | Reason |
---|---|---|---|
ERROR | 1 | Occurs for any other condition that does not raise. | |
INVREQ | 16 | Occurs if WRITEQ names an extra-partition queue that has been opened for input.This condition cannot be raised for intra-partition queues. | |
IOERR | 17 | Occurs when an input/output error and the data record in error is skipped. | |
NOSPACE | 18 | Occurs if no more space exists on the intra-partition or extra-partition queue, or the relative byte address (RBA) for an intra-partition queue would exceed 2 GB. | |
NOTOPEN | 19 | Occurs if the destination is closed. | |
LENGERR | 22 | Occurs in either of the following situations -
| |
QIDERR | 44 | Occurs if the symbolic destination to be used cannot be found. | |
SYSIDERR | 53 | Occurs when the SYSID option specifies a name that is neither the local system nor a remote system. | |
NOTAUTH | 70 | A resource security check has failed on QUEUE (name). | |
DISABLED | 84 | Occurs when the queue has been disabled. |