Wednesday, April 9, 2014

Static call and Dynamic call in cobol with example - compiler options for static and dynamic call

This is a much discussed topic among the COBOL programmers.We can identify the calls by seeing the 'CALL' structure.Lets see what is the difference between static and dynamic call and other information.
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-PGM 
CALL 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.
Positive point:
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


  1. Hi Mukherjee,

    This is really explained well. Many Thanks!

  2. Its very clear to differentiate static call and dynamic call

  3. Please tell in detail how to use or specify NODYNAM COMPILER OPTION

    1. if u use a compile JCL with IGYCRCTL, then you can use like below:

      If you use endeavor or changeman then you cant not do it thru the JCL directly. However the other way of overriding the existing parameters is to write the parm before the IDENTIFICATION DIVISION in your cobol program. something like CBL DATA(24), RMODE(24).
      CBL is the compiler directive which can be used to override the compier options through cobol program. Let me know if this clarifies.

    2. amazing Rik..

  4. IF program A is calling Program B Using Dynamic call and Program B is Calling Program C Using Static call and Program C is calling Program D using Dynamic call. what if there is a change in Program D then what all programs needs to be compiled and how it would work ?

  5. Only program D need to compile again , no need to compile all other program because its takes the changed value of program D at run time.

    1. Yes, you are right Paro. To continue to your answer if any changes in program B or C we need to recompile both programs(B&c).
      Please correct me if I am wrong.