CICS file management covers how transactions read and update records in files (typically VSAM and BDAM) and how temporary data is stored in temporary storage queues. Programs use File Control commands—READ, WRITE, REWRITE, DELETE—and each file must be defined in the File Control Table (FCT). This page explains these commands, the role of the FCT, and how temporary storage fits in.
Imagine CICS as a librarian. The library has filing cabinets (files). Before you can look at or change a folder, the librarian must know which cabinet you mean and whether you are allowed to read or change it. File management is the set of rules and commands: "read this folder," "add a new folder," "change this folder," "remove this folder." There is also a scratch pad (temporary storage) where you can jot things down during your visit. The librarian (CICS) keeps track of who has which folder open so two people do not change it at once.
File Control is the CICS component that handles file I/O. Every file a CICS region can access must be defined in the File Control Table (FCT). An FCT entry specifies the logical file name used in programs, the physical dataset name (e.g. VSAM cluster name), the file type (KSDS, ESDS, RRDS, etc.), and which operations are allowed: read, update (REWRITE/DELETE), add (WRITE), browse (sequential read with STARTBR/READNEXT/ENDBR), and delete. The program uses the logical file name in EXEC CICS READ FILE(name) etc.; CICS translates it to the dataset and enforces the allowed operations. If the FCT does not allow update, a REWRITE or DELETE will fail.
EXEC CICS READ retrieves one record from a file. For keyed files (e.g. VSAM KSDS), you set the key in the RIDFLD (record identifier field) and optionally specify KEYLENGTH. The record is returned INTO a data area (or you use SET for a pointer). If you intend to update or delete the record later, you must use READ with the UPDATE option so CICS locks the record; otherwise another task could change it before you REWRITE or DELETE. The response code indicates success (NORMAL) or conditions such as NOTFND (record not found), and for optional files you can get a specific response when the file is not open. Always check the response after READ.
123456789101112131415EXEC CICS READ FILE('ACCTFILE') RIDFLD(WS-ACCT-KEY) INTO(WS-ACCT-REC) UPDATE RESP(WS-RESP) RESP2(WS-RESP2) END-EXEC IF WS-RESP NOT = DFHRESP(NORMAL) IF WS-RESP = DFHRESP(NOTFND) PERFORM RECORD-NOT-FOUND ELSE PERFORM FILE-ERROR END-IF END-IF.
RIDFLD must be at least as long as the key (or the full RID for RRDS). For READ UPDATE, the same RIDFLD is used in the subsequent REWRITE or DELETE so CICS knows which record to update or remove.
EXEC CICS WRITE adds a new record to the file. You supply the record content in the FROM (or INTO) area and the key (or RID) in RIDFLD. For a KSDS, the key must be unique; if a record with that key already exists, CICS typically returns DUPREC (duplicate record). For ESDS you do not supply a key; CICS may use RIDFLD to return the RBA of the new record. LENGTH and KEYLENGTH can be specified if needed. The FCT must allow add (write) for the file. After a successful WRITE, the record is in the file and can be read or updated by the same or another task according to the file type and locking rules.
REWRITE replaces an existing record. You must have read that record earlier with READ UPDATE. You then modify the data in your buffer (the INTO area from the READ) and issue EXEC CICS REWRITE FILE(name) FROM(updated-area) (and optionally LENGTH). The value in RIDFLD must not change between the READ and the REWRITE—it identifies the same record. If the record was deleted by another task after your READ, or if you did not do a READ UPDATE, REWRITE can fail (e.g. NOTFND or invalid state). REWRITE does not change the key in keyed files; to change the key you typically delete the old record and write a new one with the new key.
EXEC CICS DELETE removes a record from the file. For keyed files you must have read the record with READ UPDATE first; then issue DELETE FILE(name) RIDFLD(same-key). The record is removed from the file. The FCT must allow delete for that file. After DELETE, the record is gone; any subsequent READ with that key will return NOTFND.
| Command | Purpose | Note |
|---|---|---|
| READ | Retrieve a record by key or RID. | Use UPDATE if you will REWRITE or DELETE. Returns NOTFND if record does not exist. |
| WRITE | Add a new record to the file. | Key or RID in RIDFLD; data in FROM. Duplicate key can return DUPREC or error depending on file type. |
| REWRITE | Update a record already read with READ UPDATE. | Key must not change. Record must still exist and not have been deleted by another task. |
| DELETE | Remove a record from the file. | Record must have been read with READ UPDATE first (for keyed files). RIDFLD identifies the record. |
| READNEXT / READPREV | Browse sequentially (forward or backward). | Used with STARTBR/ENDBR for browse operations; RIDFLD updated on each read. |
For sequential access (e.g. "read all records in key order") you use STARTBR to position at a key or RBA, then READNEXT (or READPREV) repeatedly until you get NOTFND or reach the end. ENDBR releases the browse. RIDFLD is updated after each READNEXT/READPREV so you know the current position. Browse does not lock records for update; use READ UPDATE for a single record if you need to REWRITE or DELETE.
Besides files, CICS provides temporary storage: named queues (TSQs) that can hold data for a task or across tasks. You WRITEQ TS to add items to a queue and READQ TS to read them. Queues can be task-private or shared (same queue name from different tasks). Data can be recoverable (logged) or not. Main temporary storage holds queues in memory; auxiliary temporary storage uses a backing dataset (e.g. VSAM DFHTEMP). Main is faster but limited in size and lost on region failure unless recoverable; auxiliary can hold more and survive restarts when recoverable. Use TS for work areas, lists built during a transaction, or passing data between related transactions.
| Type | Storage | Typical use |
|---|---|---|
| Main (in-memory) | CICS region memory. | Short-lived, fast; lost on region failure unless recoverable. |
| Auxiliary | Backing file (e.g. VSAM DFHTEMP). | Larger data, survives region restart if recoverable; more I/O. |
Every File Control command returns a response. Use RESP and optionally RESP2 in the EXEC CICS command to capture the code; then check it. NORMAL means success. NOTFND means the record was not found (READ, REWRITE, DELETE). DUPREC means duplicate key on WRITE. Other codes indicate I/O errors, invalid state (e.g. REWRITE without READ UPDATE), or file not open. Always handle NOTFND and duplicate key where applicable and log or handle permanent errors so transactions do not leave data inconsistent.
1. Before issuing REWRITE you must:
2. The FCT in CICS defines:
3. Temporary storage queues (TSQ) in CICS are used to: