Key Takeaways — Chapter 23: Parameter Passing Patterns

The Three Modes

  1. 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.

  2. 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.

  3. 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

  1. 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.

  2. OMITTED parameters enable optional arguments. Always check ADDRESS OF for null before accessing an OMITTED parameter. Provide sensible defaults.

  3. 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

  1. 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.

  2. 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

  1. 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."

  2. Standardize error handling across all modules. A consistent convention understood by every developer is worth more than clever module-specific approaches.

Architecture Patterns

  1. 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.

  2. Separate parameters are better for loosely coupled utility programs used by many callers with different data contexts.

The Big Picture

  1. 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.