Key Takeaways — Chapter 23: Parameter Passing Patterns
The Three Modes
-
BY REFERENCE (default) passes the address of the caller's data. The called program directly accesses and can modify the caller's storage. Use for output parameters and bidirectional communication.
-
BY CONTENT passes the address of a temporary copy. The caller's data is protected — any modifications affect only the copy. Use for input parameters that must be preserved, and for passing literals.
-
BY VALUE passes the actual value (not an address). Restricted to elementary binary, float, and pointer items. Use primarily for interoperability with C and other non-COBOL languages.
Safety Patterns
-
Use BY CONTENT for inputs and BY REFERENCE for outputs to make data flow direction visible at the CALL site, even without reading the subprogram's documentation.
-
OMITTED parameters enable optional arguments. Always check
ADDRESS OFfor null before accessing an OMITTED parameter. Provide sensible defaults. -
The length fields pattern — passing an actual count alongside a table or buffer — prevents the called program from accessing uninitialized or out-of-bounds storage.
Return Code Conventions
-
Standard return codes (0=success, 4=warning, 8=error, 12=severe, 16=fatal) are universally understood in mainframe environments. Use level 88 condition names (RTN-SUCCESS, RTN-OK, RTN-FAILED) for readable evaluation.
-
Propagate the highest-severity return code through call chains. The RETURN-CODE special register communicates the job's overall status to the operating system and JCL condition code checking.
Error Communication
-
Error structures complement return codes by providing the "what" and "why" — which field failed, what value was found, and what was expected. Return codes tell "how bad"; error structures tell "what happened."
-
Standardize error handling across all modules. A consistent convention understood by every developer is worth more than clever module-specific approaches.
Architecture Patterns
-
Communication areas (COMMAREA) bundle all interface data into a single structure, eliminating parameter order bugs and simplifying CALL statements. Best for tightly coupled program pipelines.
-
Separate parameters are better for loosely coupled utility programs used by many callers with different data contexts.
The Big Picture
- Parameter passing patterns are the contract language of modular COBOL. When every subprogram follows the same conventions — the same return codes, the same error structure, the same copybook-based interfaces — the system becomes dramatically easier to build, debug, and maintain. The theme of Defensive Programming is realized through careful parameter design.