Which of the following files can be OPENed in all the 4 modes? The four modes are INPUT, I-O, OUTPUT and EXTEND
-
INDEXED
-
RELATIVE
-
SEQUENTIAL
-
All of the above
In COBOL, all three file organizations (INDEXED, RELATIVE, and SEQUENTIAL) support all four open modes: INPUT (read-only), I-O (read/write), OUTPUT (write-new), and EXTEND (append).
The correct answer is 'All of the above'. The four OPEN modes are INPUT, OUTPUT, I-O, and EXTEND. While many tutorial sites simplify the rule to 'EXTEND is only for sequential files,' the authoritative IBM Enterprise COBOL for z/OS Language Reference documents that VSAM indexed (KSDS) and relative (RRDS) files can also be opened in EXTEND mode (a file must be open in OUTPUT, I-O, or EXTEND to add records). IBM's own 'Opening a file (ESDS, KSDS, or RRDS)' topic confirms EXTEND for all three organizations. Therefore sequential, indexed, and relative files can each be opened in all four modes, so 'All of the above' is the defensible technically-correct answer. The one caveat is that for EXTEND the file must be in sequential access mode and records added in ascending key/relative-key sequence.