READQ TD
The CICS READQ TD statement is used to retrieve data from a transient data queue (TDQ) in CICS. Once a record is read, it is no longer available, which is why this type of queue is called to as a read-destructive queue.
TDQs are predefined in CICS and do not allow direct access to specific records. They can be classified as either intrapartition (within CICS) or extrapartition (which includes external files, printers, etc.).
Syntax -
EXEC CICS READQ TD
QUEUE('queue-name')
INTO(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 read from.
- INTO(data-area) - Defines the data area where the retrieved information will be stored.
- LENGTH(length) - Specifies the length of data to be read from 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 READQ 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 READQ TD operation when the error occured.
How it works?
- The READQ TD command retrieves the first available record from the specified TDQ.
- If an intrapartition TDQ is used, the record is deleted automatically after reading.
- If an extrapartition TDQ is used, the record remains in the queue and must be deleted manually.
- Once data is retrieved, it is stored in the specified INTO data area.
Short Examples -
Scenario - Reading a Specific Item from 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-LENGTH PIC S9(4) COMP VALUE 120.
01 WS-RESP PIC S9(4) COMP.
PROCEDURE DIVISION.
EXEC CICS READQ TD
QUEUE(WS-QUEUE-NAME)
INTO(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 specified. The first available record in the queue is read and stored in WS-CUST-RECORD. The response code (RESP) is checked to confirm whether the read operation was successful or if the queue is empty (QZERO).
Error Conditions -
Eror Condition | RESP | RESP2 | Reason |
---|---|---|---|
INVREQ | 16 | This condition only occurs for extra-partition queue.Occurs if the queue specified has been opened for output. | |
IOERR | 17 | Occurs when an input/output error and the data record in error is skipped. | |
NOTOPEN | 19 | Occurs if the destination is closed. This condition applies to extra-partition queues only. | |
LENGERR | 22 | Occurs if READQ INTO area is shorter than the data read from queue or an invalid length has been supplied. | |
QZERO | 23 | Occurs when the destination (queue) is empty or the end of the queue has been reached. | |
QBUSY | 25 | Occurs if a READQ TD command attempts to access a record in a logically recoverable queue (that is being written to or is being deleted by another task and there are no more committed records). This condition applies only to intra-partition queues. | |
QIDERR | 44 | Occurs when the queue specified 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 disabled. |