Static call implies that the objects modules(of called and calling) are bound together before they use each other.This bonding remains the same until one of the program gets changed and the whole set is compiled/linked again.
Dynamic call implies the calling program does not know about the called program until the call takes place.The bonding between the program happens right at the time the call is made
Lets see in details how the calls are made and few other details
In case of static call, we refer to the called program name directly in the call statement.
Ex: CALL ‘PGM1’.
In case of dynamic Call, we call one working-storage variable which is populated with the called program name at run time dynamically.
01 WS-PGM PIC X(08). <<== Working storage variable
Move ‘PGM1’ to WS-PGMCALL WS-PGM
Here WS-PGM is the Working Storage item. In Procedure Division we are moving the called program name 'PGM1' to WS-PGM and then calling it.
When to go for Static and Dynamic call ?
Taking the decision to call statically or dynamically is upto the programmer.Generally we consider the size of the program and decide.If the size of the called program is small (i mean, very few lines of code and non complex functions )then we can go for static call, otherwise dynamic call will be better.Both have its positive and negative points.
So in case of static call:
If we have the main program PGM-A and it calls two sub programs statically(pgm-b &pgm-c), we will have only 1 load module for all the three.Load modules of pgm-b and pgm-c will be linked edited into the load module of PGM-A making the size of the load bigger.
Negative points for a static call
Since the load modules exists together,it takes up more virtual space on disk
If any changes are made to called program, then all the programs must be compiled/linkd.
Positive point: Execution is fast
In case of Dynamic call:
As the name suggests, the program is called dynamically.The load module of the called program will exists separately in the load module library. Thus here if PGM-A calls pgm-b and pgm-c, we will have 3 load modules our load library.
The main module does not take up unnecessary space.
Since these are stand alone programs, we can compile/link respective programs without touching all the programs and main program.
Negative points for a dynamic Call:
Since it executes with program call resolution, the call is a bit slow than static all.
Compiler options which can override the Static and dynamic calls:
If compiled with NODYNAM compiler option
CALL 'PGM-A' will be handled as a static call
CALL WS-VARA will be treated as dynamic call
If compiled with DYNAM compiler option:
CALL 'PGM-A' will be also treated as a dynamic call
CALL WS-VARA will be treated as a dynamic call