Quiz — Chapter 22: CALL and Subprogram Linkage

Multiple Choice

1. What is the primary difference between a static CALL and a dynamic CALL?

A) Static CALL can pass parameters; dynamic CALL cannot B) Static CALL resolves the subprogram at link-edit time; dynamic CALL resolves it at runtime C) Static CALL uses GOBACK; dynamic CALL uses STOP RUN D) Static CALL is faster because it uses fewer parameters


2. Which statement should a subprogram use to return control to its caller?

A) STOP RUN B) EXIT PROGRAM or GOBACK C) RETURN D) END PROGRAM


3. What happens if a subprogram executes STOP RUN instead of GOBACK?

A) The subprogram returns to the caller normally B) The subprogram loops indefinitely C) The entire run unit terminates — the calling program never regains control D) A compile-time error occurs


4. In which section of a called program are the received parameters declared?

A) WORKING-STORAGE SECTION B) FILE SECTION C) LINKAGE SECTION D) LOCAL-STORAGE SECTION


5. How are parameters matched between the CALL USING clause and the PROCEDURE DIVISION USING clause?

A) By data item name B) By data type C) By position (first to first, second to second, etc.) D) By level number


6. What does the CANCEL statement do?

A) Terminates the calling program B) Releases a dynamically loaded subprogram from memory C) Deletes the load module from the library D) Prevents a subprogram from being called again


7. What ABEND code typically occurs when a dynamically called program cannot be found and no ON EXCEPTION clause is coded?

A) S0C4 B) S0C7 C) S806 D) S0CB


8. Which compiler option in IBM Enterprise COBOL controls whether CALL literal is treated as static or dynamic?

A) CALLOPT / NOCALLOPT B) DYNAM / NODYNAM C) STATIC / DYNAMIC D) LINK / NOLINK


9. Why should copybooks be used for subprogram interface definitions?

A) They improve compilation speed B) They guarantee that calling and called programs use identical parameter layouts C) They are required by the COBOL standard D) They enable static CALL


10. After a CANCEL and subsequent re-CALL of a subprogram, what is the state of the subprogram's WORKING-STORAGE?

A) It retains values from the previous invocation B) It is in its initial state (as defined by VALUE clauses) C) All items are set to spaces D) All items are set to zeros


True or False

11. A CALL using a data item (identifier) is always treated as a dynamic CALL, regardless of compiler options.

12. LINKAGE SECTION items allocate storage in the called program.

13. The ON EXCEPTION clause is meaningful for both static and dynamic CALL statements.

14. A subprogram can call other subprograms (nested calls are allowed).

15. VALUE clauses are prohibited in the LINKAGE SECTION (except for level 88 condition names).


Short Answer

16. Explain the difference between a load module and an object module in the COBOL build pipeline.

17. A developer reports that a subprogram works correctly when tested standalone but produces incorrect results when called from a production program. The return code is always 0 (success), but the output data is garbled. List three possible causes and how you would diagnose each.

18. Describe a scenario where dynamic CALL would be clearly preferable to static CALL. Explain your reasoning.

19. What is a "storage overlay" in the context of CALL parameter passing? How does it occur, and how can it be prevented?

20. Write the CALL statement, LINKAGE SECTION, and PROCEDURE DIVISION USING clause for a subprogram that accepts an employee ID (PIC X(8)), a pay rate (PIC S9(5)V99 COMP-3), and returns a formatted name (PIC X(30)) and a return code (PIC S9(4) COMP).


Answer Key

1. B — Static CALL resolves at link-edit time; dynamic CALL resolves at runtime.

2. B — EXIT PROGRAM or GOBACK returns control to the caller.

3. C — STOP RUN terminates the entire run unit.

4. C — LINKAGE SECTION.

5. C — Parameters are matched positionally.

6. B — CANCEL releases a dynamically loaded subprogram from memory.

7. C — S806 is the typical ABEND for program-not-found.

8. B — DYNAM / NODYNAM controls static vs. dynamic literal CALL.

9. B — Copybooks guarantee identical parameter layouts.

10. B — WORKING-STORAGE returns to its initial state after CANCEL.

11. True — A CALL using an identifier is always dynamic.

12. False — LINKAGE SECTION items describe the layout of storage owned by the caller; they do not allocate new storage.

13. False — ON EXCEPTION is only meaningful for dynamic CALL. For static CALL, resolution happens at link-edit time.

14. True — Subprograms can call other subprograms, creating a call chain.

15. True — VALUE clauses are not permitted in LINKAGE SECTION except for level 88 condition names.

16. An object module is the output of the COBOL compiler — it contains machine code but with unresolved external references. A load module is the output of the linkage editor (binder) — it is a fully resolved, executable program ready to be loaded into memory by the operating system. The linkage editor resolves external references by combining object modules.

17. Three possible causes: (1) Parameter order mismatch — the CALL USING lists parameters in a different order than the PROCEDURE DIVISION USING; diagnose by comparing the copybooks or parameter lists side by side. (2) Parameter size mismatch — the caller defines a field as PIC X(10) but the subprogram expects PIC X(20), causing storage overlay; diagnose by comparing data item sizes in both programs. (3) Stale load module — the subprogram was recompiled but the caller was not relinked (for static CALL), so it is using an old version with a different interface; diagnose by checking compile timestamps.

18. A date validation routine used by 50+ programs across the system. Dynamic CALL allows deploying an updated validation module once, and all 50 callers automatically use the new version on their next execution. With static CALL, all 50 callers would need to be relinked. Additionally, if the routine is large and not all callers need it in every run, dynamic CALL saves memory by loading it only when needed.

19. A storage overlay occurs when a called program writes beyond the bounds of a parameter's actual storage. For example, if the caller passes a PIC X(10) field but the subprogram's LINKAGE SECTION declares it as PIC X(50) and writes 50 bytes, the extra 40 bytes overwrite whatever storage follows the parameter in the caller's memory. This can corrupt other data items, leading to unpredictable results or ABENDs later in execution. Prevention: always use shared copybooks for interface definitions.

20.

* In the calling program:
CALL 'EMPFMT' USING WS-EMP-ID
                    WS-PAY-RATE
                    WS-FORMATTED-NAME
                    WS-RETURN-CODE

* In the called program (EMPFMT):
LINKAGE SECTION.
01  LS-EMP-ID           PIC X(8).
01  LS-PAY-RATE         PIC S9(5)V99 COMP-3.
01  LS-FORMATTED-NAME   PIC X(30).
01  LS-RETURN-CODE      PIC S9(4) COMP.

PROCEDURE DIVISION USING LS-EMP-ID
                         LS-PAY-RATE
                         LS-FORMATTED-NAME
                         LS-RETURN-CODE.