Module 7: CICS Temporary Storage and Transient Data
WRITEQ TS
The WRITEQ TS command is how you put data into temporary storage. It adds a new record to a queue, or updates an existing record when you ask for a rewrite.
Syntax and options
- QUEUE or QNAME - the name of the TS queue. QUEUE takes 1 to 8 characters; QNAME takes up to 16 characters.
- FROM - the data area that holds the record you want to write.
- ITEM - the item number of the record to update. Used only with REWRITE.
- REWRITE - tells CICS to update an existing record instead of adding a new one.
- NUMITEMS - a field where CICS puts the number of records in the queue after the new record is added.
- MAIN or AUXILIARY - keeps the queue in main storage or on disk in the DFHTEMP file.
Adding a record
- To add a record, code just QUEUE (or QNAME) and FROM. Each new record gets the next item number automatically.
- If the queue does not exist, CICS creates it, in main or auxiliary storage as you asked.
- This is the most common use: collecting records one by one, for example invoice lines.
Updating a record
- To update, code ITEM with the item number and the REWRITE keyword. The record is replaced with the data in the FROM area.
- If the item number does not exist, CICS raises the ITEMERR condition.
- If the queue itself does not exist, CICS raises the QIDERR condition.
- A typical pattern: read a customer record with READ FILE, save it in a TS queue, then rewrite the TS item when the user changes the data.
Example:-
*--- Add a new record to the queue ---*
EXEC CICS
WRITEQ TS QUEUE(TS-QUEUE-NAME)
FROM(TS-QUEUE-RECORD)
END-EXEC.
*--- Update item 1 already in the queue ---*
EXEC CICS
WRITEQ TS QUEUE(TS-QUEUE-NAME)
FROM(TS-QUEUE-RECORD)
ITEM(TS-ITEM-NUMBER) REWRITE
RESP(RESPONSE-CODE)
END-EXEC.
IF RESPONSE-CODE = DFHRESP(ITEMERR)
MOVE 'Item does not exist' TO MSG
END-IF.
