Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 19

STATIC CALL AND DYNAMIC CALL

Objectives of Presentation
1) Ways Of Transferring control from one program to
another
2) Why we need to make a call
3) What is Static and Dynamic Call
4) Making Static and Dynamic Calls
5) Example of Static and Dynamic Call
6) Performance of static and Dynamic Call
Ways Of Transferring Control to the
Sub Program
To enhance the performance of program we
transfer the control from one program to
another…
There are four ways by which we transfer the
control to programs:
1) Static Calls
2) Dynamic calls
3) Calls to nested programs
4)Calls to dynamic link libraries( DLLs)
Why should we make a Call
• A program(Main program) can also reference an
independent sub-programs stored in a library using CALL.
• Types of Calls:
1. Static Call
2. Dynamic Call
• Advantages:
1. Avoids Duplication of effort
2. Improves programmer productivity
3. Provides greater flexibility.
• Syntax : Call literal/identifier using parameters
NOTE: Main program – Calling program
Sub Program - Called program
How to make a Static Call
• Syntax: CALL literal using param1 param2
• literal-------Program-ID of Subprogram
• using – used to specifies the parameters to be
passed to the called program
• In a Static Call the calling and all called
programs are in the same load module.

Main Program(Calling Program)

Subprogram1( Subprogram2 Subprogram3


(Called (Called (Called
Program) Program) Program)
Storage
Identification Division.
Identification Division. Program-ID. Subprog1.
Environment Division.
Program-Id. Mainprog.
Data Division.
Environment Division. Linkage Section.
Data Division. 01 subA pic 9(2).
Working –Storage Section. 01 subB pic 9(2).
01 A pic 9(2). Procedure Division using subA,subB.
01 B pic 9(2).
Procedure division.
Call “Subprog1” using A,B. Exit Program.
;
Identification Division.
; Program-ID. Subprog2.
Environment Division.
Call “Subprog2 using A,B. Data Division.
; Linkage Section.
; 01 subA pic 9(2).
Stop Run. 01 subB pic 9(2).
Procedure Division using subA,subB.

Exit Program.
Example for Static Call
Calling Program Called Program
IDENTIFICATION DIVISION. IDENTIFICATION DIVISION.
DATA DIVISION. PROGRAM-ID. SUBPROG.
WORKING-STORAGE SECTION. DATA DIVISION.
01 RECORD-2 PIC X. LINKAGE SECTION.
01 RECORD-1. 01 PAYREC.
05 PAY PIC S9(5)V99. 10 PAY PIC S9(5)V99.
05 HOURLY-RATE PIC S9V99. 10 HOURLY-RATE PIC S9V99.
05HOURS PIC S99V9. . . 10 HOURS PIC S99V9.
PROCEDURE DIVISION.
1000-MAIN-PARA. PROCEDURE DIVISION USING PAYREC.
CALL "SUBPROG" USING RECORD-1.
EXIT PROGRAM.
STOP RUN. .
What happens in the static call
statements
• When the control issued from the calling
program
1. The control branches to the called program
as it is available in the same load module of
calling program.
2.Subsequent executions of the call statement
make the called programs available in its last-
used.
What exactly happens in a static call?

• CALL SUBPROG1 USING RECORD-1.


• PROCEDURE DIVISION USING PAY-REC.
Load lib

RECORD-1 CALLING PROGRAM

PAY-REC

SUBPROG1 SUBPROG2 SUBPROG3


Subprogram Data Linkage
• The order of the parameters is important as the
sub-program recognizes them by relative location
not by name.
Ex: Calling Program: CALL ‘SUM-SUB’ USING AMT-1,AMT-2

Called Program: Procedure division using A, B.


• Move zero to A or Move zero to AMT-1 will set
the field in either case to zero ,because this
statements are modified to “Move zero to the
field beginning at address 1000 (say that AMT-1
is starting at memory location 1000)
CALL OPTIONS
• Syntax : CALL literal/identifier using
by content param1,param2, by
reference param 3,param4.
• By Content---- Parameters should be passed
BY CONTENT when you are not expecting
them to get a value from the called program.
• By Reference ---- Parameters should be
passed BY REFERENCE if you require the called
program to pass back data - as is the case
with the result of the multiplication.
• Default : By referrence
INITIAL VERB
• As we know the subsequent issue of call will
branch to the sub-program in its previous
state of execution.
• To get the subprogram into its initial state in
a run unit or job we use the INITIAL attribute.
• Syntax : Program-Id. Programname IS INITIAL
• This will be explained with an example…
Dynamic Call
Dynamic call: In this form of a call statement, the
called COBOL programs is not link-edited with the
main program, instead link-edited into a separate
load module, and is loaded at runtime when it is
required( that is, when called).
Syntax : CALL identifier using param1 param2
Call
Main Program

Subprog

Subprog

Load library Load Library


Loading at runtime
Identification Division.
Program-Id. Mainprog. Identification Division.
Environment Division. Program-ID. Subprog1.
Environment Division.
Data Division.
Data Division.
Working –Storage Section. Linkage Section.
77 ws-program –name pic x(8) 01 subA pic 9(2).
01 A pic 9(2). 01 subB pic 9(2).
01 B pic 9(2). Procedure Division using subA,subB.
Procedure division.
Move “Subprog1” to ws-program-name.
Call “Subprog1” using A,B. Exit Program.
;
Identification Division.
; Program-ID. Subprog2.
Cancel ws-program-name. Environment Division.
Move “Subprog2” to ws-program-name. Data Division.
Linkage Section.
Call “Subprog2 using A,B. 01 subA pic 9(2).
; 01 subB pic 9(2).
; Procedure Division using subA,subB.
Cancel ws-program-name
Stop Run. Exit Program.
Cancelling a Call
CANCEL statement is issued to cancel a sub-
program.
When a cancel stmt is issued for a subprogram :
1) The storage occupied by the subprog is freed
2) Subsequent call to the subprogram functions as
though it were a first call to the sub program.
Question:
Can we cancel a subprogram from a program other
than the original caller?
Ans : Yes.
Cancel Command

Main program Subprogram1


loaloa

Subprogram1

Cancel
Making A dynamic Call
• Syntax : CALL IDENTIFIER USING
PARAM1,PARAM2.
IDENTIFIER –VARIABLE NAME( SUBPRGRAM
NAME).
Question: Can we make a dynamic call with
static call syntax ?
Ans: Yes ,we can make a call by setting the
compiler options as DYNM and NODLL.
Example Of dynamic Program
Calling Program
Called Program
IDENTIFICATION DIVISION.
IDENTIFICATION DIVISION.
PROGRAM-ID.MAIN-PROG.
PROGRAM-ID. SUBPROG.
DATA DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
LINKAGE SECTION.
77 PGM-NAME PIC X(8).
01 PAYREC.
01 RECORD-2 PIC X.
10 PAY PICTURE S9(5)V99.
01 RECORD-1.
10 HOURLY-RATE PICTURE S 9V99.
05 PAY PICTURE S9(5)V99.
10 HOURS PICTURE S 99V9.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9. . . . 77 PAY-CODE PICTURE 9.
PROCEDURE DIVISION. . . . PROCEDURE DIVISION USING PAYREC.
MOVE "SUBPROG" TO PGM-NAME.
CALL PGM-NAME USING RECORD-1. ...
CANCEL PGM-NAME. EXIT PROGRAM.
MOVE "PAYMASTR" TO PGM-NAME.
CALL PGM-NAME USING RECORD-1
RECORD-2.
STOP RUN.
Performance Of static and Dynamic Call

Static Call Dynamic Call


• In static call, as the • In Dynamic Call, unless the call is
subprogram is link-edited issued the subprogram is not link-
edited to the main program
with the main program, it is
• So storage wise dynamic call are
faster in processing .So always better because they free
static call is best when u the storage occupied by the
don't need the services for dynamic call with a cancel stmt.
dynamic calls • Dynamic calls are issued when we
• In static call the subprogram want to call many subprograms
having a large storage.
is link-edited with main
• Using a dynamic call stmt then
program it occupies the cancel consecutively is always
main storage irrespective of better than going for static call
the call issued on the occupying large amount of data
subprogram.

You might also like