TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

CICS LINK Control Command


CICS LINK Command:

To pass control to a program at a lower logical level expecting control to be returned to the program at the higher logical level.


When one program LINKs to another, the first program stays in the main storage while the second program is executing.

When the second (LINKed to) program ends and returns control, the first program resumes at the point after the LINK statement. The LINKed to program is considered to be operating at one logical level lower than the LINKing program.

cics link control command

The above diagram explains the process of calling a Link’ed program from Main program – Lower Logical Levels.

LINK must be used for programs which need to return to the program that invoked it. All LINKed to programs must have a RETURN command.


Syntax:

EXEC CICS LINK
    PROGRAM(name)
    COMMAREA(ws-area)
    LENGTH(ws-length)
END-EXEC.
  • PROGRAM

    Specified the name of the program to which is to be Linked. If the name is a literal, it should be enclosed in quotes. Program name can be unto eight characters long. The program must be defined in the PPT.

  • COMMAREA

    Optional parameter, specifying the data area containing the data to be passed to the LINKed to program. This option is required only if you want to pass information to the program being linked to.

  • LENGTH

    Specifies the length of the COMMAREA. This parameter is required only if COMMAREA is present. Like length parameters in other commands, it must be a half word binary.

Ws-length is length of ws-area and ws-area has the information that needs to be passed to LINK program.


Passing Data using LINK Command:

Data from the linking program to the linked to program can be passed using the COMMAREA option.

If the COMMAREA OPTION is used in the LINKing program, the area must be defined in the working storage section. In the LINKed program, the area must be defined as the first area in the linkage section, under the reserved name DFHCOMMAREA.

Passing data using CICS LINK command.jpg

The COMMAREA is shared between the two programs. When the LINKing program regains control, any changes made to the COMMAREA by the LINKed to program are accessible.

The WORKING STORAGE Section of the LINKing program is retained till its execution ends. But the Working storage of the LINKed to program is automatically released after the RETURN command.

Both the linking and the linked programs execute under the same task.


Example:

The below example shows how to use Link control command to pass the control to another program.

IDENTIFICATION DIVISION.
PROGRAM-ID. IBMMF.
WORKING-STORAGE SECTION.
01 WS-COMMAREA    PIC X(70).
PROCEDURE DIVISION.

EXEC CICS LINK
   PROGRAM('PROGRAM')
   COMMAREA(WS-COMMAREA)
   LENGTH(70)
END-EXEC.

Important CICS Interview Question:

Difference between LINK and XCTL?
XCTLLINK
XCTL does not expect control back LINK expects control back
Handle conditions in the main program are not available to the called program. Establish new handle conditions Handle conditions in the calling program are needed again. Hence use PUSH and POP commands to restore them again
XCTL does not expect control back and hence less overhead on system resources like memory etc. LINK expects control back and hence the overhead is more in this case on memory etc.
Similar to GO TO Similar to PERFORM, and control will be passed back to the instruction following this


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal