CALL


In this chapter, we will discuss the usage of the COBOL CALL statement in the CICS environment. The CALL statement can serve as an alternative to the LINK and XCTL commands. It is used to invoke another program that is at the same level or a lower level, with the expectation that control will return to the calling program. Any program that is called using the CALL statement must have a program definition (PPT). It's important to note that static calling is not allowed in CICS environments.

The CALL statement is typically used in the following scenarios within CICS:

  • CALL is particularly useful when the subprogram is written solely in COBOL and does not contain any CICS statements.
  • It is also advantageous in scenarios where a subprogram is called multiple times, as this can enhance efficiency and performance.
  • When a subprogram is called repeatedly, CALL works much faster and utilizes less memory.

Disadvantages -

  • Calls can not be debugged, as they are invisible to CICS.
  • The CALL statement cannot be used for programs in remote regions.
  • For multiple calls, the working storage of the subprogram retains its values, so use caution when calling it a second time.
  • If the working storage is not initialized, it may lead to unpredictable results.

Syntax -

Static CALL -

CALL 'PROG1' USING parameter-1, parameter-2.
  • PROG1: The name of the subprogram being called.
  • USING: Passes parameters to the subprogram.

Dynamic CALL -

CALL WS-PROG-NAME USING parameter-1, parameter-2.
  • WS-PROG-NAME: A working-storage variable containing the name of the program.

How it works?

  1. The calling program executes a CALL statement.
  2. Control transfers to the called program.
  3. The called program processes the request and returns control.
  4. The calling program resumes execution after the called program completes.

Short Examples -


Scenario - Below is an example demonstrating how a main program (MAINPROG) calls a subprogram (SUBPROG) using the CALL statement.

Main Program (MAINPROG) -

IDENTIFICATION DIVISION.
PROGRAM-ID. MAINPROG.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-COMMAREA  PIC X(100).
01 WS-PROG-NAME PIC X(08)  VALUE "SUBPROG".

PROCEDURE DIVISION.
    ...

	CALL WS-PROG-NAME 
	     USING WS-CUSTOMER-ID, WS-CUSTOMER-NAME.

    ...
	
    EXEC CICS RETURN
         END-EXEC.

Called Subprogram (SUBPROG) -

IDENTIFICATION DIVISION.
PROGRAM-ID. SUBPROG.

DATA DIVISION.
LINKAGE SECTION.
01 LK-CUSTOMER-ID   PIC X(10).
01 LK-CUSTOMER-NAME PIC X(30).

PROCEDURE DIVISION 
       USING LK-CUSTOMER-ID, LK-CUSTOMER-NAME.
    DISPLAY "Received Customer ID: ", LK-CUSTOMER-ID.
    
	PERFORM GET-CUSTOMER-NAME.
	
    MOVE "John Doe" TO LK-CUSTOMER-NAME.
    ...

Differences Between CICS XCTL, CICS LINK, and COBOL CALL Statements -


Feature CICS XCTL CICS LINK COBOL CALL
Purpose Transfers control permanently to another program. Calls another CICS program temporarily and returns after execution. Calls a COBOL subprogram (works in both batch and CICS).
Control Flow The calling program is terminated, and control is never returned. The called program executes and returns control to the calling program. The called program executes and returns control to the calling program.
Hierarchy Called program replaces the calling program. Called program runs at the same logical level as the caller. Called program runs within the caller's memory space.
Returns Control? No Yes Yes
Works in CICS? Yes Yes Yes
Works in Batch? No No Yes
Passes Data? Yes (COMMAREA) Yes (COMMAREA) Yes (Parameter passing)
COMMAREA Required? Yes Yes No (Uses parameters instead)
Execution Speed Fast (program replacement) Moderate Slower (depends on static/dynamic binding)
Error Handling RESP and RESP2 RESP and RESP2 RETURN-CODE
How It Works? - The calling program stops executing.
- The called program runs and never returns.
- The calling program pauses execution.
- The called program runs and returns.
- The calling program pauses execution.
- The subprogram runs and returns.