Wednesday 7 April 2021

COBOL CALL Statement CALL BY Reference, CALL BY Value, CALL BY Content [CALL statement in COBOL].

COBOL CALL Statement, Dynamic Call in COBOL

CALL Statement in COBOL.

COBOL CALL Statement is an important statement. It's used to transfer control from the main program to a sub-program or subroutine. CALL statement in COBOL has three different variants i.e. CALL BY REFERENCE, CALL BY VALUE, CALL BY CONTENT. COBOL CALL  statement is divided into two categories i.e. static calls vs dynamic calls in COBOL.  

Welcome back to today's session on "CALL Statement in COBOL". In this session, you'll learn the basics of the "COBOL CALL Statement" along with an overview of the COBOL calling program and called program. You'll deep dive into different variants of COBOL CALL statements along with COBOL CALL using statement syntax and CALL statements in COBOL examples. 

Let's get started with today's agenda.

Agenda. 
  • Introduction to COBOL main program, subroutine, or subprograms. 
  • COBOL CALL Statement overview.
  • COBOL CALL Statement Syntax. 
    • CALL BY REFERENCE in COBOL.
    • CALL BY CONTENT in COBOL.
    • CALL BY VALUE in COBOL.
  • COBOL CALL Statement Types.
  • Dynamic VS Static CALLs in COBOL.
  • COBOL CALL Statement Control Flow. 
  • Conclusion.

Introduction. 

Large-scale enterprise applications are generally a combination of many systems and sub-systems. These systems and subsystems are hosted on different computing platforms, such as IBM Mainframe or windows, etc. 

A legacy application, which is hosted on an IBM mainframe is a combination of many online and batch programs. These programs are categorized into a main program, a subprogram, and copybooks based on the nature of the functionality and business logic. 

Now, the first program in the run unit is considered the main program, and all other programs in the run unit are termed as subprograms/subroutines. The main program is also known as the "calling program", and the subprogram is known as the "called program". 
Let's deep dive into COBOL CALL statement definition, syntax, and variants. 

COBOL CALL Statement. 

The COBOL CALL statement is used to transfer control from the main program to the subprogram/subroutine. The main program (i.e. COBOL, JAVA, CICS, etc.) includes the CALL statement is referred to as the calling program. The program named in the CALL statement that is linked and executed within the main program (i.e. calling program) is referred to as the called program (i.e. subprogram or subroutine).

A called program (i.e. subprogram), should have a LINKAGE SECTION. The variable which will be used to transfer data from the main program should be mapped properly with the variable defined in the linkage section. Refer to the following CALL statement example for more details. 

COBOL CALL Statement Example: 

The following example showcases how the main program calls a subprogram. 

        CALL “EMPTAX01” USING EMP-SAL, EMP-TAX.

In the following example, PGMDSP01 is the main COBOL program. It has the CALL statement that calls EMPTAX01 tax subroutine to calculate monthly tax. 

COBOL CALL Statement Example.


Let's deep dive into a COBOL CALL Statement Syntax. 

COBOL CALL Statement Syntax. 

The COBOL Call syntax is reasonably simple and easy to understand. You only need to remember a few different parameters. The COBOL CALL statement begins with the CALL keyword followed by the program name. If you want to pass value from the calling program to the called program then you have to use the keyword USING followed by variable names. 

    CALL "SUB PROGRAM NAME" USING identifier-1, identifier-2.

Now, let's go through the complex variant of the COBOL CALL statement. In this, variant you have more control over the data which is passed to the sub-program (i.e. subroutine). Specifically, the following three parameters are very important from a programming standpoint. 
  • CALL BY REFERENCE in COBOL. 
  • CALL BY CONTENT in COBOL.
  • CALL BY VALUE in COBOL.


COBOL CALL Statement Syntax, CALL Syntax in COBOL

COBOL CALL Statement Syntax

If you do not specify any of the three parameters then the system will assume CALL BY REFERENCE as the default value. The next set of parameters is on exception not on exception and returning. So these three parameters are generally used to execute a set of statements that you want to execute in case if there is any specific condition that happens.

CALL BY REFERENCE in COBOL.

In CALL BY REFERENCE, the subprogram refers to and processes the data items in the storage of the calling program instead of a copy of the data. If the subprogram updates any literal value then it will be reflected in the main program. 

CALL BY CONTENT in COBOL. 

In CALL BY CONTENT, the calling program passes only the copy of the content to the subprogram. If the subprogram updates any literal value then it will not be reflected in the main program.

CALL BY VALUE in COBOL.

In CALL BY CONTENT, the calling program passes only the copy of the content to the subprogram. If the subprogram updates any literal value then it will not be reflected in the main program. CALL BY Content is generally used in calling JAVA, C++, or any other programs. 

COBOL CALL Statement Types. 

The CALL statement in COBOL is broadly divided into the following two categories. 
  • STATIC CALL in COBOL. 
  • DYNAMIC CALL in COBOL. 
Let's discuss each category one by one in detail.

COBOL STATIC CALLS. 

static CALL in COBOL transfers controls from a calling program to a subprogram that is compiled with the calling program. The subprogram is link edited into the main module. It means, that there is only one load module that includes both the main program and subprogram. The program should be compiled with NODYNAM and NODLL options.

From a performance perspective, COBOL Static Calls are better in case you have a high number of calls because the load module resides in the main memory. 

COBOL DYNAMIC CALLS.

dynamic program CALL in COBOL transfers controls from a calling program to a called program that has been compiled into a separate program. That is, both programs (i.e. main program and subprogram) are compiled into separate load modules. The called program is loaded into the main memory and executed only when it is called.


COBOL Dynamic Call happens when a program is compiled with the DYNAM and NODLL compiler options. Always, remember the called module will be in the last used state.


From a performance perspective, COBOL Dynamic Calls can be slow and deteriorate system performance because the system has to retrieve and link the two programs together during runtime. 


What is the difference between Static call and Dynamic Call in COBOL? 

Well, there is little or no difference in the coding between a dynamic program call and a static program call. But, the procedure to produce the executable program load module is different and it is due to different compiler options. You must follow the correct compiler option and correct compilation sequence. 

COBOL CALL Example or COBOL CALL Control Statement Flow. 

Now, let's focus on a CALL statement example in COBOL, to understand the underlying concept and how exactly control transfers between the main program and subprogram. In the following example, you have two programs first program is a calling program or it's a main program and the second one is a calling program or a subprogram. In the main program, you have a COBOL call statement to invoke the subprogram.


CALL Statement in COBOL, CALL statement

COBOL CALL Statement


When the call statement is executed in the main program the control will be transferred to the subprogram. The control will be transferred back to the main program after the execution of subprogram logic. The above flow diagram illustrates the control flow. 

CALL Statement in COBOL - Youtube video. 



Conclusion. 

Finally, this marks an end to the COBOL CALL statement session. In this session, you learned what is COBOL CALL Statement and why it is an important statement. You also learned the different variants of COBOL CALL Statements such as CALL BY REFERENCE, CALL BY VALUE, and CALL BY CONTENT. Lastly, what is the difference between static calls vs dynamic calls in COBOL? Do check out COBOL LEVEL 88 Condition.


Subscribe to Topictrick & Don't forget to press THE BELL ICON to never miss any updates. Also, Please visit mention the link below to stay connected with Topictrick and the Mainframe forum on - 

► Youtube
► Facebook 
► Reddit

Thank you for your support. 
Mainframe Forum™

No comments:

Post a Comment

New In-feed ads