Calling Program
A calling program, in the mainframe context, is an executable program (e.g., a COBOL program, Assembler module, or PL/I program) that initiates the execution of another program or routine, known as a **called program** or **subroutine**, to perform a specific function. It transfers control to the called program, often passing data, and expects to regain control upon the called program's completion.
Key Characteristics
-
- Control Transfer Mechanism: Utilizes specific language constructs (e.g.,
CALLstatement in COBOL,BALRinstruction in Assembler) to transfer execution control to the entry point of the called program. - Parameter Passing: Can pass data (parameters or arguments) to the called program, typically by reference (passing the address of data) or by value, adhering to established linkage conventions.
- Linkage Conventions Adherence: Must follow IBM's standard z/OS linkage conventions (e.g., register usage, save area management) to ensure proper communication and control flow between programs, especially across different programming languages.
- Return Address Management: Stores the return address to which the called program should transfer control back upon its completion, enabling sequential execution flow.
- Modular Design Enabler: Facilitates modular programming, allowing complex applications to be broken down into smaller, reusable, and more manageable components.
- Shared Environment: Typically operates within the same address space and often the same task as the called program, sharing resources like memory and program status.
- Control Transfer Mechanism: Utilizes specific language constructs (e.g.,
Use Cases
-
- Business Logic Encapsulation: A main batch COBOL program calls a separate COBOL subroutine to perform a complex calculation (e.g., tax computation, interest calculation) or a specific data validation routine, centralizing the logic.
- Common Utility Functions: An application program calls a common Assembler or COBOL utility module to perform system-level tasks like date formatting, string manipulation, or error message retrieval.
- Database Access Abstraction: In a CICS transaction, a calling program might invoke a subprogram specifically designed to interact with a DB2 or IMS database, separating business logic from data access logic.
- Inter-Language Communication: A PL/I program might call an existing COBOL subroutine to leverage established business rules or vice versa, requiring careful management of data types and linkage.
- Error Handling and Logging: An application module calls a dedicated error handling or logging routine whenever an exception or significant event occurs, ensuring consistent error reporting.
Related Concepts
The calling program is intrinsically linked to the called program (subroutine or subprogram), forming the basis of modular programming on z/OS. Their interaction is governed by program linkage conventions, which dictate how parameters are passed and control is transferred. The linkage editor plays a crucial role in resolving external references between calling and called programs, combining them into a single load module or multiple load modules that can be dynamically linked. Effective communication often involves the Program Linkage Area (PLA) and proper register usage.
- Define Clear Interfaces: Establish a precise interface for the called program, detailing all expected parameters (data type, length, usage), their order, and potential return codes.
- Adhere to Linkage Conventions: Strictly follow IBM's z/OS standard linkage conventions to ensure reliable communication, especially when mixing programming languages (e.g., COBOL calling Assembler).
- Implement Robust Error Handling: Design both the calling and called programs with comprehensive error detection and reporting, using return codes to signify success, warnings, or specific failure conditions.
- Validate Input Parameters: The called program should always validate its input parameters to prevent invalid data from causing abends or incorrect processing, even if the calling program is expected to provide valid data.
- Manage Resources Responsibly: Ensure that any resources (e.g., files, database cursors, dynamically allocated memory) acquired by the called program are properly released or closed before returning control to the caller.
- Thorough Documentation: Document the purpose, parameters, return codes, and side effects of both the calling and called programs to facilitate maintenance and future development.