In VSAM you identify and position to records in different ways depending on the dataset type. Two important methods are the relative byte address (RBA) and the relative record number (RRN). RBA is a byte offset from the start of the dataset—it says "the record starts at this byte." RRN is a slot number (1, 2, 3, …)—it says "the record is in slot N." ESDS and KSDS use RBA (and key for KSDS); RRDS uses RRN. Choosing the right type and thus the right addressing method affects how you write your program and how stable record "addresses" are over time. This page explains the difference between RBA and RRN, when each is used, and how they compare.
The relative byte address is the offset, in bytes, of a record (or the start of a control interval) from the beginning of the data component. The first byte of the dataset is RBA 0; the next record might start at RBA 80 (if the first record is 80 bytes), and so on. RBA is typically a 4-byte value. In an ESDS, records are stored in entry order, so each record has a fixed position and thus an RBA. You can save that RBA and later position back to the same record (e.g. READ by RBA or START at RBA then READ). So RBA gives you "position-based" access: you identify a record by where it is in the file. RBA is stable until the record is deleted or the file is reorganized; after a REPRO or major change, RBAs can change. For very large datasets (over 4 GB), extended addressability (e.g. XRBA) may be used so that the offset can exceed 4 bytes.
The relative record number is the slot number in an RRDS. The dataset is divided into fixed-length slots, numbered 1, 2, 3, and so on. To read or write a specific record you specify the RRN (e.g. RRN 5 for the fifth slot). Each slot either contains a record or is empty (e.g. after a delete). So RRN is an index: "give me the record in slot N." It is not a byte offset; it is a slot index. The mapping from RRN to physical location (which CI, which slot within the CI) is done by VSAM. RRN is useful when you have a direct mapping from some application key to a slot number (e.g. customer number 1–10000 maps to RRN 1–10000) or when you want array-like access by position. Slots are fixed in number (determined by allocation and record length); you cannot "append" a new slot the way you append a record in ESDS—you use an existing empty slot.
| Aspect | RBA | RRN |
|---|---|---|
| Meaning | Byte offset from start of component (e.g. 0, 4096, 8192) | Slot number: 1, 2, 3, … (integer index) |
| Unit | Bytes (position in the dataset) | Record/slot number (which slot) |
| Used by | ESDS (primary), KSDS (optional/support) | RRDS, VRRDS only |
| Record size | Variable or fixed; RBA points to start of record | Fixed-length slots (or variable in VRRDS); RRN = slot index |
| Stability | Stable until record deleted or file reorg; then RBAs can change | Slot numbers are fixed; slot 5 is always slot 5 unless slot is reused |
Use RBA when you need to remember "where" a record is and come back to it later. ESDS is the main dataset type that uses RBA for direct access: you read sequentially and save the RBA of interesting records, or you position by RBA to read a specific record. RBA is also used internally by VSAM for the index (e.g. pointers from index to data CIs). In application programming, RBA is typical for ESDS (logs, audit trails, sequential files where you need to jump back to a position). RBA is in bytes, so record boundaries are determined by the record layout and RDFs; the program or the access method uses the RBA to find the correct CI and then the record within it.
Use RRN when you want to address by slot number. RRDS is the only type that uses RRN. You use it when you have a fixed set of "buckets" (e.g. one slot per customer ID if the ID is in a small range and maps to 1–N), or when you want direct access by position without a key. Insert is "write to an empty slot"; delete is "clear the slot." So RRN is good for lookup tables, caches, or any structure where the natural address is "slot number" rather than "byte offset" or "key." Variable-length RRDS (VRRDS) still uses slot numbers, but each slot can hold a variable-length record.
RBA: After you write a record in an ESDS, its RBA is fixed until that record is deleted or the file is reorganized. If you REPRO the ESDS to a new cluster, the new file has different physical layout and the old RBAs are no longer valid for the new file. So if you store RBAs (e.g. in a key or in another file), they are valid only for that version of the dataset. RRN: Slot numbers (RRNs) are fixed for the life of the dataset. Slot 5 is always slot 5. So RRN is stable across opens and closes; it is not stable across a REPRO to a new cluster if the new cluster has a different number of slots or different allocation. For RRDS, typically the slot count is fixed by allocation and record length, so RRN 1–N remain meaningful as long as the dataset structure is the same.
RBA is like saying "the book is 50 steps from the start of the shelf"—you measure in steps (bytes). RRN is like saying "the book is in the 5th slot"—you count slots (1, 2, 3, 4, 5). One is distance; one is slot number. You use the one that matches your filing system: ESDS uses distance (RBA), RRDS uses slot number (RRN).
1. What does RBA represent?
2. Which dataset type uses RRN for addressing?
3. How is RRN different from RBA?