Constructing and using a channel: an example

Figure 1 shows a CICS® client program that:
  1. Uses EXEC CICS PUT CONTAINER commands to construct (and put data in) a set of containers. The containers are all part of the same named channel—"payroll-2004".
  2. Issues an EXEC CICS LINK command to invoke the PAYR server program, passing it the payroll-2004 channel.
  3. Issues an EXEC CICS GET CONTAINER command to retrieve the server's program output, which it knows will be in the status container of the payroll-2004 channel.
Figure 1. How a client program can construct a channel, pass it to a server program, and retrieve the server's output

* create the employee container on the payroll-2004 channel
EXEC CICS PUT CONTAINER('employee') CHANNEL('payroll-2004') FROM('John Doe')

* create the wage container on the payroll-2004 channel
EXEC CICS PUT CONTAINER('wage') CHANNEL('payroll-2004') FROM('100')

* invoke the payroll service, passing the payroll-2004 channel
EXEC CICS LINK PROGRAM('PAYR') CHANNEL('payroll-2004')

* examine the status returned on the payroll-2004 channel
EXEC CICS GET CONTAINER('status') CHANNEL('payroll-2004') INTO(stat)
Figure 2 shows part of the PAYR server program invoked by the client. The server program:
  1. Queries the channel with which it's been invoked.
  2. Issues EXEC CICS GET CONTAINER commands to retrieve the input from the employee and wage containers of the payroll-2004 channel.
  3. Processes the input data.
  4. Issues an EXEC CICS PUT CONTAINER command to return its output in the status container of the payroll-2004 channel.
Figure 2. How a server program can query the channel it's been passed, retrieve data from the channel's containers, and return output to the caller
        
"PAYR", CICS COBOL server program

* discover which channel I've been invoked with
EXEC CICS ASSIGN CHANNEL(ch_name)
:
WHEN ch_name 'payroll-2004'
    * my current channel is "payroll-2004"
    * get the employee passed into this program
    EXEC CICS GET CONTAINER('employee') INTO(emp)
    * get the wage for this employee 
    EXEC CICS GET CONTAINER('wage') INTO(wge)
    :
    * process the input data
    :
    :
    * return the status to the caller by creating the status container
    * on the payroll channel and putting a value in it
    EXEC CICS PUT CONTAINER('status') FROM('OK')
    :
    :
WHEN ch_name 'payroll-2005'
    * my current channel is "payroll-2005"
    :
    :
    :