Sunteți pe pagina 1din 6

3/7/2017 Basicexamples

Basic examples
Version 5.2.0

A simple example of a program that creates a channel and passes it to second program.

Figure 1 shows a COBOL program, CLIENT1, that:


1. Uses PUT CONTAINER(container-name) CHANNEL(channel-name) commands to create a channel called inqcustrec and add two
containers, custno and branchno, to it; these contain a customer number and a branch number, respectively.

2. Uses a LINK PROGRAM(program-name) CHANNEL(channel-name) command to link to program SERVER1, passing the inqcustrec
channel.

3. Uses a GET CONTAINER(container-name) CHANNEL(channel-name) command to retrieve the customer record returned by SERVER1.
The customer record is in the custrec container of the inqcustrec channel.

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 INQUIRYCHANNEL and its containers. These lines are not strictly necessary to the working of the programs, because channels
and containers are created by being named on, for example, PUTCONTAINER commands; they do not have to be dened. 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.

Recommendation
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 denes the data elds that map to the containers. Include the copybook in both the client and the server program.

https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 1/6
3/7/2017 Basicexamples

Note

This example shows two COBOL programs. The same techniques can be used in any of the other languages supported by CICS.
However, for COBOL programs only, if the server program uses the SET option (instead of INTO) on the EXECCICSGETCONTAINER
command, the structure of the storage pointed to by SET must be dened in the LINKAGE section of the program. This means that you
will require two copybooks rather than one. The rst, in the WORKING-STORAGE section of the program, names the channel and
containers used. The second, in the LINKAGE section, denes the storage structure.

Figure 1. A simple example of a program that creates a channel and passes it to a second program

IDENTIFICATIONDIVISION.
PROGRAMID.CLIENT1.

WORKINGSTORAGESECTION.

COPYINQINTC
*copybookINQINTC
*Channelname
*01INQUIRYCHANNELPICX(16)VALUE'inqcustrec'.
*Containernames
*01CUSTOMERNOPICX(16)VALUE'custno'.
*01BRANCHNOPICX(16)VALUE'branchno'.
*01CUSTOMERRECORDPICX(16)VALUE'custrec'.
*Definethedatafieldsusedbytheprogram
*01CUSTNOPICX(8).
*01BRANCHNOPICX(5).

https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 2/6
3/7/2017 Basicexamples

*01CREC.
*02CUSTNAMEPICX(80).
*02CUSTADDR1PICX(80).
*02CUSTADDR2PICX(80).
*02CUSTADDR3PICX(80).

PROCEDUREDIVISION.
MAINPROCESSINGSECTION.

*
*INITIALISECUSTOMERRECORD
*
...CREATECUSTNOandBRANCHNO
*
*GETCUSTOMERRECORD
*
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

https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 3/6
3/7/2017 Basicexamples

*
*PROCESSCUSTOMERRECORD
*
...FURTHERPROCESSINGUSINGCUSTNAMEandCUSTADDR1etc...

EXECCICSRETURNENDEXEC

EXIT.

Figure 2 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 specied the CHANNEL keyword on the GET and PUT commands in SERVER1: if the channel isn't specied
explicitly, the current channel is usedthat is, the channel that the program was invoked with.
Figure 2. A simple example of a linked to program that retrieves data from the channel it has been passed. This program is linked-to by
program CLIENT1 shown in Figure 1.

IDENTIFICATIONDIVISION.
PROGRAMID.SERVER1.

WORKINGSTORAGESECTION.

COPYINQINTC
*copybookINQINTC
*Channelname
*01INQUIRYCHANNELPICX(16)VALUE'inqcustrec'.
https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 4/6
3/7/2017 Basicexamples

*Containernames
*01CUSTOMERNOPICX(16)VALUE'custno'.
*01BRANCHNOPICX(16)VALUE'branchno'.
*01CUSTOMERRECORDPICX(16)VALUE'custrec'.
*Definethedatafieldsusedbytheprogram
*01CUSTNOPICX(8).
*01BRANCHNOPICX(5).
*01CREC.
*02CUSTNAMEPICX(80).
*02CUSTADDR1PICX(80).
*02CUSTADDR2PICX(80).
*02CUSTADDR3PICX(80).

PROCEDUREDIVISION.
MAINPROCESSINGSECTION.

EXEC CICS GET CONTAINER(CUSTOMER-NO)


INTO(CUSTNO) END-EXEC
EXEC CICS GET CONTAINER(BRANCH-NO)
INTO(BRANCHNO) END-EXEC

...USECUSTNOANDBRANCHNOTOFINDCRECINADATABASE

EXEC CICS PUT CONTAINER(CUSTOMER-RECORD)


FROM(CREC)
FLENGTH(LENGTH OF CREC) END-EXEC

EXECCICSRETURNENDEXEC
https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 5/6
3/7/2017 Basicexamples

EXIT.

Parent topic:
Channels: quick start

dfhp3_ch04.html | Last updated: Thursday, 12 January 2017

https://www.ibm.com/support/knowledgecenter/en/SSGMCP_5.2.0/com.ibm.cics.ts.applicationprogramming.doc/topics/dfhp3_ch04.html 6/6

S-ar putea să vă placă și