Quiz — Chapter 13: Relative Files and RRDS

Multiple Choice

1. In a relative file, records are accessed by:

a) A key field within the record b) A relative record number (position in the file) c) A hash of the record contents d) The order in which they were written

2. Where must the RELATIVE KEY field be defined?

a) In the FILE SECTION as part of the record b) In the ENVIRONMENT DIVISION c) In WORKING-STORAGE SECTION d) It can be defined anywhere in the DATA DIVISION

3. What is the VSAM data set type for relative record organization?

a) KSDS (Key-Sequenced Data Set) b) ESDS (Entry-Sequenced Data Set) c) RRDS (Relative Record Data Set) d) LDS (Linear Data Set)

4. How many I/O operations does a random READ on a relative file typically require?

a) 1 b) 2-3 c) 3-4 d) It depends on the file size

5. In the IDCAMS DEFINE CLUSTER for an RRDS, which keyword replaces INDEXED?

a) RELATIVE b) NUMBERED c) POSITIONAL d) SEQUENTIAL

6. What does file status '23' mean for a relative file?

a) The file is full b) The slot is empty (no record at that RRN) c) A hash collision occurred d) The RRN exceeds the file size

7. In the division/remainder hash method, why is a prime number used as the divisor?

a) Prime numbers are faster to divide b) Prime numbers produce more uniform distributions of remainders c) Prime numbers prevent overflow d) Prime numbers are required by VSAM

8. What is the recommended load factor range for a hash-based relative file?

a) 90-100% b) 50-60% c) 67-77% d) 30-40%

9. Which collision handling strategy tries slots at positions N+1, N+4, N+9, N+16...?

a) Linear probing b) Quadratic probing c) Double hashing d) Separate chaining

10. Which of the following is NOT a disadvantage of relative files compared to indexed files?

a) No alternate key support b) Slower random access c) Potential disk waste from sparse allocation d) Sequential reads are in slot order, not business key order

True or False

11. Relative files support alternate record keys.

12. The first relative record number in a file is 0.

13. Sequential reading of a relative file automatically skips empty slots.

14. DELETE on a relative file truly empties the slot, unlike logical deletes on indexed files.

15. You must READ a record before you can REWRITE it in a relative file.

16. An RRDS requires both a DATA component and an INDEX component in VSAM.

17. The RELATIVE KEY field is part of the physical record stored on disk.

18. A relative file with 10,000 slots and 3,000 records has a load factor of 30%.

19. GnuCOBOL does not support relative file organization.

20. Hashing is always required when using relative files.

Short Answer

21. Explain why the RELATIVE KEY must be in WORKING-STORAGE rather than in the record description. What conceptual difference does this reflect compared to RECORD KEY for indexed files?

22. A company has 50,000 employees with sequential numeric IDs (1-50000). They need the fastest possible random access for payroll lookups. Should they use a KSDS or an RRDS? Justify your answer.

23. You are designing a hash table with 8,000 records. Calculate the minimum number of slots needed to achieve a load factor of 70% or less. What prime number would you use as the divisor in the division/remainder method?

24. Describe the GlobalBank "quick lookup table" pattern. What problem does it solve, and what are its trade-offs?

25. What is the difference between file status '14' and '23' on a relative file? Give an example scenario for each.

Code Analysis

26. Find the error in this code:

       FD  MY-RELATIVE-FILE.
       01  MY-REL-RECORD.
           05  REL-KEY         PIC 9(05).
           05  REL-DATA        PIC X(95).

       FILE-CONTROL.
           SELECT MY-RELATIVE-FILE
               ASSIGN TO MYREL
               ORGANIZATION IS RELATIVE
               ACCESS MODE IS RANDOM
               RELATIVE KEY IS REL-KEY
               FILE STATUS IS WS-REL-STATUS.

27. This hash function produces poor distribution. Why?

       COMPUTE-BAD-HASH.
           MOVE WS-KEY-VALUE TO WS-NUMERIC-KEY
           DIVIDE WS-NUMERIC-KEY BY 1000
               GIVING WS-QUOTIENT
               REMAINDER WS-HASH-REMAINDER
           ADD 1 TO WS-HASH-REMAINDER
           MOVE WS-HASH-REMAINDER TO WS-RELATIVE-KEY.

28. This collision-handling loop has a bug. What is it?

       FIND-SLOT.
           PERFORM COMPUTE-HASH
           PERFORM UNTIL WS-SLOT-FOUND
               READ REL-FILE
                   INVALID KEY
                       SET WS-SLOT-FOUND TO TRUE
                   NOT INVALID KEY
                       ADD 1 TO WS-RELATIVE-KEY
               END-READ
           END-PERFORM.

Answer Key

  1. b — Records are accessed by relative record number (slot position).
  2. c — The RELATIVE KEY must be in WORKING-STORAGE.
  3. c — RRDS is the VSAM relative record organization.
  4. a — A random READ on a relative file requires exactly 1 I/O (no index).
  5. b — NUMBERED is the IDCAMS keyword for RRDS.
  6. b — Status '23' means the slot is empty.
  7. b — Prime numbers produce more uniform remainder distributions.
  8. c — 67-77% is the recommended range for good performance.
  9. b — Quadratic probing uses squared offsets.
  10. b — Relative files have FASTER random access, not slower.
  11. False — RRDS does not support alternate keys.
  12. False — Relative record numbers start at 1.
  13. True — Sequential READ NEXT skips empty slots.
  14. True — DELETE on a relative file empties the slot at the VSAM level.
  15. True — READ before REWRITE is required for relative files, same as indexed.
  16. False — An RRDS has only a DATA component; there is no INDEX component.
  17. False — The RELATIVE KEY is in WORKING-STORAGE and is not stored in the record.
  18. True — Load factor = 3,000 / 10,000 = 30%.
  19. False — GnuCOBOL supports relative file organization.
  20. False — Hashing is only needed when the business key is not a sequential integer. Natural numeric keys can be used directly as RRNs.
  21. The RELATIVE KEY is in WORKING-STORAGE because the record number is a file-system concept (the slot position), not business data. It represents where the record IS, not what the record CONTAINS. In contrast, the RECORD KEY for indexed files is a field within the record because it is part of the business data — the key value is intrinsic to the record and stored with it.
  22. RRDS — because: (a) the employee IDs are natural sequential integers that map directly to slot numbers (no hashing needed), (b) the key space is dense (50,000 out of 50,000 slots = 100% occupancy), (c) RRDS gives 1 I/O per lookup vs. 3-4 for KSDS, and (d) no alternate access paths are mentioned. The only downside: if the company grows beyond 50,000 employees, the file must be redefined with more slots.
  23. Minimum slots = 8,000 / 0.70 = 11,429 slots. Round up to the nearest prime: 11,443 would work (or any prime >= 11,429). Use 11,443 as the divisor.
  24. The quick lookup pattern uses an RRDS as a fast cache for "hot" (frequently accessed) records from a KSDS master file. Before batch processing, a prep program loads the most-accessed records into the RRDS using a hash function. During processing, lookups try the RRDS first (1 I/O) and fall back to the KSDS only for cache misses. Trade-offs: requires extra disk space, cache rebuild overhead, potential for stale data between rebuilds, and hash collision management.
  25. Status '14' means the RRN is larger than the file's maximum slot number (the slot doesn't exist). Example: file has 1,000 slots and you request slot 1,500. Status '23' means the slot exists but is empty (no record has been written there). Example: file has 1,000 slots and you request slot 500, but no record was ever written to slot 500.
  26. The RELATIVE KEY (REL-KEY) is defined inside the FD record description. It must be in WORKING-STORAGE. The compiler will reject this because the RELATIVE KEY clause requires a data item that is NOT part of the record.
  27. The divisor 1000 is not a prime number. Specifically, 1000 = 2^3 * 5^3, which means keys that are multiples of 2, 5, 8, 10, 20, 25, etc. will cluster into the same slots. For example, all keys ending in 000 hash to slot 1, all keys ending in 500 hash to slot 501, etc. Using a prime like 997 would distribute much more uniformly.
  28. Two bugs: (a) There is no probe limit — if the file is full, this loops forever. (b) When WS-RELATIVE-KEY is incremented past the maximum slot number, it is not wrapped around to slot 1 (no wrap-around logic). The fix: add a probe counter with a maximum, and add IF WS-RELATIVE-KEY > WS-MAX-SLOTS MOVE 1 TO WS-RELATIVE-KEY.