Deleting a record from an RRDS means removing the record at a specific relative record number (RRN) and freeing that slot or RRN for possible reuse. You do this by setting the RRN (e.g. in the COBOL RELATIVE KEY) to the record you want to remove and issuing DELETE. The record is removed from the file. In a fixed RRDS the slot becomes empty; in a variable RRDS the RRN is freed and the index is updated. If the cluster was defined with REUSE, that slot or RRN can later be used again for a new WRITE. If the cluster has NOREUSE (or the default), the slot remains empty and is not reused. This page explains how delete works in fixed and variable RRDS, the effect of REUSE and NOREUSE, what happens when you delete an empty slot, and how to perform delete in COBOL.
Delete means: remove the record at a given RRN. You specify the RRN (the slot number or relative record number) and issue the DELETE command. The access method finds that record—either by slot position (fixed RRDS) or by index (variable RRDS)—and removes it. The slot is then empty (fixed) or the RRN is no longer associated with a record (variable). The space that held the record is not necessarily returned to the system; in fixed RRDS the slot remains part of the file but is marked empty. So delete is "free this RRN" rather than "shrink the file."
As with READ and WRITE, you identify the record by its RRN. Move the RRN of the record you want to delete into the RELATIVE KEY (in COBOL) or the equivalent field for your language or API. Then issue DELETE. The system removes the record at that RRN. If there is no record at that RRN (slot is empty or RRN was never used), the DELETE fails with a record-not-found or invalid-key condition. So you can only delete a record that exists; you cannot "delete" an already-empty slot.
In a fixed-length RRDS each slot holds zero or one record. When you DELETE at an RRN, the record in that slot is removed. The slot becomes empty. The slot still exists—it still has the same RRN—but it no longer contains a record. A subsequent READ at that RRN will return "record not found" (or equivalent). Whether you can later WRITE a new record at that same RRN depends on REUSE. With REUSE the slot is available for a new WRITE; with NOREUSE the slot typically stays empty and may not accept a new WRITE at that RRN.
In a variable-length RRDS the index maps each RRN to the record. When you DELETE at an RRN, the record is removed and the index entry for that RRN is updated (the RRN is no longer associated with a record). The space that held the record may be reclaimed internally. If the cluster has REUSE, that RRN can be assigned to a new record when you WRITE with that RRN. So the behavior is analogous to fixed RRDS: delete frees the RRN, and REUSE determines whether the RRN can be reused.
REUSE and NOREUSE are specified when you define the cluster (in DEFINE CLUSTER). They cannot be changed later without redefining the cluster. REUSE means that when you delete a record, the slot (fixed) or RRN (variable) becomes available for a new record. So the lifecycle is: WRITE at RRN 5 (insert), later DELETE at RRN 5 (remove), then WRITE at RRN 5 again (re-insert). NOREUSE means that once you delete a record at an RRN, that RRN is not reused. The slot remains empty. This is useful when you want to preserve the meaning of RRNs (e.g. RRN 5 must always refer to the same logical "slot" even after deletion) or when your application never reuses slots. Many applications prefer REUSE so that space from deleted records can be used again.
| Type / option | Behavior |
|---|---|
| Fixed RRDS | Slot is marked empty. With REUSE, a new WRITE at that RRN can use the slot. |
| Variable RRDS | Record is removed; index entry for that RRN is updated. With REUSE, RRN can be assigned to a new record. |
| NOREUSE | Slot/RRN stays empty and is not reused. READ at that RRN returns record not found. |
In COBOL you set the RELATIVE KEY to the RRN of the record you want to delete and then issue DELETE. You do not need to READ the record first (though you can if you need to verify it exists or use its data). Example: delete the record at RRN 12.
123456789101112131415SELECT RRDSFILE ASSIGN TO RRDSFILE ORGANIZATION IS RELATIVE ACCESS MODE IS RANDOM RELATIVE KEY IS WS-RRN FILE STATUS IS WS-STATUS. ... 01 WS-RRN PIC 9(8) COMP. ... MOVE 12 TO WS-RRN DELETE RRDSFILE INVALID KEY DISPLAY 'No record at RRN 12 or delete failed' NOT INVALID KEY DISPLAY 'Record at RRN 12 deleted' END-DELETE
If a record exists at RRN 12, the DELETE succeeds and the slot or RRN is freed. If the slot is empty or the RRN has no record, INVALID KEY is raised. Your program should check FILE STATUS or INVALID KEY to handle both cases.
Deleting records does not shrink the physical file. In a fixed RRDS the slots are pre-allocated; when you delete a record, the slot is just marked empty. The total space (e.g. cylinders) stays the same. In variable RRDS the space previously occupied by the record may be reused internally for new records, but the dataset extent does not necessarily shrink. To reduce allocated space you would typically define a new cluster with less space and REPRO the records you want to keep (excluding the deleted RRNs), or use system-specific utilities.
Use DELETE when you need to remove a record and free its RRN. For example, removing an employee record when they leave, or clearing a cache slot. If you want to "clear" the content but keep the slot for future use with the same RRN, delete and then (with REUSE) write a new record later. If you want to change the content of an existing record without freeing the slot, use READ followed by REWRITE (see Replace) instead of DELETE.
Imagine numbered mailboxes. To "delete" means you take the letter out of mailbox 7. Now mailbox 7 is empty. If the rule is REUSE, someone can put a new letter in mailbox 7 later. If the rule is NOREUSE, mailbox 7 stays empty forever. You can only take a letter out of a mailbox that has a letter; if mailbox 7 is already empty, you can't "delete" it again (you get an error). Delete = take the thing out of that number and free the number for maybe use again.
1. How do you delete the record at RRN 7 in an RRDS?
2. With REUSE, after you DELETE the record at RRN 5, what can you do?
3. What typically happens if you DELETE at an RRN that has no record?