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-A calls PGM-B and PGM-C statically, there will be one load module containing all three programs.
  • 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-A calls PGM-B and PGM-C dynamically, there will be three separate load modules.
  • 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:

FeatureStatic CallDynamic Call
BindingCompile/link timeRuntime
Load modulesCombined into oneSeparate
Execution speedFasterSlightly slower
Disk/virtual spaceLargerSmaller
MaintenanceMust recompile all if one changesIndividual program can be recompiled
Use caseSmall programs, performance-criticalLarge programs, maintainability

4. Compiler Options

  • NODYNAM
    • CALL 'PGM-A' → Static call
    • CALL WS-VARA → Dynamic call
  • DYNAM
    • CALL 'PGM-A' → Dynamic call
    • CALL 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

Discover more from DBzTech-Technology Dossier

Subscribe now to keep reading and get access to the full archive.

Continue reading