Containers are CICS objects that hold data and are used for passing information between programs, transactions, and across CICS regions. They provide a modern, flexible alternative to traditional COMMAREA data passing.
A container is a named data object that exists within a channel. Containers can hold any type of data - character, binary, or structured - and can be much larger than the 32KB limit of COMMARea. Multiple containers can exist on a single channel, allowing complex data structures to be passed between programs.
The COMMAREA (Communication Area) is limited to 32,767 bytes and can only pass a single data structure between programs. It's defined in the EXEC CICS LINK or XCTL command.
Containers overcome COMMAREA limitations by allowing:
Use the PUT CONTAINER command to create a new container or update an existing one:
12345EXEC CICS PUT CONTAINER('CUSTOMER-DATA') FROM(WS-CUSTOMER-RECORD) FLENGTH(LENGTH OF WS-CUSTOMER-RECORD) CHANNEL('ORDER-CHANNEL') END-EXEC.
Use the GET CONTAINER command to retrieve data from a container:
12345EXEC CICS GET CONTAINER('CUSTOMER-DATA') INTO(WS-CUSTOMER-RECORD) FLENGTH(WS-DATA-LENGTH) CHANNEL('ORDER-CHANNEL') END-EXEC.
Remove containers when they're no longer needed:
123EXEC CICS DELETE CONTAINER('TEMP-DATA') CHANNEL('WORK-CHANNEL') END-EXEC.
A channel is a collection of related containers. Channels provide a context for containers and can be passed between programs just like a COMMAREA.
When a program is invoked with a channel, that channel becomes the current channel. You don't need to specify the channel name in container commands if you're working with the current channel.
Channels are created implicitly when you put the first container or explicitly using:
12EXEC CICS GET CHANNEL('MY-CHANNEL') END-EXEC.
You can browse through all containers on a channel to discover what data is available:
123456789101112131415161718192021EXEC CICS STARTBROWSE CONTAINER BROWSETOKEN(WS-BROWSE-TOKEN) CHANNEL('ORDER-CHANNEL') END-EXEC. PERFORM UNTIL WS-END-OF-CONTAINERS EXEC CICS GETNEXT CONTAINER(WS-CONTAINER-NAME) BROWSETOKEN(WS-BROWSE-TOKEN) RESP(WS-RESPONSE) END-EXEC IF WS-RESPONSE = DFHRESP(END) SET WS-END-OF-CONTAINERS TO TRUE ELSE PERFORM PROCESS-CONTAINER END-IF END-PERFORM. EXEC CICS ENDBROWSE CONTAINER BROWSETOKEN(WS-BROWSE-TOKEN) END-EXEC.
Give containers descriptive names that indicate their purpose. Use a consistent naming convention across your applications.
Maintain documentation of what containers are used, their data structures, and which programs create or consume them.
Before accessing a container, check if it exists to avoid errors:
123456789EXEC CICS GET CONTAINER('OPTIONAL-DATA') INTO(WS-DATA) RESP(WS-RESPONSE) END-EXEC. IF WS-RESPONSE = DFHRESP(CONTAINERERR) * Container doesn't exist - use default values PERFORM SET-DEFAULT-VALUES END-IF.
Delete containers that are no longer needed to free up storage, especially in long-running transactions.
While containers can be very large, consider the performance impact of moving large amounts of data between programs. Use appropriate data sizes for your application needs.
Containers exist for the lifetime of the task (transaction) unless explicitly deleted. When the task ends, all containers are automatically deleted.
Containers can be passed between programs using LINK or XCTL commands. The channel containing the containers is passed as part of the program invocation.
Business Transaction Services (BTS) provides persistent containers that can survive beyond task termination and be accessed across different activities and processes.
Common container-related errors and how to handle them:
Returned when trying to access a container that doesn't exist. Check for this condition when working with optional containers.
Returned when the target area is too small for the container data. Determine the required length first using the FLENGTH option without specifying INTO.
Returned when the specified channel doesn't exist. Ensure the channel was created before accessing its containers.
Use PUT CONTAINER64 and GET CONTAINER64 commands for containers larger than 16MB, taking advantage of 64-bit addressing capabilities.
Specify DATATYPE(CHAR) or DATATYPE(BIT) to indicate the type of data in a container, which can affect how the data is converted when sent across systems with different codepages.
CICS can automatically convert character data between different codepages when containers are passed between systems. Use FROMCCSID and TOCCSID options to control conversion.