Monday 28 July 2014

CALL VERB | COBOL CALL STATEMENT | CALL Statement in COBOL.

COBOL CALL statement is often used to CALL the running unit subroutine or subprogram. The calling program is called the "main program" and the called program is called a "subprogram" or "subroutine"

In today's session, you'll learn the basics of CALL statements in COBOL and how you can use call statements to call subprograms. You'll also learn the different variants of COBOL CALL phrases such as CALL BY VALUE, CALL BY CONTENT, and CALL BY REFERENCE

Let's get started with today's COBOL tutorial on the CALL statement in COBOL.  

Agenda.
  • Introduction.
  • COBOL CALL Statement and Syntax. 
    • CALL BY REFERENCE.
    • CALL BY VALUE.
    • CALL BY CONTENT.
  • Static CALL Vs Dynamic CALLs.
  • CALL statement control flow. 
  • COBOL CALL statement example. 

Introduction. 

Large scale enterprise applications is a combination of many system and subsystems. Different computing platforms, such as IBM Mainframe or cloud, support these systems.

Mainframe application is a combination of tons of batch and online programs. These programs are labeled as the main program, subprogram, and a copybook on the essence of the features and business logic used in these programs.

Copybooks are often used to include the structure of the file or even some basic piece of logic for example - month calculation. COPY statement are used to include the copybook logic in the COBOL program.

CALL Statement in COBOL. 

There are no specific criteria for the main program and subprogram. But, as per rule, the first program is often treated as the main program and other programs consider as subprograms. 

COBOL CALL statement is used to transfer control from the main program to subprogram and once the logic is executed then control is transferred back to main-program. 

Important Point: 
  • A COBOL subroutine/subprogram typically left in the last used-state in next subsiquent call. But, if you specify INITAL attribute in the program then subroutine will be initialized everytime it is called. 
  • You should always use GOBACK or EXIT PROGRAM statement instead of STOP RUN in called program. Otherwsie, subprogram and main program processing will be terminated.  
Let's look at syntax of CALL statements in COBOL. 

COBOL CALL Statement Syntax. 

The syntax of COBOL Call statement is pretty simple and straight forwards. You have to use CALL keyword followed by subroutine name and parameters value. following is the simple variant of COBOL call statemement.  

CALL literal-1 [USING identifier-1 . . .]

Now, let's discuss complex variant of CALL statement. In this variant, you have more control over the data that is passed from main program to subprogram and vice versa. 

CALL Statement in COBOL syntax, CALL Statement syntax
COBOL CALL Statement Syntax.

In above syntax, call by reference, call by value and call by content are three different techniques of passing data from main program to subprogram. If you don't specify anything then By REFERENCE will be assumed. Let's discuss each parameters one by one. 

  • CALL BY REFERNCE: The subprogram refers to and processes the data items in storage of the calling program rather than working on a copy of the data.
  • CALL BY CONTENT: The calling program passes only the contents of the literal or identifier. 
  • CALL BY VALUE: The calling program passes the value of the data-items, instead of reference to the sending data item. The called program can change the parameter, but the change do not affect the argument in calling program
Static Vs Dynamic Call in COBOL.

COBOL CALL statement is divided into following category: 
  • STATIC CALL
  • DYNAMIC CALL
In the static CALL statement, the COBOL program and all called programs are part of the same load module. When control is transferred, the called program already resides in storage, and a branch to it takes place. Subsequent executions of the CALL statement make the called program available in its last-used state unless the called program has the INITIAL attribute. In that case, the called program and each program directly or indirectly contained within it are placed into their initial state each time the called program is called within a run unit.

In these forms of the CALL statement, the called COBOL subprogram is not link-edited with the main program. Instead, it is link-edited into a separate load module, and is loaded at run time only when it is required (that is, when called). The program-name in the PROGRAM-ID paragraph or ENTRY statement must be identical to the corresponding load module name or load module alias of the load module that contains the program.

COBOL CALL Statement control flow: 

In the following example you have two programs in a run unit. The main program is PGMDSP01 and the subroutine i.e. EXPTAX01. 

Main program call subroutine by using COBOL CALL statement. The main program pass EMP-SAL and subroutine return Tax on employee salary.  



No comments:

Post a Comment

New In-feed ads