Invoker - Calling program
In the context of IBM mainframe systems, an **invoker** or **calling program** is a program or module that initiates the execution of another program, often referred to as a **called program** or **subprogram**. It transfers control to the called program, typically passing data through parameters, and expects control to be returned upon the called program's completion.
Key Characteristics
-
- Control Transfer: The invoker explicitly transfers execution control to the called program using language constructs (e.g.,
CALLin COBOL) or system services. - Parameter Passing: It is responsible for preparing and passing data (parameters) to the called program, which can be done by reference (address) or by value.
- - Return of Control: After the called program completes its processing, it returns control and often a status indicator (e.g., return code) back to the invoker.
- Execution Environment: The invoker maintains its own execution environment (e.g., working storage, registers) and typically expects the called program to preserve or restore certain aspects of this environment.
- Language Agnostic: An invoker can be written in various mainframe languages (COBOL, PL/I, Assembler) and can call programs written in the same or different languages, provided their linkage conventions are compatible.
- Control Transfer: The invoker explicitly transfers execution control to the called program using language constructs (e.g.,
Use Cases
-
- Modular Program Design: A main COBOL program calling multiple subprograms, each responsible for a specific function like data validation, complex calculation, or database access.
- Utility Routines: A CICS online transaction program invoking a common utility subprogram to format dates, validate input fields, or perform standard error logging.
- Batch Processing: A JCL job step executing a program that, in turn, dynamically calls another program based on runtime conditions to perform a specific data transformation.
- System Services: The z/OS operating system itself acts as an invoker when it loads and executes a user-defined program specified in a
EXEC PGM=statement in JCL.
Related Concepts
The invoker is intrinsically linked to the called program or subprogram, forming a fundamental client-server relationship within an application. The mechanism for transferring data between them is parameter passing, which relies on linkage conventions established during compilation and linking. The Linkage Editor or Binder combines the invoker and called programs into a single load module for static calls, or prepares them as separate load modules for dynamic calls, where the invoker resolves the called program's address at runtime. In CICS, LINK and XCTL commands are specific forms of program invocation, with LINK behaving like a traditional call (returning to the invoker) and XCTL transferring control permanently.
- Define Clear Interfaces: Document the exact parameters (data type, length, purpose, direction) expected by the called program to ensure correct data exchange and prevent runtime errors.
- Handle Return Codes: Always check the return code or status indicator provided by the called program to implement appropriate error handling or conditional logic in the invoker.
- Optimize Call Type: Use static calls for frequently used, small, and stable subprograms to reduce overhead. Employ dynamic calls for less frequently used, larger, or interchangeable modules to conserve memory and enhance flexibility.
- Manage Shared Resources: If the invoker and called program share common areas (e.g.,
LINKAGE SECTIONforBY REFERENCEparameters), ensure proper synchronization and avoid unintended side effects. - Resource Management: For CICS programs, be mindful of
LINKdepth, as excessive nesting can consume valuable resources and potentially lead to transaction abends. ConsiderXCTLfor transferring control to a new transaction without returning.