Containers are named blocks of data designed for passing information between programs. You can think of them as "named communication areas (COMMAREAs)". Programs can pass any number of containers between each other. Containers are grouped together in sets called channels. A channel is analogous to a parameter list.
To create named containers and assign them to a channel, a program uses EXEC CICS PUT CONTAINER(container-name) CHANNEL(channel-name) commands. It can then pass the channel (and its containers) to a second program using the CHANNEL(channel-name) option of the EXEC CICS LINK, XCTL, START, or RETURN commands.
The second program can read containers passed to it using the EXEC CICS GET CONTAINER(container-name) command. This command reads the named container belonging to the channel that the program was invoked with.
If the second program is invoked by a LINK command, it can also return containers to the calling program. It can do this by creating new containers, or by reusing existing containers.
Channels and containers are visible only to the program that creates them and the programs they are passed to. When these programs terminate, CICS automatically destroys the containers and their storage.
Channel containers are not recoverable. If you need to use recoverable containers, use CICS business transaction services (BTS) containers. The relationship between channel and BTS containers is described in Channels and BTS activities.
Figure 41 shows a COBOL program, CLIENT1, that:
Note that the same COBOL copybook, INQINTC, is used by both the client and server programs. Line 3 and lines 5 through 7 of the copybook represent the INQUIRY-CHANNEL and its containers. These lines are not strictly necessary to the working of the programs, because containers and channels are created simply by being named (on, for example, PUT CONTAINER commands); they do not have to be defined. However, the inclusion of these lines in the copybook used by both programs makes for easier maintenance; they record the names of the containers used.
For ease of maintenance of a client/server application that uses a channel, create a copybook that records the names of the containers used and defines the data fields that map to the containers. Include the copybook in both the client and the server program.
IDENTIFICATION DIVISION.
PROGRAM-ID. CLIENT1.
WORKING-STORAGE SECTION.
COPY INQINTC
* copybook INQINTC
* Channel name
* 01 INQUIRY-CHANNEL PIC X(16) VALUE 'inqcustrec'.
* Container names
* 01 CUSTOMER-NO PIC X(16) VALUE 'custno'.
* 01 BRANCH-NO PIC X(16) VALUE 'branchno'.
* 01 CUSTOMER-RECORD PIC X(16) VALUE 'custrec'.
* Define the data fields used by the program
* 01 CUSTNO PIC X(8).
* 01 BRANCHNO PIC X(5).
* 01 CREC.
* 02 CUSTNAME PIC X(80).
* 02 CUSTADDR1 PIC X(80).
* 02 CUSTADDR2 PIC X(80).
* 02 CUSTADDR3 PIC X(80).
PROCEDURE DIVISION.
MAIN-PROCESSING SECTION.
*
* INITIALISE CUSTOMER RECORD
*
... CREATE CUSTNO and BRANCHNO
*
* GET CUSTOMER RECORD
*
EXEC CICS PUT CONTAINER(CUSTOMER-NO) CHANNEL(INQUIRY-CHANNEL)
FROM(CUSTNO) FLENGTH(LENGTH OF CUSTNO)
END-EXEC
EXEC CICS PUT CONTAINER(BRANCH-NO) CHANNEL(INQUIRY-CHANNEL)
FROM(BRANCHNO) FLENGTH(LENGTH OF BRANCHNO)
END-EXEC
EXEC CICS LINK PROGRAM('SERVER1') CHANNEL(INQUIRY-CHANNEL) END-EXEC
EXEC CICS GET CONTAINER(CUSTOMER-RECORD) CHANNEL(INQUIRY-CHANNEL)
INTO(CREC) END-EXEC
*
* PROCESS CUSTOMER RECORD
*
... FURTHER PROCESSING USING CUSTNAME and CUSTADDR1 etc...
EXEC CICS RETURN END-EXEC
EXIT.
Figure 42 shows the SERVER1 program linked to by CLIENT1. SERVER1 retrieves the data from the custno and branchno containers it has been passed, and uses it to locate the full customer record in its database. It then creates a new container, custrec, on the same channel, and returns the customer record in it.
Note that the programmer hasn't specified the CHANNEL keyword on the GET and PUT commands in SERVER1: if the channel isn't specified explicitly, the current channel is used--that is, the channel that the program was invoked with.
IDENTIFICATION DIVISION.
PROGRAM-ID. SERVER1.
WORKING-STORAGE SECTION.
COPY INQINTC
* copybook INQINTC
* Channel name
* 01 INQUIRY-CHANNEL PIC X(16) VALUE 'inqcustrec'.
* Container names
* 01 CUSTOMER-NO PIC X(16) VALUE 'custno'.
* 01 BRANCH-NO PIC X(16) VALUE 'branchno'.
* 01 CUSTOMER-RECORD PIC X(16) VALUE 'custrec'.
* Define the data fields used by the program
* 01 CUSTNO PIC X(8).
* 01 BRANCHNO PIC X(5).
* 01 CREC.
* 02 CUSTNAME PIC X(80).
* 02 CUSTADDR1 PIC X(80).
* 02 CUSTADDR2 PIC X(80).
* 02 CUSTADDR3 PIC X(80).
PROCEDURE DIVISION.
MAIN-PROCESSING SECTION.
EXEC CICS GET CONTAINER(CUSTOMER-NO)
INTO(CUSTNO) END-EXEC
EXEC CICS GET CONTAINER(BRANCH-NO)
INTO(BRANCHNO) END-EXEC
... USE CUSTNO AND BRANCHNO TO FIND CREC IN A DATABASE
EXEC CICS PUT CONTAINER(CUSTOMER-RECORD)
FROM(CREC)
FLENGTH(LENGTH OF CREC) END-EXEC
EXEC CICS RETURN END-EXEC
EXIT.