Static and Dynamic Call
Static and Dynamic Call
Static 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)
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?
PAY-REC
Subprog
Subprog
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