COMMAREA


The COMMAREA (Communication Area) is a memory area used to pass data between programs or between different executions of a transaction. It is primarily used for inter-program communication in CICS applications.

Usage of COMMAREA -

COMMAREA is typically used in two scenarios:

  • Passing data between two programs (via LINK or XCTL commands).
  • Retaining data between multiple invocations of the same transaction (via RETURN TRANSID).

Using COMMAREA for Program-to-Program Communication -


When one CICS program calls another, it can pass a COMMAREA. The receiving program accesses this data area for processing.

Scenario - Passing COMMAREA using LINK

Calling Program (PROGRAM1)

...
WORKING-STORAGE SECTION.
01 WS-COMMAREA  PIC X(100).

PROCEDURE DIVISION.
    ...

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

    ...

Receiving Program (PROGRAM2)

...
LINKAGE SECTION.
01 DFHCOMMAREA  PIC X(100).

PROCEDURE DIVISION.
    MOVE DFHCOMMAREA TO WS-COMMAREA.
    ...

Using COMMAREA for Transaction-to-Transaction Communication -


A CICS program can pass COMMAREA from one execution to another using RETURN TRANSID.

Scenario - Passing COMMAREA between Transactions

Calling Program (PROGRAM1)

...
WORKING-STORAGE SECTION.
01 WS-COMMAREA  PIC X(100).

PROCEDURE DIVISION.
    ...

    EXEC CICS RETURN
        TRANSID('TRX2')
        COMMAREA(WS-COMMAREA)
        LENGTH(100)
        END-EXEC.

    ...

Receiving Program (PROGRAM2)

...
LINKAGE SECTION.
01 DFHCOMMAREA  PIC X(100).

PROCEDURE DIVISION.
    MOVE DFHCOMMAREA TO WS-COMMAREA.
    ...

Important things to note -

  • The maximum length of data that can be passed through COMMAREA is 64 kilobytes (KB), but it is recommended to limit the size to 24 KB to ensure optimal performance.
  • COMMAREA can be utilized with the LINK, XCTL, and RETURN commands.
  • The programs involved in communication can define the COMMAREA either in the WORKING-STORAGE SECTION or the LINKAGE SECTION, depending on their hierarchy level. The first program that creates the COMMAREA can define it in the WORKING-STORAGE SECTION, while the subsequent programs should declare it in the LINKAGE SECTION.
  • The receiving data area can be the same length as, or shorter than, the original communication area, but it must not exceed the original length.
  • If the receiving data area is longer than the original communication area, there is a risk that the transaction may attempt to read or write data outside the allocated area, potentially causing CICS to abend. To avoid this issue, it's essential to check the length of the COMMAREA by comparing EIBCALEN with the data area length specified in the LENGTH option of the LINK, XCTL, or RETURN command.

Size and Limitations -


  • Once created, it cannot be expanded: The receiving program cannot increase the size of the COMMAREA.
  • If COMMAREA is Not Passed, DFHCOMMAREA is Not Allocated: The receiving program must check if COMMAREA was received.