Quiz — Chapter 12: Indexed File Processing (VSAM KSDS)
Multiple Choice
1. What is a Control Interval (CI) in VSAM?
a) A time-based scheduling unit for I/O operations b) The smallest unit of data transferred between disk and memory c) A logical grouping of related records by key range d) An index entry pointing to a data record
2. Which VSAM data set type is used for key-sequenced indexed access?
a) ESDS (Entry-Sequenced Data Set) b) RRDS (Relative Record Data Set) c) KSDS (Key-Sequenced Data Set) d) LDS (Linear Data Set)
3. In the SELECT statement, which ACCESS MODE allows both random and sequential access in the same program?
a) SEQUENTIAL b) RANDOM c) INDEXED d) DYNAMIC
4. What file status code indicates "record not found"?
a) '10' b) '22' c) '23' d) '35'
5. Which statement is required before a REWRITE on an indexed file?
a) START b) OPEN I-O c) READ (of the same record) d) Both b and c
6. What does the WITH DUPLICATES clause on ALTERNATE RECORD KEY mean?
a) The primary key can have duplicate values b) Multiple records can have the same alternate key value c) The file can have duplicate records d) The alternate index allows duplicate index entries
7. A CI split occurs when:
a) The file is reorganized b) A new record must be inserted into a full CI c) The index is rebuilt d) Two programs access the file simultaneously
8. What file status code indicates a successful write where a duplicate alternate key value already exists?
a) '00' b) '02' c) '22' d) '21'
9. In the IDCAMS DEFINE CLUSTER command, what does FREESPACE(20 10) specify?
a) 20% of disk space reserved, 10% for index b) 20% free space per CI, 10% free CIs per CA c) 20 bytes free per record, 10 bytes for the key d) 20% for data, 10% for the index component
10. Which COBOL statement positions an indexed file at a specific key value for subsequent sequential reading?
a) SEEK b) POSITION c) START d) SET
True or False
11. You can change the primary key value of a record using REWRITE.
12. The DELETE statement in RANDOM access mode requires a prior READ of the record.
13. A VSAM KSDS file must be defined via IDCAMS before a COBOL program can use it on a mainframe.
14. Status code '10' indicates a permanent I/O error.
15. In sequential access mode, records must be written in ascending key order.
16. The BUFND parameter controls the number of index buffers for a VSAM file.
17. A generic key START allows you to position at records with a matching key prefix.
18. GnuCOBOL requires IDCAMS to define indexed files.
19. Status code '02' represents a failure condition that should trigger error handling.
20. VSAM alternate indexes with the UPGRADE option are automatically maintained when the base cluster changes.
Short Answer
21. Explain the difference between a CI split and a CA split. Which is more expensive, and why?
22. Write the SELECT statement for an indexed file called EMPLOYEE-FILE with: - External name EMPFILE - Dynamic access mode - Primary key EMPLOYEE-ID - Alternate key EMPLOYEE-DEPT with duplicates - File status field WS-EMP-STATUS
23. Why is "logical delete" (setting a status field to 'closed') preferred over physical DELETE in banking systems?
24. Describe the steps VSAM performs when a program issues a random READ on a KSDS file. How many disk I/Os are typically involved?
25. A program receives file status '39' on OPEN. What does this mean, and what should you check?
Code Analysis
26. Find the bug in this code:
UPDATE-BALANCE.
MOVE WS-ACCT-NUM TO AM-ACCT-NUMBER
ADD WS-DEPOSIT-AMT TO AM-BALANCE
REWRITE ACCT-MASTER-RECORD
INVALID KEY
DISPLAY 'REWRITE ERROR'
END-REWRITE.
27. What is wrong with this status-checking approach?
READ ACCT-MASTER-FILE
END-READ
IF WS-ACCT-STATUS NOT = '00'
DISPLAY 'ERROR: ' WS-ACCT-STATUS
STOP RUN
END-IF
PERFORM PROCESS-ACCOUNT.
28. This program compiles but produces incorrect results when browsing. Why?
BROWSE-ALL.
OPEN INPUT ACCT-MASTER-FILE
PERFORM UNTIL WS-EOF
READ ACCT-MASTER-FILE NEXT
AT END
SET WS-EOF TO TRUE
END-READ
IF NOT WS-EOF
DISPLAY AM-ACCT-NUMBER ' ' AM-BALANCE
END-IF
END-PERFORM
CLOSE ACCT-MASTER-FILE.
Answer Key
- b — The CI is the smallest unit of data transfer between disk and memory.
- c — KSDS is the key-sequenced data set type.
- d — DYNAMIC access mode allows both random and sequential access.
- c — Status '23' means record not found.
- d — Both OPEN I-O and a prior READ are required for REWRITE.
- b — Multiple records can share the same alternate key value.
- b — A CI split occurs when inserting into a full CI.
- b — Status '02' indicates success with a duplicate alternate key.
- b — 20% free space per CI, 10% free CIs per CA.
- c — START positions the file at a key value.
- False — You cannot change the primary key on REWRITE. You must DELETE and WRITE.
- False — In RANDOM mode, DELETE can be performed by key without a prior READ.
- True — VSAM clusters must be defined before use on a mainframe.
- False — Status '10' is end of file. Status '30' is a permanent I/O error.
- True — Sequential access mode requires ascending key order for writes.
- False — BUFND controls data buffers. BUFNI controls index buffers.
- True — Generic key START matches on a key prefix.
- False — GnuCOBOL creates indexed files automatically on first OPEN OUTPUT.
- False — Status '02' is a successful completion indicating a non-unique alternate key was written.
- True — UPGRADE alternate indexes are automatically maintained.
- A CI split moves half the records from a full CI to a free CI within the same CA. A CA split allocates a new CA and redistributes CIs between the old and new CAs. CA splits are more expensive because they involve more data movement, may require extending the file, and cause index updates at multiple levels. 22.
SELECT EMPLOYEE-FILE
ASSIGN TO EMPFILE
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS EMPLOYEE-ID
ALTERNATE RECORD KEY IS EMPLOYEE-DEPT
WITH DUPLICATES
FILE STATUS IS WS-EMP-STATUS.
- Logical deletes preserve audit trails (regulators require transaction history), simplify recovery (if a deletion was a mistake, the data is still there), and avoid the overhead and risk of physical file reorganization. Banking regulations often require data retention for 7+ years.
- VSAM searches the index set (1-2 levels, 1-2 I/Os), then the sequence set (1 I/O), then reads the data CI (1 I/O). Typically 3-4 disk I/Os total, though index buffers can eliminate the index I/Os if the index is cached.
- Status '39' means the file's attributes (record size, key position, key length, organization) as defined in the COBOL program do not match the actual VSAM cluster definition. Check that the RECORD KEY position and length, RECORDSIZE, and ORGANIZATION match between the COBOL program and the IDCAMS definition.
- The code does not READ the record before the REWRITE. It moves the key, then directly modifies AM-BALANCE (which contains whatever was previously in the buffer, not the current record), and then REWRITEs. The fix: READ the record first, then ADD, then REWRITE.
- Two problems: (a) Status '10' (end of file) would cause the program to STOP RUN instead of being handled as a normal condition. (b) Status '02' (duplicate alternate key success) would also trigger the error path. The check should be:
IF WS-ACCT-STATUS NOT = '00' AND WS-ACCT-STATUS NOT = '02' AND WS-ACCT-STATUS NOT = '10'. - The program does not issue a START before the first READ NEXT. Without START, the file position is undefined, and the program may skip records or start from an unpredictable position. Fix: Add
MOVE LOW-VALUES TO AM-ACCT-NUMBERandSTART ACCT-MASTER-FILE KEY IS NOT LESS THAN AM-ACCT-NUMBERbefore the PERFORM loop. Also, the SELECT must specify ACCESS MODE IS DYNAMIC or SEQUENTIAL.