Understanding Static and Dynamic Calls in COBOL
This is a commonly discussed topic among COBOL programmers. We can identify program calls by looking for the CALL statement in the code. Let’s explore the difference between static and dynamic calls, and understand when and why to use each.
1. Static Call
A static call means the calling and called program modules are bound together at compile/link time. This binding remains fixed until one of the programs changes, after which the entire set must be recompiled and linked.
Example:
CALL 'PGM1'.
Here, the program PGM1 is directly referenced in the CALL statement.
Characteristics of Static Calls:
- Load module: All programs are combined into a single load module.
- Example: If
PGM-AcallsPGM-BandPGM-Cstatically, there will be one load module containing all three programs.
- Example: If
- Execution speed: Fast, since no runtime resolution is needed.
- Disk/virtual storage: Larger, because all code is loaded together.
- Maintenance: If a called program changes, all programs must be recompiled and linked.
2. Dynamic Call
A dynamic call occurs when the calling program does not know about the called program until runtime. The binding happens at the moment the call is executed.
Example:
01 WS-PGM PIC X(08). *> Working storage variable
MOVE 'PGM1' TO WS-PGM
CALL WS-PGM
Here, WS-PGM is a working-storage variable populated with the name of the program to call at runtime.
Characteristics of Dynamic Calls:
- Load module: Each program exists as a separate load module in the library.
- Example: If
PGM-AcallsPGM-BandPGM-Cdynamically, there will be three separate load modules.
- Example: If
- Execution speed: Slightly slower due to runtime call resolution.
- Disk/virtual storage: More efficient; main program only loads what it needs.
- Maintenance: Each program can be compiled and linked independently, without affecting others.
3. Choosing Between Static and Dynamic Calls
- Static call: Best for small, simple programs where execution speed is critical.
- Dynamic call: Better for larger or complex programs, or when incremental maintenance is desired.
Summary Table:
| Feature | Static Call | Dynamic Call |
|---|---|---|
| Binding | Compile/link time | Runtime |
| Load modules | Combined into one | Separate |
| Execution speed | Faster | Slightly slower |
| Disk/virtual space | Larger | Smaller |
| Maintenance | Must recompile all if one changes | Individual program can be recompiled |
| Use case | Small programs, performance-critical | Large programs, maintainability |
4. Compiler Options
- NODYNAM
CALL 'PGM-A'→ Static callCALL WS-VARA→ Dynamic call
- DYNAM
CALL 'PGM-A'→ Dynamic callCALL WS-VARA→ Dynamic call
✅ Key Takeaways:
- Use static calls for fast execution and tightly coupled small programs.
- Use dynamic calls for flexibility, smaller main modules, and easier maintenance.
- Compiler options can override default behavior, so always check your environment.
Leave a comment