Quiz — Chapter 10: Defensive Programming

Multiple Choice

1. What FILE STATUS code indicates a successful I/O operation?

a) '01' b) '00' c) 'OK' d) '99'

2. Which FILE STATUS code indicates end-of-file on a READ operation?

a) '00' b) '10' c) '23' d) '99'

3. What does FILE STATUS '35' indicate on an OPEN operation?

a) File is locked by another process b) File attributes conflict with FD c) File not found d) File already open

4. When does ON SIZE ERROR trigger?

a) When any decimal truncation occurs b) When the integer portion of the result exceeds the receiving field, or on divide by zero c) When the receiving field is alphanumeric d) Only on divide by zero

5. Which statement is true about DECLARATIVES?

a) They must appear at the end of the PROCEDURE DIVISION b) They fire before an unsuccessful I/O operation c) They must appear at the beginning of the PROCEDURE DIVISION, before other sections d) They can only be used with indexed files

6. What is the standard industry convention for a return code of 8?

a) Success b) Warning c) Error d) Fatal

7. What is the NUMERIC class test used for?

a) Checking if a field contains only alphabetic characters b) Checking if a field contains valid numeric data for its usage c) Counting the number of digits in a field d) Converting alphanumeric to numeric

8. In the error threshold pattern, what does the "consecutive error counter" detect?

a) The total number of errors in the run b) Errors that occur in the same paragraph c) Multiple errors in a row, suggesting a systemic problem d) Errors on the same file

9. Which approach does Maria Chen at GlobalBank prefer for error handling?

a) DECLARATIVES only b) Inline FILE STATUS only c) DECLARATIVES as safety net, inline checking for expected conditions d) No error handling — let the system ABEND

10. What should a program do when it encounters an unrecoverable error?

a) Continue processing and ignore the error b) ABEND immediately without any cleanup c) Log the error, close all files, set a fatal return code, and STOP RUN d) Retry the operation indefinitely

True/False

11. ON SIZE ERROR detects truncation of decimal places. True / False

12. FILE STATUS should be checked after CLOSE operations. True / False

13. The INVALID KEY phrase applies only to indexed and relative file operations. True / False

14. A FILE STATUS variable must be defined as PIC XX (two characters). True / False

15. DECLARATIVES fire for all I/O errors, including AT END conditions. True / False

16. On z/OS, an unclosed VSAM file may require manual VERIFY before it can be accessed again. True / False

17. The RETURN-CODE special register can hold values larger than 16. True / False

18. Using both FILE STATUS checking and INVALID KEY in the same program is redundant and should be avoided. True / False

Short Answer

19. Explain why checking FILE STATUS after OPEN is especially important. What are three common status codes that indicate OPEN failure, and what does each mean?

20. Describe the difference between the "error threshold pattern" and the "bypass pattern." When would you use each?

21. A program processes 1 million records. The developer defined the record counter as PIC 9(5). What will happen, and how should this be prevented?

22. Write the WORKING-STORAGE entries and a validation paragraph that checks whether a date field (PIC 9(8) in YYYYMMDD format) represents a valid date, including leap year checking for February.

23. Explain why James Okafor insists on validating input data before performing arithmetic on it. What specific ABEND can occur on z/OS when arithmetic is performed on non-numeric data?


Answer Key

  1. b — '00' indicates success.
  2. b — '10' indicates end of file.
  3. c — '35' means file not found.
  4. b — SIZE ERROR fires on integer overflow or divide by zero, not decimal truncation.
  5. c — DECLARATIVES appear at the beginning of the PROCEDURE DIVISION.
  6. c — 8 typically means error.
  7. b — NUMERIC checks for valid numeric data based on field's USAGE.
  8. c — Consecutive errors suggest systemic problems like wrong file format.
  9. c — Hybrid approach: DECLARATIVES as safety net plus inline checking.
  10. c — Orderly shutdown: log, close, set RC, stop.
  11. False — ON SIZE ERROR only detects integer overflow, not decimal truncation.
  12. True — A failed CLOSE may mean data was not fully flushed.
  13. True — INVALID KEY is for indexed and relative file operations.
  14. True — FILE STATUS requires a two-character alphanumeric field.
  15. False — DECLARATIVES with USE AFTER ERROR fire on permanent errors (30+), not AT END.
  16. True — Unclosed VSAM files enter a "not properly closed" state.
  17. True — RETURN-CODE can hold any value that fits its implementation (typically S9(4) COMP).
  18. False — Using both is a valid belt-and-suspenders approach; many shops do this.