Dynamic CALL
Dynamic CALL Example
Scenario - Dynamic Call from MAINPROG to SUBPROG.
MAINPROG -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. MAINPRDY.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-PROG PIC X(08) VALUE "SUBPRDY".
PROCEDURE DIVISION.
DISPLAY "Before Calling Subprogram".
CALL WS-PROG.
DISPLAY "Returned From Subprogram".
STOP RUN.
SUBPROG -
----+----1----+----2----+----3----+----4----+----5----+
IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPRDY.
AUTHOR. MTH.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-VAR.
05 WS-INP1 PIC 9(02) VALUE 10.
05 WS-INP2 PIC 9(02) VALUE 20.
05 WS-RESULT PIC 9(03) VALUE ZEROES.
PROCEDURE DIVISION.
COMPUTE WS-RESULT = WS-INP1 + WS-INP2.
DISPLAY "RESULT (SUBPROG): " WS-RESULT.
GOBACK.
JCL -
//MATEPKRJ JOB MSGLEVEL=(1,1),NOTIFY=&SYSUID //*********************************************** //* RUN A COBOL PROGRAM //*********************************************** //STEP01 EXEC PGM=MAINPRDY //STEPLIB DD DSN=MATEPK.COBOL.LOADLIB,DISP=SHR //SYSOUT DD SYSOUT=*
Output -
Before Calling Subprogram RESULT (SUBPROG): 030 Returned From Subprogram
Explaining Example -
In the above example:
- MAINPRDY is the main program, and SUBPRDY is the subprogram.
- CALL WS-PROG makes the call as dynamic call.
- WS-INP1 and WS-INP2 are the precoded inputs in the SUBPRDY.
- SUBPRDY adds those values, places the result into WS-RESULT and displays it.
- Returns the control to the main program.