Mar 22, 2010

Subprograms

1. How do you call subprograms in COBOL?
Subprograms are called using CALL statement. If Program A calls program B and pass parameters x,y 
then Call statement can be written in program A as 
CALL B USING X,Y.
Similarly in Prog B, we should have procedure division as 
PRODCEDURE DIVISION USING X,Y. 

2. What is difference between static call and dynamic call?



STATIC Call:

1) Identified by Call literal.
Ex: CALL ‘PGM1’.
2) Default Compiler option is NODYNAM and so all the literal calls are considered as static calls
3) If the subprogram undergoes change, sub program and main program need to be recompiled
4) Sub modules are link edited with main module.
5) Size of load module will be large
6) Fast,Less flexible.
7) Sub-program will not be in initial stage the next time it is called unless you explicitly use INITIAL or you do a CANCEL after each call.

DYNAMIC CALL
1) Identified by Call variable and the variable should be populated at run time.
01 WS-PGM PIC X(08).
Move ‘PGM1’ to WS-PGM
CALL WS-PGM


2) If you want convert the literal calls into DYNAMIC, the program should be compiled with DYNAM option.
By default, call variables and any un-resolved calls are considered as dynamic


3) If the subprogram undergoes change, recompilation of subprogram is enough.
4) Sub modules are picked up during run time from the load library.
5) Size of load module will be less.
6) Slow compared to Static call.
More flexible.
7) Program will be in initial state every time it is called.

Please note difference between call identifier and call literal.
CALL identifier, where identifier is a data item that contains the name of a nonnested subprogram when the program is run, always results in the target subprogram being loaded when it is called. Also, the name of the shared library must match the name of the target entry point.

CALL literal, where literal is the explicit name of a nonnested subprogram being called, can be resolved statically or dynamically. If the NODYNAM compiler option is in effect, either static or dynamic linking can be done. If DYNAM is in effect, CALL literal is resolved in the same way as CALL identifier: the target subprogram is loaded when it is called, and the name of the shared library must match the name of the target entry point.
These call definitions apply only in the case of a COBOL program calling a nonnested program. When a COBOL program calls a nested program, the CALL is resolved by the compiler without any system intervention.

Your COBOL programs can call a subprogram that is linked into the same executable module as the caller (static linking) or that is provided in a shared library (dynamic linking). COBOL for AIX also provides for run-time resolution of the target subprogram from a shared library.
If you link the target program statically, it is part of the executable module of the caller and is loaded with the caller. If you link it dynamically or resolve the call at run time, it is provided in a library and is loaded either when the caller is loaded or when it is called.

Static linking and dynamic linking are done for COBOL CALL literal subprograms only. Run-time resolution is always done for COBOL CALL identifier and is done for CALL literal when the DYNAM option is in effect.

3. How would you write static call?
Following example shows how static call can be written

PROCESS NODYNAM NODLL
IDENTIFICATION DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECORD-2 PIC X. (6)
01 RECORD-1. (2)
05 PAY PICTURE S9(5)V99.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9.
. . .
PROCEDURE DIVISION.
CALL "SUBPROG" USING RECORD-1. (1)
CALL "PAYMASTR" USING RECORD-1 RECORD-2. (5)
STOP RUN.

For calling subprogram SUBPROG, CALL literal is used. Moreover program needs to be compile with NODYNAM OPTION.

Also program needs to be statically link edited like below and link card should INCLUDE subprogm also in link editing. this will cause, subprogram to be link edited in the main program itself.

3 comments:

  1. Very good site. Keep it Very Helpful

    ReplyDelete
  2. check this as well
    http://mframes.blogspot.com/

    ReplyDelete
  3. Thanks and I have a swell supply: How Often Renovate House total home renovation

    ReplyDelete