Chapter 12 Quiz: Indexed File Processing (VSAM KSDS)

Test your understanding of VSAM KSDS indexed file processing in COBOL. Each question has one correct answer. Try to answer before revealing the solution.


Question 1

What does ORGANIZATION IS INDEXED in the SELECT clause specify?

A) The file is a sequential file with an index B) The file is a VSAM KSDS (or equivalent indexed file) with key-based access C) The file uses relative record numbers for access D) The file has records sorted in descending order

Answer **B) The file is a VSAM KSDS (or equivalent indexed file) with key-based access** `ORGANIZATION IS INDEXED` tells the COBOL runtime that the file supports direct access by a primary key field. On z/OS, this maps to a VSAM KSDS. On GnuCOBOL, it maps to the configured indexed file backend (Berkeley DB, VBISAM, etc.).

Question 2

Which ACCESS MODE allows both random READ and sequential READ NEXT in the same program?

A) SEQUENTIAL B) RANDOM C) DYNAMIC D) INDEXED

Answer **C) DYNAMIC** ACCESS MODE IS DYNAMIC allows both random operations (READ file-name) and sequential operations (READ file-name NEXT, START) in the same program. This is the most flexible access mode.

Question 3

What file status code indicates "record not found"?

A) 10 B) 21 C) 22 D) 23

Answer **D) 23** File status 23 means the record with the specified key was not found. This is returned by READ (random), START, and DELETE when no matching record exists. Status 10 is end of file, 21 is key sequence error, and 22 is duplicate primary key.

Question 4

What is the correct sequence for updating a record in a VSAM KSDS?

A) REWRITE, then READ B) MOVE key, REWRITE C) READ, modify fields, REWRITE D) DELETE, then WRITE

Answer **C) READ, modify fields, REWRITE** REWRITE requires a prior successful READ of the record to be updated. The sequence is: (1) READ the record to establish the current position, (2) modify the desired fields in the record area, (3) REWRITE the modified record. Attempting REWRITE without a prior READ results in file status 43.

Question 5

What does file status '02' indicate?

A) An error occurred during the I/O operation B) The file is empty C) The operation succeeded but a duplicate alternate key value exists D) Two records were read simultaneously

Answer **C) The operation succeeded but a duplicate alternate key value exists** Status 02 is a successful completion code. It occurs when a WRITE or REWRITE creates a record whose alternate key value already exists in the file (for an alternate key defined WITH DUPLICATES). Programs should treat 02 as success, not as an error.

Question 6

Which OPEN mode is required for REWRITE and DELETE operations?

A) INPUT B) OUTPUT C) I-O D) EXTEND

Answer **C) I-O** OPEN I-O is required for REWRITE and DELETE operations because these modify existing data. OPEN INPUT allows only reading, OPEN OUTPUT allows only writing new records, and OPEN EXTEND allows only appending.

Question 7

What does the START statement do?

A) Opens the file for processing B) Reads the first record in the file C) Positions the file pointer without reading a record D) Initializes the file for random access

Answer **C) Positions the file pointer without reading a record** START positions the file pointer at a record matching the specified key condition (EQUAL TO, GREATER THAN, NOT LESS THAN) without actually reading a record. A subsequent READ or READ NEXT retrieves the record at the positioned location.

Question 8

In the IDCAMS DEFINE CLUSTER command, what does KEYS(10 0) specify?

A) 10 keys starting at record 0 B) A 10-byte primary key starting at byte offset 0 C) 10 index levels at position 0 D) 10% key compression at level 0

Answer **B) A 10-byte primary key starting at byte offset 0** The KEYS parameter in DEFINE CLUSTER specifies the length and offset of the primary key within the record. KEYS(10 0) means the key is 10 bytes long and starts at the beginning of the record (offset 0).

Question 9

What happens if you WRITE a record with a key that already exists in the KSDS?

A) The existing record is replaced B) The new record is appended after the existing one C) File status 22 is returned and the write fails D) File status 02 is returned and the write succeeds

Answer **C) File status 22 is returned and the write fails** A VSAM KSDS does not allow duplicate primary keys. If you attempt to WRITE a record whose primary key already exists, the operation fails with file status 22 (duplicate primary key) and the INVALID KEY clause executes. To change an existing record, use READ followed by REWRITE.

Question 10

What is a VSAM control interval (CI)?

A) The time between I/O operations B) The unit of data transfer between disk and memory C) The maximum number of records in the file D) The frequency of index updates

Answer **B) The unit of data transfer between disk and memory** A control interval (CI) is the basic unit of I/O for VSAM. Each CI contains one or more records plus VSAM control information. When VSAM reads or writes data, it transfers entire CIs between disk and memory buffers. Typical CI sizes range from 2,048 to 32,768 bytes.

Question 11

Which IDCAMS command builds an alternate index from existing base cluster data?

A) DEFINE ALTERNATEINDEX B) DEFINE PATH C) BLDINDEX D) REPRO

Answer **C) BLDINDEX** BLDINDEX reads all records from the base cluster and creates the corresponding alternate index entries. DEFINE ALTERNATEINDEX creates the AIX structure but does not populate it. DEFINE PATH creates the logical connection between AIX and base. REPRO copies data between data sets but does not build indexes.

Question 12

What does FREESPACE(20 10) specify in a DEFINE CLUSTER?

A) 20 bytes free in each record, 10 bytes in each CI B) 20% of each CI and 10% of CAs left free for inserts C) 20 free CIs and 10 free CAs D) 20% of disk space and 10% of memory reserved

Answer **B) 20% of each CI and 10% of CAs left free for inserts** FREESPACE(ci-percent ca-percent) specifies the percentage of each control interval left empty during initial load (for future inserts) and the percentage of control areas left entirely empty. This free space helps prevent CI and CA splits when new records are inserted.

Question 13

In ACCESS MODE IS RANDOM, which statement adds a new record to an existing KSDS opened for I-O?

A) WRITE B) REWRITE C) INSERT D) ADD

Answer **A) WRITE** In ACCESS MODE IS RANDOM with OPEN I-O, the WRITE statement adds new records to the KSDS. Records can be added in any key order (unlike sequential access mode, which requires ascending key order). REWRITE only modifies existing records. INSERT and ADD are not valid COBOL I/O verbs.

Question 14

Why do VSAM files not need DCB parameters in JCL DD statements?

A) VSAM files are always in memory B) VSAM gets its attributes from the VSAM catalog, not JCL C) DCB parameters are only for tape files D) The COBOL program provides all attributes

Answer **B) VSAM gets its attributes from the VSAM catalog, not JCL** When you DEFINE CLUSTER via IDCAMS, all file attributes (record size, key position, CI size, etc.) are stored in the VSAM catalog. The JCL DD statement only needs the data set name and disposition. There is no DCB, SPACE, or RECFM needed.

Question 15

What is the difference between READ CUSTOMER-MASTER and READ CUSTOMER-MASTER NEXT in ACCESS MODE IS DYNAMIC?

A) No difference; they are identical B) READ performs a random read by key; READ NEXT performs a sequential read of the next record C) READ reads one record; READ NEXT reads all remaining records D) READ is for input; READ NEXT is for output

Answer **B) READ performs a random read by key; READ NEXT performs a sequential read of the next record** In dynamic access mode, the presence or absence of the NEXT keyword determines the type of access. `READ file-name` (without NEXT) performs a random read using the current value in the RECORD KEY field. `READ file-name NEXT` performs a sequential read of the next record in key order from the current position.

Question 16

What does the WITH DUPLICATES clause mean on an ALTERNATE RECORD KEY?

A) The alternate key allows multiple records with the same alternate key value B) The records are stored in duplicate C) Two alternate indexes share the same structure D) The alternate key must match the primary key

Answer **A) The alternate key allows multiple records with the same alternate key value** WITH DUPLICATES means the alternate key is non-unique -- multiple records can have the same value for that alternate key field. For example, multiple customers may share the same last name. Without WITH DUPLICATES, the alternate key must be unique (like SSN), and attempting to add a duplicate would result in an error.

Question 17

What file status code indicates a key sequence error during sequential WRITE?

A) 10 B) 21 C) 22 D) 24

Answer **B) 21** File status 21 occurs when writing records in ACCESS MODE IS SEQUENTIAL and the new record's key is not greater than the previous record's key. Sequential writes to a KSDS must be in ascending key order. Status 22 is for duplicate keys, 10 is end of file, and 24 is key boundary violation.

Question 18

What is the purpose of the IDCAMS DEFINE PATH command?

A) It creates a directory for VSAM files B) It creates a logical connection between an alternate index and its base cluster C) It defines the physical storage path on disk D) It sets up the network path for remote VSAM access

Answer **B) It creates a logical connection between an alternate index and its base cluster** DEFINE PATH creates a named object that connects an alternate index to its base cluster. When a COBOL program opens a file with alternate keys, the JCL includes DD statements for both the base cluster and each PATH. The PATH allows VSAM to route alternate key requests through the AIX to the base cluster.

Question 19

Which SHAREOPTIONS value is most appropriate for a file that is read by multiple programs but updated by only one batch job at a time?

A) SHAREOPTIONS(1 3) B) SHAREOPTIONS(2 3) C) SHAREOPTIONS(3 3) D) SHAREOPTIONS(4 3)

Answer **B) SHAREOPTIONS(2 3)** SHAREOPTIONS(2 3) provides cross-region share option 2 (multiple readers OR one writer) and cross-system share option 3. This is the most common choice for files that are read concurrently by multiple programs but updated exclusively by one program at a time. Option 1 is fully exclusive, option 3 allows concurrent updates (with risk), and option 4 provides direct buffered access.

Question 20

What happens during a CI split?

A) The control interval is deleted B) Records are redistributed between the original CI and a new CI within the same CA C) The entire file is reorganized D) The index is rebuilt from scratch

Answer **B) Records are redistributed between the original CI and a new CI within the same CA** When a new record needs to be inserted into a CI that is full, VSAM performs a CI split: approximately half the records remain in the original CI, and the other half move to a new CI obtained from free space within the same control area. The index is updated to reflect the new record locations. Excessive CI splits degrade performance.

Question 21

In the JCL for a COBOL program using a VSAM file with alternate keys, how are the PATH DD statements specified?

A) Each PATH has its own separately named DD statement B) PATH DDs are concatenated under the base cluster DD statement C) PATH DDs are not needed; VSAM handles it automatically D) PATH DDs go in a separate step

Answer **B) PATH DDs are concatenated under the base cluster DD statement** The JCL concatenates the base cluster DD with the PATH DDs in the order matching the ALTERNATE RECORD KEY clauses in the SELECT statement:
//CUSTMAST DD DSN=base.cluster,DISP=SHR
//         DD DSN=base.cluster.path.ssn,DISP=SHR
//         DD DSN=base.cluster.path.name,DISP=SHR

Question 22

Which IDCAMS command would you use to back up a VSAM KSDS to a sequential file?

A) EXPORT B) REPRO C) PRINT D) COPY

Answer **B) REPRO** REPRO copies records from one data set to another. `REPRO INFILE(vsamdd) OUTFILE(seqdd)` copies all records from the VSAM KSDS to a sequential file, creating a backup that can be used to reload the KSDS if needed. EXPORT also backs up but includes catalog information; REPRO is more commonly used for data-only backups.

Question 23

What must be true about the RECORD KEY field in a COBOL program?

A) It must be defined in WORKING-STORAGE B) It must be defined within the record description under the FD C) It must be a numeric field D) It must be the first field in the record

Answer **B) It must be defined within the record description under the FD** The RECORD KEY data-name must be defined as a field within the 01-level record description under the file's FD entry. It does not have to be the first field (though it commonly is), and it can be alphanumeric or numeric. The offset and length of this field must match the KEYS parameter in the VSAM DEFINE CLUSTER.

Question 24

When opening a VSAM KSDS for initial load, which combination of OPEN mode and ACCESS MODE is typical?

A) OPEN INPUT, ACCESS MODE IS SEQUENTIAL B) OPEN OUTPUT, ACCESS MODE IS SEQUENTIAL C) OPEN I-O, ACCESS MODE IS RANDOM D) OPEN EXTEND, ACCESS MODE IS DYNAMIC

Answer **B) OPEN OUTPUT, ACCESS MODE IS SEQUENTIAL** Initial loading of a KSDS typically uses OPEN OUTPUT (write-only, creates new data) with ACCESS MODE IS SEQUENTIAL (records must be written in ascending key order). This is the most efficient way to load a KSDS because VSAM can optimize the sequential write pattern. After loading, programs typically open the file for I-O with RANDOM or DYNAMIC access.

Question 25

What is the IDCAMS VERIFY command used for?

A) Verifying that all records have valid key values B) Checking the program's SELECT clause against the file's catalog entry C) Correcting the catalog's end-of-data information after an abnormal termination D) Validating the free space percentages

Answer **C) Correcting the catalog's end-of-data information after an abnormal termination** If a program abends while a VSAM file is open, the end-of-data (high-used RBA) information in the VSAM catalog may be incorrect. VERIFY reads the actual data and corrects the catalog entry. It is often included as a standard step before critical batch processing to ensure file integrity.

Question 26

Which of the following is NOT a valid START condition?

A) KEY IS EQUAL TO B) KEY IS GREATER THAN C) KEY IS NOT LESS THAN D) KEY IS LESS THAN

Answer **D) KEY IS LESS THAN** The START statement supports EQUAL TO, GREATER THAN, NOT LESS THAN (same as GREATER THAN OR EQUAL TO), and their equivalents. It does not support LESS THAN because START positions for forward sequential reading -- there is no concept of reading backward. To read records below a certain key, you would START at the beginning and read forward until reaching the threshold.

Question 27

A COBOL program writes a record to a KSDS and receives file status '02'. What should the program do?

A) Abort with an error B) Retry the write operation C) Treat it as a successful write and continue D) Delete the duplicate record and retry

Answer **C) Treat it as a successful write and continue** File status 02 means the write was successful, but a duplicate value was created in a non-unique alternate key. The record was written to the base cluster; the 02 status is informational. The program should treat 02 (along with 00) as a success condition. It may optionally log or count the occurrence of duplicate alternate keys.

Question 28

What is the effect of the UPGRADE parameter on a DEFINE ALTERNATEINDEX command?

A) It upgrades the AIX to the latest VSAM version B) It automatically keeps the AIX synchronized when the base cluster is modified C) It improves the performance of the AIX D) It allows the AIX to be used with newer COBOL compilers

Answer **B) It automatically keeps the AIX synchronized when the base cluster is modified** UPGRADE means that whenever a record is added, updated, or deleted in the base cluster, VSAM automatically updates the alternate index to reflect the change. Without UPGRADE, the AIX becomes stale and must be manually rebuilt with BLDINDEX. UPGRADE adds overhead to write operations but ensures the AIX is always current.

Question 29

In ACCESS MODE IS SEQUENTIAL, can you delete a record without first reading it?

A) Yes, just move the key and issue DELETE B) No, you must READ the record before you can DELETE it in sequential mode C) Yes, but only if the file is opened for EXTEND D) No, DELETE is not allowed in sequential mode

Answer **B) No, you must READ the record before you can DELETE it in sequential mode** In ACCESS MODE IS SEQUENTIAL, DELETE removes the record most recently read. A prior successful READ is required. If you need to delete by key without a prior read, use ACCESS MODE IS RANDOM or DYNAMIC, where you can move the key value and issue DELETE directly.

Question 30

A VSAM KSDS has a CI size of 4096 bytes and fixed-length records of 200 bytes. Approximately how many records fit in one CI (ignoring VSAM control fields for simplicity)?

A) 5 B) 10 C) 20 D) 40

Answer **C) 20** 4096 / 200 = 20.48, so approximately 20 records per CI. In practice, VSAM reserves some bytes in each CI for control information (typically 7-10 bytes for CIDF and RDF entries), so the actual number would be slightly fewer. But for a rough estimate, dividing CI size by record size gives the approximate capacity. This calculation is useful for estimating how many I/O operations are needed to read a given number of records.