Thursday, November 20, 2008

Cobol static and dynamic call efficiency

Finally, after learning about different type of cobol calls there are few more pop-up questions.

What is more efficient - static or dynamic call – and why? Which CALL is better under what circumstances ?

Lets discuss this, we will compare both type of calls under different scenarios. This will give us a much clear picture.
1) Suppose we have a main program which calls 100 other programs (each one only once) which one would be better i.e Static or Dynamic Call ?
2) Similarly if we have a main program which calls a single program 100 times then in that case which one would be better i.e Static or Dynamic Call ?


While making decision whether to make static call or dynamic call, we must consider size of the called program. If the called program is very small then we can go for static call, otherwise dynamic call will be better. As in static call, called program is embedded into calling programs load module.

1)In first case since the number of called program is too high so it will be better to go for dynamic call, as if you go for static call and if any one of the 100 programs get changed then u need to compile all the 100 programs in correct sequence.
2)In second case it is better to go for static call, as main program is calling 100 times the subroutine program. As in dynamic call, control need to passed to different object module, so it will take more time, where as in static call there will be only one load module, so time consumption will be less in that case.

As is the case in most programing choices one must evaluate the "trade offs" involved.

Statically linked modules:
  • It accumulate virtual space on disk - bad (see Note 1 below).
  • execute with a branch to the entry point - good (fast).
  • if any changes are made to called program, then all the calling programs must be relinked - bad.

Dynamically linked modules:

  • It doesn't accumulate virtual space on disk - good.
  • It executes with system assist & overhead - bad (Its slow See Note 2 below).
  • if any changes are made to called program, then you don't need to recomplie/relink the calling programs - good.

Note 1 - If main mod is 10K and each of the 100 subs is 5k the combined static load mod is 510K. The dynamic is 10K, but will use only 15K. As I recall you issue a CANCEL after each use of a submod to get a fresh copy of the code; if you need totals already accumulated, you'd want to avoid the CANCEL.

Note 2 - When each dynamic mod is CALLed memory is 1st searched for a usable copy. If none is found loadlib is searched and the mod is loaded (that means reads are done against the load PDS) and control is then passed to the called mod.

So it boils down to a process of evaluating the "trade offs" (good vs bad) and making a decision.

I hope this post was helpful to you. Please do let me know your comments or reactions.

For more cobol queries.

COBOL calls with compiler options

Hi,

In the few previous post, we talked about the different types of call in cobol( static and dynamic). We also talked about how to invoke these. But be careful, there are few compiler options which can change the type of call made by you in the COBOL program.

Below are the compiler options which can override the calling mechanism in your COBOL program :

  • If compiled with NODYNAM compiler option:
  • CALL 'literal' is a static call
  • CALL WS-label is a dynamic call

  • If compiled with DYNAM compiler option:
  • CALL 'literal' is a dynamic call
  • CALL WS-label is a dynamic call

So, next time just be careful while making any type of CALL in your cobol code.

Hope things are much more clearer now. Please do not forget to provide your comments or reactions.


For more cobol queries, check this out : More COBOL questions