Quiz — Chapter 9: Copybooks and Code Reuse

Multiple Choice

1. What does the COPY statement do at compile time?

a) Calls a subroutine stored in the copybook library b) Inserts the text of the copybook into the source program c) Creates a link to the copybook that is resolved at runtime d) Compiles the copybook as a separate module

2. Which of the following is the correct syntax for pseudo-text replacement?

a) COPY ACCT-REC REPLACING :PREFIX: WITH ACCT. b) COPY ACCT-REC REPLACING ==:PREFIX:== BY ==ACCT==. c) COPY ACCT-REC SUBSTITUTING ':PREFIX:' FOR 'ACCT'. d) COPY ACCT-REC CHANGING ==:PREFIX:== TO ==ACCT==.

3. On z/OS, where are copybooks typically stored?

a) In the PROCEDURE library b) In VSAM KSDS files c) As members of a Partitioned Data Set (PDS) d) In the SYSIN input stream

4. When the REPLACING phrase is used with a nested COPY, the replacement applies to:

a) The immediately copied copybook text only b) All nested copybooks automatically c) Only the innermost nested copybook d) All levels of nesting, recursively

5. What is the primary purpose of FILLER bytes at the end of a record layout copybook?

a) To improve I/O performance through alignment b) To allow future field additions without changing the record length c) To satisfy COBOL syntax requirements for 01-level items d) To provide space for error messages

6. Which of the following is NOT a valid location for a COPY statement?

a) ENVIRONMENT DIVISION (FILE-CONTROL paragraph) b) DATA DIVISION (WORKING-STORAGE SECTION) c) In the middle of a MOVE statement d) PROCEDURE DIVISION (inside a paragraph)

7. What convention makes REPLACING tokens visually distinctive in a copybook?

a) Using all uppercase letters b) Using colon delimiters like :PREFIX: c) Prefixing with CB- for copybook d) Using numeric suffixes like FIELD-01

8. When multiple libraries are concatenated in SYSLIB, and the same copybook name exists in two libraries, which version does the compiler use?

a) The newest version by date b) The version in the first library in the concatenation order c) The version in the last library in the concatenation order d) The compiler reports an error

9. What is a "shadow copybook" problem?

a) A copybook that is never referenced by any program b) A copybook with an empty body c) The same copybook name existing in multiple libraries, causing the wrong version to be used d) A copybook that contains only comments

10. Which naming convention pattern would be MOST helpful for identifying a copybook that contains a record layout for a transaction file?

a) COPYBOOK1 b) TXN-REC or REC-TXN c) FILE01 d) TRANSACTION-RECORD-LAYOUT-DEFINITION

True/False

11. The COPY statement can appear in any division of a COBOL program. True / False

12. Pseudo-text replacement (==...==) can match partial words within data names. True / False

13. Identifier replacement in REPLACING matches partial words. True / False

14. A copybook must always begin at the 01 level. True / False

15. On z/OS, PDS member names for copybooks are limited to 8 characters. True / False

Short Answer

16. Explain the difference between pseudo-text replacement and identifier replacement in the REPLACING phrase. When would you choose one over the other?

17. Describe two strategies for handling copybook versioning when a record layout needs to change.

18. Why do production COBOL shops use paragraph library copybooks? What are the risks?

19. A program compiles successfully but produces incorrect results. You discover it was compiled against the wrong version of a copybook because the SYSLIB concatenation was incorrect. How would you detect and prevent this in the future?

20. Explain how copybooks serve as "interface definitions" in the context of modernization, similar to how APIs work in modern systems.


Answer Key

  1. b — The COPY statement inserts text at compile time.
  2. b — Pseudo-text uses ==...== delimiters and the BY keyword.
  3. c — Copybooks are PDS members on z/OS.
  4. a — REPLACING applies only to the immediately copied text.
  5. b — FILLER allows future expansion without record length changes.
  6. c — COPY cannot appear inside a statement.
  7. b — Colons make tokens visually distinct and unmatchable.
  8. b — The first library in concatenation order wins.
  9. c — Shadow copybooks cause wrong-version compilation.
  10. b — Encodes both the type (REC) and subject (TXN).
  11. True — COPY can appear in ENVIRONMENT, DATA, or PROCEDURE divisions.
  12. True — Pseudo-text matches character-for-character, including partial words.
  13. False — Identifier replacement only matches complete words.
  14. False — Copybooks can contain entries at any level.
  15. True — PDS members have an 8-character name limit.