Data-oriented EXEC CICS commands are how online programs manipulate VSAM records: READ retrieves rows, WRITE inserts new rows, REWRITE replaces rows previously read for update, and DELETE removes rows held for update. Each command accepts parameters that must agree with the CICS file definition and the underlying DEFINE CLUSTER attributes. This page explains the most common parameters—FILE, INTO, FROM, LENGTH, RIDFLD, KEYLENGTH, UPDATE—and the RESP discipline beginners adopt after their first production NOTFOUND incident. Examples show COBol-shaped pseudocode; adjust names to your copybooks and standards. Always cross-check optional keywords such as TOKEN, SYSID, or data set positioning clauses with the Application Programming Reference for your CICS release because enterprises enable different subsets.
| Command | Beginner notes |
|---|---|
| READ | Fetch by RIDFLD; optional UPDATE for lock; LENGTH tells max receive size; return area may be partial if allowed. |
| WRITE | Insert new record; duplicate key handling via RESP; LENGTH is send size. |
| REWRITE | Replace record held from READ UPDATE; lengths must remain valid for VSAM define. |
| DELETE | Remove record held from READ UPDATE; follow with SYNCPOINT rules per design. |
123456789101112131415161718MOVE CUST-ID-IN TO WS-CUST-KEY EXEC CICS READ FILE('CUSTMAS') INTO(WS-CUST-REC) LENGTH(WS-LEN) RIDFLD(WS-CUST-KEY) KEYLENGTH(10) RESP(WS-RESP) END-EXEC IF WS-RESP = 0 PERFORM USE-CUSTOMER ELSE IF WS-RESP = 13 PERFORM NO-CUSTOMER ELSE PERFORM READ-ERROR END-IF END-IF
Compare RESP to symbolic constants from your copybooks when available; numeric examples in training slides (such as 13 for NOTFOUND on many levels) must be verified against your CICS documentation because values are not portable trivia. LENGTH is often a fullword working storage item set to the maximum buffer size before the call and updated to the actual length returned when the command supports that pattern. If your program intentionally reads partial records, document the business meaning; otherwise set LENGTH to the full maximum to avoid truncation bugs.
1234567891011121314151617EXEC CICS READ FILE('CUSTMAS') INTO(WS-CUST-REC) LENGTH(WS-LEN) RIDFLD(WS-CUST-KEY) KEYLENGTH(10) UPDATE RESP(WS-RESP) END-EXEC ... validate ... MOVE NEW-EMAIL TO EMAIL-FIELD OF WS-CUST-REC EXEC CICS REWRITE FILE('CUSTMAS') FROM(WS-CUST-REC) LENGTH(WS-LEN) RESP(WS-RESP) END-EXEC
If the transaction ends without REWRITE or DELETE after READ UPDATE, you may hold locks longer than users tolerate. Design short units of work with SYNCPOINT boundaries consistent with your persistence story. When SYNCPOINT rolls back, the REWRITE never persisted; training materials should show both happy and rollback paths so new developers do not assume success from lack of abend messages alone.
Populate RIDFLD with the new key, FROM with the record image, LENGTH with send length, then EXEC CICS WRITE. Handle duplicate key RESP by branching to an update flow or rejection message. For variable-length records, LENGTH must reflect the actual bytes you intend VSAM to store subject to maximum. Heavy insert hotspots still stress CI splits just like batch; capacity belongs in architecture reviews, not only in post-mortems.
DELETE follows READ UPDATE for the row you intend to remove. Some patterns read without update when business rules allow; follow your manual and standards rather than improvising. After DELETE, subsequent READs for the same key should return NOTFOUND unless duplicates exist and your program walks remaining duplicates by design.
Legacy programs sometimes use HANDLE CONDITION to branch on ERROR or NOTFOUND globally. Modern mixed-language applications often prefer explicit RESP on each command for clarity. Your shop standard wins over personal taste. Mixing both styles in one program is difficult to debug because flow jumps to labels far from the failing EXEC block. Refactoring HANDLE programs is a modernization task worth scheduling explicitly rather than pretending it will happen accidentally during small fixes.
Some architectures ship file requests to remote regions using SYSID or token parameters. Beginners should recognize keywords when reading code even if they do not implement them yet. Misconfigured function shipping can yield NOTAUTH style responses that look like VSAM corruption until someone traces the request to the wrong region. Keep architecture phone numbers handy when those tickets appear.
Some services intentionally read only a prefix of large rows for summary displays. If you adopt partial reads, document maximum LENGTH per API version and update mobile clients when that maximum grows. Otherwise you will ship silent truncation that compliance teams classify as a data integrity defect even though RESP stayed NORMAL.
READ is peeking at one card in a box. READ UPDATE is holding that card in your hand so nobody else can change it until you put it back or throw it away. REWRITE is putting the card back with new crayon marks. DELETE is tossing the card in recycling. WRITE is slipping a brand new card into the sorted deck in the right place. RESP is the sticker on your hand that says whether the librarian let you do it.
1. Which READ option prepares a KSDS row for REWRITE?
2. WRITE against an existing primary key on a unique KSDS typically yields:
3. RIDFLD must align with: