Call Statement Example


Scenario - Let us assume sub program perfoming addition with precoded values. It is required to call from many a Main program.

MAINPROG -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MAINPRST.
       AUTHOR. MTH.

       PROCEDURE DIVISION.

           DISPLAY "Before Calling Subprogram".
           CALL "SUBPRST".
           DISPLAY "Returned From Subprogram".
           STOP RUN.

SUBPROG -

----+----1----+----2----+----3----+----4----+----5----+
       IDENTIFICATION DIVISION.
       PROGRAM-ID. SUBPRST. 
       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=MAINPRST                      
//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:

  • MAINPRST is the main program, and SUBPRST is the subprogram.
  • CALL "SUBPRST" makes the call as static call.
  • WS-INP1 and WS-INP2 are the precoded inputs in the SUBPRST.
  • SUBPRST adds those values, places the result into WS-RESULT and displays it.
  • Returns the control to the main program.