We also call a COBOL Call Statement as Inter-Program communication which means that one program can communicate with another program by calling it.
So, the program which calls another program can share the variables, values, and resources with other programs and both of these programs can use these to perform some specific operations.
A Program can call another program/s to perform a set of tasks. In this case, the program which calls other programs we call that as CALLING Program (sometimes, also called as Main Program) while the program which is called in called as CALLED program or subprogram.
There are 2 types of calls –
- STATIC CALL
- DYNAMIC CALL
STATIC CALLS
- In case of STATIC CALLS, if we have 2 programs MAIN-PGM and SSUB-PGM then both the Programs are compiled as a separate PDS member but are link edited together at the same time. This is the reason, STATIC CALLS are faster compared to DYNAMIC CALLS.
- If we modify the sub program SSUB-PGM, we need to compile SSUB-PGM and the Calling program MAIN-PGM as well in order to link back to this newly compiled module.
- STATIC CALLS occupy more storage but take less time for execution compared to DYNAMIC CALLS.
- NODYNAM compiler option is used in case of STATIC CALLS. To check your compiler option, please check with your mainframe support/admin group.
- If the called program is very small then we can go for a static call, otherwise, the dynamic call will be better because, in static calls, the CALLED program is embedded into CALLING program’s load module.
The Syntax of STATIC Calls
Type 1: CALL ‘SUB-PROGRAM’
In this case, we don’t pass the parameters or arguments.
Type 2: CALL ‘SSUB-PGM’ USING PRM-1,PRM-2,….
In this case, we pass the parameters or arguments during the call.
DYNAMIC CALLS
In case of DYNAMIC CALLS, if we have 2 programs MAIN-PGM and DSUB-PGM then both Programs are compiled as a separate PDS member and link edited separately as well.
DYNAMIC CALLS occupy less storage as a compiled module is loaded into memory only when it is called but takes more time for execution compared to STATIC CALLS.
DYNAM compiler option is used for DYNAMIC CALLS.
- Dynamically called programs are much easier to manage than static programs
The Syntax of DYNAMIC Calls
Type 1: CALL ‘WS-SUB-PGM’
In this case, Here, WS-SUB-PGM is a working storage variable which gets the name of the sub program.This type 1 does not pass arguments or parameters.
Type 2: CALL ‘WS-SUB-PGM’ USING PRM-1,PRM-2,….
In this case, Here, WS-SUB-PGM is a working storage variable which gets the name of the sub program.This type 2 passes arguments or parameters calling the sub program.The arguments are used in the sub program to perform the operations.
We can define this WS-SUB-PGM as either –
1) We can define the WS-SUB=PGM in WORKING-STORAGE section as below –
01 WS-SUB-PGM PIC X(08) VALUE ‘DSUB-PGM’
2) Or, we can accept the name of the program through ACCEPT statement in COBOL as below:
ACCEPT WS-SUB-PGM.
While calling a subprogram, either it can a SIMPLE CALL (without any parameter or argument being passed to the subprogram) or a CALL by passing arguments to the sub programs.
Let us understand all these CALLS.
Simple Calls in COBOL
Simple Calls are calls without passing any value or arguments to the CALLED Programs.
Call By Reference
The CALLING Program sends the copy of the content of the parameters to the CALLED Program.
In this case, the Parameters while calling the sub program does not have the same memory location as that of the variables which are received to the CALLED Program.
This is the Default option available in CALL. If CALL BY REFERENCE/CONTENT/VALUE is not defined then COBOL assumes CALL BY REFERENCE as default.
Call By Content
The Parameters used in the CALLING Program for sending values to the CALLED Program refers to the same memory location.
If we change the value of any parameter in sub program, the same value will not reflect in the main program(CALLING program).
SYNTAX
USING BY CONTENT identifier1, identifier2…
Example
CALL ‘PGM-B’ USING BY CONTENT X, Y.
Call By Value
It is similar to ‘CALL BY CONTENT’ but only limited values can be sent to the CALLED program. In most of the versions, we can either pass an Integer or one-byte alphanumeric value hence it is not a preferred choice.
SYNTAX
USING BY VALUE identifier1, identifier2…
Example
CALL ‘PGM-B’ USING BY CONTENT X, Y.