Date post: | 09-Apr-2018 |
Category: |
Documents |
Upload: | thrinadh-kiran-kumar |
View: | 228 times |
Download: | 0 times |
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 1/19
STATIC CALL AND DYNAMIC CALL
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 2/19
Objectives of Presentation1) Ways Of Transf erring control from one program to
another
2) Why we need to make a call3) 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
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 3/19
Ways Of Transf erring Control to the
Sub ProgramTo enhance the performance of program we
transf er the control from one program toanother
There are four ways by which we transf er the control to programs:
1) Static Calls
2) Dynamic calls
3) Calls to nested programs
4)Calls to dynamic link libraries( DLLs)
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 4/19
Why should we make a Call
A program(Main program) can also ref erence 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/identif ier using parametersNOTE: Main program Calling program
Sub Program - Called program
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 5/19
How to make a Static Call Syntax: CALL literal using param1 param2
literal-------Program-ID of Subprogram
using used to specif ies 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(
(Called
Program)
Subprogram2
(Called
Program)
Subprogram3
(Called
Program)Storage
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 6/19
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 7/19
Example for Static CallCalling Program
IDENTIFICATION DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECORD-2 PIC X.
01 RECORD-1.05 PAY PIC S9(5)V99.
05 HOURLY-RATE PIC S9V99.
05HOURS PIC S99V9. . .
PROCEDURE DIVISION.
1000-MAIN-PARA.CALL "SUBPROG" USING RECORD-1.
STOP RUN.
Called Program
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPROG.
DATA DIVISION.
LINKAGE SECTION.
01 PAYREC.10 PAY PIC S9(5)V99.
10 HOURLY-RATE PIC S9V99.
10 HOURS PIC S99V9.
PROCEDURE DIVISION USING PAYREC.
EXIT PROGRAM.
.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 8/19
What happens in the static call
statements
When the control issued from the calling
program
1. The control branches to the called programas 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.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 9/19
What exactly happe s i a static call?
CALL SUBPROG1 USING RECORD-1.
PROCEDURE DIVISION USING PAY-REC.
CALLING PROGRAM
SUBPROG1 SUBPROG2 SUBPROG3
RECORD-1
PAY-REC
Load lib
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 10/19
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 f ield in either case to zero ,because this
statements are modif ied to Move zero to the f ield beginning at address 1000 (say that AMT-1 is starting at memory location 1000)
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 11/19
CALL OPTIONS
Syntax : CALL literal/identif ier 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 ref errence
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 12/19
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. P rogramname IS INITIAL
This will be explained with an example
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 13/19
Dynamic Call
Dynamic call: In this form of a call statement, thecalled COBOL programs i s 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 identif ier using param1 param2
Main Program
Subprog
Load LibraryLoad library
Loading at runtime
Subprog
Call
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 14/19
Identif ication Division.
Program-Id. Mainprog.
Environment Division.
Data Division.
Working Storage Section.
77 ws-program name pic x(8)
01 A pic 9(2).
01 B pic 9(2).
Procedure division.
Move Subprog1 to ws-program-name.
Call Subprog1 using A,B.
;;
Cancel ws-program-name.
Move Subprog2 to ws-program-name.
Call Subprog2 using A,B.
;;
Cancel ws-program-name
Stop Run.
Identif ication Division.
Program-ID. Subprog1.
Environment Division.
Data Division.
Linkage Section.01 subA pic 9(2).
01 subB pic 9(2).
Procedure Division using subA,subB.
Exit Program.
Identif ication Division.
Program-ID. Subprog2.
Environment Division.
Data Division.
Linkage Section.
01 subA pic 9(2).
01 subB pic 9(2).Procedure Division using subA,subB.
Exit Program.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 15/19
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 f irst call to the sub program.
Question:
Can we cancel a subprogram from a program otherthan the original caller?
Ans : Yes.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 16/19
Subprogram1
Cancel Command
loaloaMain program Subprogram1
Cancel
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 17/19
Making A dynamic Call
Syntax : CALL IDENTIFIER USING
PARAM1,PARAM2.
ID
ENTIFIER VARIABLE NAME( SUBPRGRAMNAME).
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.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 18/19
Example Of dynamic ProgramCalling Program
IDENTIFICATION DIVISION.
PROGRAM-ID.MAIN-PROG.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 PGM-NAME PIC X(8).
01 RECORD-2 PIC X .
01 RECORD-1.
05 PAY PICTURE S9(5)V99.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9. . . .
PROCEDURE DIVISION. . . .
MOVE "SUBPROG" TO PGM-NAME.CALL PGM-NAME USING RECORD-1.
CANCEL PGM-NAME.
MOVE "PAYMASTR" TO PGM-NAME.
CALL PGM-NAME USING RECORD-1
RECORD-2.STOP RUN.
Called Program
IDENTIFICATION DIVISION.PROGRAM-ID. SUBPROG.
DATA DIVISION.
LINKAGE SECTION.
01 PAYREC.
10 PAY PICTURE S9(5)V99.
10 HOURLY-RATE PICTURE S 9V99.
10 HOURS PICTURE S 99V9.
77 PAY-CODE PICTURE 9.
PROCEDURE DIVISION USING PAYREC.
. . .
EXIT PROGRAM.
8/8/2019 Static and Dynamic Call
http://slidepdf.com/reader/full/static-and-dynamic-call 19/19
Performance Of static and Dynamic Call
Static Call
In static call, as the subprogram is link-edited with the main program, it is f aster in processing .So
static call is best when udon't need the services fordynamic calls
In static call the subprogramis link-edited with main
program it occupies the main storage irrespective of the call issued on the subprogram.
Dynamic Call
In Dynamic Call, unless the call is issued the subprogram is not link-edited to the main program
So storage wise dynamic call are always better because they free
the storage occupied by the dynamic call with a cancel stmt.
Dynamic calls are issued when we want to call many subprograms having a large storage.
Using a dynamic call stmt then cancel consecutively is always better than going for static call
occupying large amount of data