You are on page 1of 101

Advanced CICS

Version 2 SPI Confidential 1


Contents
A. Coding CICS Program
B. Sample Program
C. Temporary storage control
D. Some more CICS commands &
programming techniques
E. Processing files sequentially
F. More CICS control features
G. Legacy coding conventions

Version 2 SPI Confidential 2


A. Coding CICS Program

Version 2 SPI Confidential 3


A01 How to code a CICS program

• How to control the execution of the


programs within a task
• How to work with mapsets
• How to work with files
• Other coding essentials

Version 2 SPI Confidential 4


How to control the execution of the
A02
programs within a task
• The operation of program control
commands
• RETURN command
• XCTL command
• LINK command
• COBOL CALL statement
• ABEND command

Version 2 SPI Confidential 5


A02a
The operation of program control
commands

Version 2 SPI Confidential 6


A02a1 Flow of control between programs and subprograms

Version 2 SPI Confidential 7


A02b RETURN command

Version 2 SPI Confidential 8


A02c XCTL command

Version 2 SPI Confidential 9


A02d LINK command

Version 2 SPI Confidential 10


A02e COBOL CALL statement

Syntax:
CALL (‘subprogram-name | data-area)
[USING identifier-1 …]

Example:
MOVE COMMUNICATION-AREA TO
DFHCOMMAREA.
CALL ‘GETINV’ USING DFHEIBLK,
DFHCOMMAREA, INV-INVOICE-NUMBER.

Version 2 SPI Confidential 11


A02f ABEND command

Syntax:
EXEC CICS
ABEND [ABCODE (abend-code)]
[NODUMP]
END-EXEC

Version 2 SPI Confidential 12


A03 How to work with mapsets
Syntax of SEND MAP
EXEC CICS
SEND MAP (map-name)
[MAPSET(mapset-name)]
[FROM (data-name)]
[MAPONLY | DATAONLY]
[ERASE | ERASEAUP]
[ALARM]
[CURSOR [(data-value)]]
END-EXEC

Syntax of RECEIVE MAP


EXEC CICS
RECEIVE MAP(map-name)
[MAPSET(mapset-name)]
[INTO (data-name)]
END-EXEC

Version 2 SPI Confidential 13


A04 How to work with files

• READ command
• WRITE command
• REWRITE command
• DELETE command
• UNLOCK command

Version 2 SPI Confidential 14


A04a
READ command
Syntax:
EXEC CICS
READ FILE (filename)
INTO (data-name)
RIDFLD (data-name)
[RRN | RBA]
[UPDATE]
END-EXEC

Example:
EXEC CICS
READ FILE (‘CUSTMAS’)
INTO (CUSTOMER-MASTER-RECORD)
RIDFLD (CM-CUSTOMER-NUMBER)
UPDATE
RESP(RESPONSE-CODE)
END-EXEC

Version 2 SPI Confidential 15


A04b
WRITE command
Syntax:
EXEC CICS
WRITE FILE (filename)
FROM (data-name)
RIDFLD (data-name)
[RRN | RBA]
END-EXEC

Example:
EXEC CICS
WRITE FILE (‘CUSTMAS’)
INTO (CUSTOMER-MASTER-RECORD)
RIDFLD (CM-CUSTOMER-NUMBER)
RESP(RESPONSE-CODE)
END-EXEC

Version 2 SPI Confidential 16


A04c
REWRITE command
Syntax:
EXEC CICS
REWRITE FILE (filename)
FROM (data-name)
END-EXEC

Example:
EXEC CICS
REWRITE FILE (‘CUSTMAS’)
FROM (CUSTOMER-MASTER-RECORD)
RESP(RESPONSE-CODE)
END-EXEC

Version 2 SPI Confidential 17


A04d
DELETE command
Syntax:
EXEC CICS
DELETE FILE (filename)
RIDFLD (data-name)
[RRN | RBA]
END-EXEC

Example (record previously read for update):


EXEC CICS
DELETE FILE (‘CUSTMAS’)
RESP(RESPONSE-CODE)
END-EXEC

Example (record not previously read for update):


EXEC CICS
DELETE FILE (‘CUSTMAS’)
RIDFLD (CUSTOMER-MASTER-RECORD)
RESP(RESPONSE-CODE)
END-EXEC

Version 2 SPI Confidential 18


A04e
UNLOCK command
Syntax:
EXEC CICS
UNLOCK FILE (filename)
END-EXEC

Example:
EXEC CICS
UNLOCK FILE (‘CUSTMAS’)
END-EXEC
Version 2 SPI Confidential 19
A04f Potential problems when updating file

• One program changes or deletes a


record while another is trying to
update it
• Deadlock: Two tasks are each
waiting for a resource that the other
is holding.

Version 2 SPI Confidential 20


A05 Other coding essentials

• Common exceptional conditions


• Using response code
• Defining communication area
• Managing event context of a
program

Version 2 SPI Confidential 21


A05a
Common exceptional conditions

Version 2 SPI Confidential 22


A05b Using response code
Syntax:
[RESP (data-name)]

Example:
EXEC CICS
READ FILE (‘CUSTMAS’)
INTO (CUSTOMER-MASTER-RECORD)
RIDFLD (CM-CUSTOMER-NUMBER)
RESP(RESPONSE-CODE)
END-EXEC

EVALUATE RESPONSE-CODE
WHEN DFHRESP(NORMAL)
MOVE input-fields TO display-area
WHEN DFHRESP(NOTFND)
MOVE “Customer does not exist” TO message-display-area
WHEN OTHER
EXEC CICS
ABEND
END-EXEC
END-EVALUATE

Version 2 SPI Confidential 23


A05c Defining communication area
01 COMMUNICATION-AREA.
05 CA-CONTEXT-FLAG PIC X.
88 PROCESS-KEY-MAP VALUE ‘1’.
88 PROCESS-ADD-CUSTOMER VALUE ‘2’.
88 PROCESS-CHANGE-CUSTOMER VALUE ‘3’.
88 PROCESS-DEL-CUSTOMER VALUE ‘4’.
05 CA-CUSTOMER-RECORD.
10 CA-CUSTOMER-NUMBER PIC X(6).
10 FILLER PIC X(112).

Version 2 SPI Confidential 24


A05d
Sample Program (Requirement)

Version 2 SPI Confidential 25


Event/response chart
A05e

Version 2 SPI Confidential 26


A05f
Managing event context of a program

Version 2 SPI Confidential 27


B. Sample CICS Program

Version 2 SPI Confidential 28


B01
Structure chart

Version 2 SPI Confidential 29


B02a
Program code

Version 2 SPI Confidential 30


B02b
Program code (contd.)

Version 2 SPI Confidential 31


B02c
Program code (contd.)

Version 2 SPI Confidential 32


B02d
Program code (contd.)

Version 2 SPI Confidential 33


B02e
Program code (contd.)

Version 2 SPI Confidential 34


B02f
Program code (contd.)

Version 2 SPI Confidential 35


B02g
Program code (contd.)

Version 2 SPI Confidential 36


B02h
Program code (contd.)

Version 2 SPI Confidential 37


C. Temporary storage control

Version 2 SPI Confidential 38


C01
Temporary storage queue concepts

Version 2 SPI Confidential 39


C02
WRITEQ TS command

Syntax: Example:
Add record to TSQ
EXEC CICS EXEC CICS
WRITEQ TS {QUEUE | QNAME} (queue-name) WRITEQ TS QUEUE (TS-QUEUE-NAME)
FROM (data-name) FROM (TS-QUEUE-
[ITEM (data-name) RECORD)
REWRITE] END-EXEC
[NUMITEMS(data-name)]
[MAIN | AUXILIARY]
END-EXEC
Update an existing record in TSQ
EXEC CICS
WRITEQ TS QUEUE (TS-QUEUE-NAME)
FROM (TS-QUEUE-
RECORD)
ITEM (TS-ITEM-
NUMBER)
REWRITE
RESP (RESPONSE-CODE
END-EXEC
Version 2 SPI Confidential 40
C03
READQ TS command

Syntax: Example:
Read a record from TSQ randomly
EXEC CICS EXEC CICS
READQ TS { QUEUE | QNAME} (queue-name) READQ TS QUEUE (TS-QUEUE-NAME)
INTO (data-name) INTO (TS-QUEUE-
[ ITEM (data-name) | RECORD)
literal | ITEM (TS-ITEM-NUMBER)
NEXT ] RESP (RESPONSE-CODE)
[ NUMITEMS (data-name) ] END-EXEC
END-EXEC

Read the next record from TSQ


EXEC CICS
READQ TS QUEUE (TS-QUEUE-NAME)
INTO (TS-QUEUE-
RECORD)
NEXT
END-EXEC

Version 2 SPI Confidential 41


C04
DELETEQ TS command

Syntax: Example:
Delete a TSQ
EXEC CICS EXEC CICS
DELETEQ TS { QUEUE | QNAME} (queue-name) DELETEQ TS
END-EXEC QUEUE (TS-QUEUE-
NAME)
RESP (RESPONSE-
CODE
END-EXEC

Version 2 SPI Confidential 42


C05a Sample program using TSQ

Version 2 SPI Confidential 43


C05b Sample program using TSQ (contd.)

Version 2 SPI Confidential 44


C05c Sample program using TSQ (contd.)

Version 2 SPI Confidential 45


Temporary storage command -
CEBR
The CEBR command lets one browse the contents of a temporary
storage queue which may be required while testing a program.

The syntax is as follows: CEBR (queue-name)

This brings up the details of the queue specified in the queue-name


option, as shown below.

Version 2 SPI Confidential 46


D. Some more CICS commands
& programming techniques

Version 2 SPI Confidential 47


Some more CICS commands &
D01
programming techniques
• Terminal handling techniques
– Positioning the cursor
– Modifying field attributes
– Optimizing data transmission
– Identifying data entry fields
– Editing input data
– Editing numeric data
– Sample programs that edit numeric data
– Using SEND TEXT command
• Handling unrecoverable errors
– Invoking a general error handling program
– COBOL code for general error handling
• Accessing data using Linkage Section
– Using fields in the EIB
– Accessing CICS areas
• Formatting date & time
– Using ASKTIME command
– Using FORMATTIME command

Version 2 SPI Confidential 48


Terminal handling techniques:
D02a
Positioning the cursor
Using IC option in DFHMDF
CUSTNO DFHMDF POS=(2,26), X
LENGTH=6, X
ATTRB=(NORM, UNPROT, IC), X
...

Using direct cursor positioning


EXEC CICS
SEND MAP (‘MNTMAP1’)
MAPSET(‘MNTSET1’)
FROM(MNTMAP1O)
CURSOR(346)
END-EXEC

Using symbolic cursor positioning


MOVE -1 TO CUSTNOIL.

EXEC CICS
SEND MAP (‘MNTMAP1’)
MAPSET(‘MNTSET1’)
FROM(MNTMAP1O)
CURSOR
END-EXEC

Version 2 SPI Confidential 49


Terminal handling techniques:
D02b1 Modifying field attributes

Version 2 SPI Confidential 50


Terminal handling techniques:
D02b2
Modifying field attributes

Version 2 SPI Confidential 51


D02c1
Terminal handling techniques:
Optimizing data transmission
Minimize data sent from
program to terminal
Move Low-Value
to symbolic map
fields present on
screen and should
remain unchanged
Use DATAONLY
with SEND MAP
when sending data
using a map
already onscreen

Version 2 SPI Confidential 52


D02c2
Terminal handling techniques:
Optimizing data transmission (contd.)
Minimize data sent to program when user presses attention key
Maintain copy of screen-fields in CA
Specifying FRSET on SEND MAP to turn off the MDT of all
unprotected fields
After issuing RECEIVE MAP, merge new entries with fields
saved in CA from previous transmission

Version 2 SPI Confidential 53


D02d1
Terminal handling techniques:
Screen format recommendations

Version 2 SPI Confidential 54


D02d2
Terminal handling techniques:
Screen format recommendations

Version 2 SPI Confidential 55


D02d3
Terminal handling techniques:
Identifying data entry fields

Version 2 SPI Confidential 56


Terminal handling techniques:
D02e
Editing input data

Version 2 SPI Confidential 57


D02f
Terminal handling techniques:
Editing numeric data

Version 2 SPI Confidential 58


D02g1 Terminal handling techniques:
Sample program that edits numeric data (INTEDIT)

Version 2 SPI Confidential 59


D02g2a Terminal handling techniques:
Sample program that edits numeric data (NUMEDIT)

Version 2 SPI Confidential 60


D02g2b Terminal handling techniques:
Sample program that edits numeric data (NUMEDIT)

Version 2 SPI Confidential 61


Terminal handling techniques:
D02h
Using SEND TEXT command
Syntax:
EXEC CICS
SEND TEXT FROM (data-name)
[ERASE]
[FREEKB]
END-EXEC

Example:
WORKING-STORAGE SECTION.
01 TERMINATION-MESSAGE PIC X(14) VALUE “Session ended”.
.
.
PROCEDURE DIVISION.
.
.
EXEC CICS
SEND TEXT FROM (TERMINATION-MESSAGE)
ERASE
FREEKB
END-EXEC

Version 2 SPI Confidential 62


D03a Handling unrecoverable errors:
Invoking a general error handling program

Version 2 SPI Confidential 63


D03b Handling unrecoverable errors:
COBOL code for general error handling

Version 2 SPI Confidential 64


D04a
Accessing data using Linkage Section
Using fields in the EIB

Version 2 SPI Confidential 65


Accessing data using Linkage Section
D04b
Accessing CICS areas

Syntax: Sample:

LINKAGE SECTION.
EXEC CICS
*
ADDRESS [CWA (pointer)]
01 DFHCOMMAREA PIC X.
[TWA (pointer)] *
[TCTUA (pointer)] 01 COMMON-WORK-AREA.
END-EXEC 05 CWA-CURRENT-DATE PIC X(8).
05 CWA-COMPANY-NAME PIC X(30).
*
PROCEDURE DIVISION.
*
.
.
EXEC CICS
ADDRESS CWA (ADDRESS OF COMMON-WORK-
AREA)
END-EXEC.
MOVE CWA-COMPANY-NAME TO COMPO.

Version 2 SPI Confidential 66


D05a
Formatting date & time
Using ASKTIME command

SYNTAX: Sample:
WORKING-STORAGE SECTION.
EXEC CICS
.
ASKTIME [ABSTIME (data-name)
END-EXEC .
01 DATE-AND-TIME-FIELDS.
05 ABSOLUTE-TIME PIC S9(15) COMP-3.
.
.
PROCEDURE DIVISION.
.
.
EXEC CICS
ASKTIME ABSTIME (ABSOLUTE-
TIME))
END-EXEC.
.
.

Version 2 SPI Confidential 67


Formatting date & time
D05b1 Using FORMATTIME command

Version 2 SPI Confidential 68


Formatting date & time
D05b2 Using FORMATTIME command (contd.)

Version 2 SPI Confidential 69


D05b3
Formatting date & time
Using FORMATTIME command (contd.)

Samples
Format default date & time
EXEC CICS
FORMATTIME ABSTIME (ABSOLUTE-TIME)
DATE(WS-DATE)
DATESEP
TIME(WS-TIME)
TIMESEP
END-EXEC

Format dd-mm-yyyy date


EXEC CICS
FORMATTIME ABSTIME (ABSOLUTE-TIME)
DDMMYYYY(WS-FULL-DATE)
DATESEP(‘-’)
END-EXEC

Version 2 SPI Confidential 70


E. Processing files sequentially

Version 2 SPI Confidential 71


E01 Processing files sequentially

• STARTBR
• READNEXT & READPREV
• ENDBR
• RESETBR

Version 2 SPI Confidential 72


E02a
Processing files sequentially
STARTBR

Syntax of STARTBR
EXEC CICS
STARTBR FILE(filename)
RIDFLD(data-name)
[RRN | RBA]
[GTEQ | EQUAL]
[GENERIC]
[KEYLENGTH (data-name) | literal]
END-EXEC

Sample of STARTBR
EXEC CICS
STARTBR FILE(‘CUSTMAS’)
RIDFLD(CM-CUSTOMER-NUMBER)
RESP(RESPONSE-CODE)
END-EXEC

Version 2 SPI Confidential 73


E02b Processing files sequentially
Controlling STARTBR position

Version 2 SPI Confidential 74


E03a
Processing files sequentially
READNEXT & READPREV

Syntax of READNEXT & READPREV

EXEC CICS
[READNEXT | READPREV] FILE(filename)
INTO(data-name)
RIDFLD(data-name)
[RRN | RBA]
[KEYLENGTH (data-name) | literal]
END-EXEC

Version 2 SPI Confidential 75


E03b Processing files sequentially
A typical READNEXT procedure

Version 2 SPI Confidential 76


E04
Processing files sequentially
ENDBR
Syntax of ENDBR

EXEC CICS
ENDBR FILE(filename)
END-EXEC

Sample
EXEC CICS
ENDBR FILE(‘INVOICE’)
END-EXEC

Version 2 SPI Confidential 77


E05
Processing files sequentially
RESETBR

Syntax of RESETBR
EXEC CICS
RESETBR FILE(filename)
RIDFLD(data-name)
[RRN | RBA]
[GTEQ | EQUAL]
[GENERIC]
[KEYLENGTH (data-name | literal)]

END-EXEC

Sample
EXEC CICS
RESETBR FILE(‘CUSTMAS’)
RIDFLD(CM-CUSTOMER-NUMBER)
EQUAL
RESP(RESPONSE-CODE)
END-EXEC
Version 2 SPI Confidential 78
E06 Processing files sequentially
Exceptional conditions

Version 2 SPI Confidential 79


F. More CICS control features

Version 2 SPI Confidential 80


F01 More CICS control features
• Interval control
– Automatic time-ordered transaction
– START
– RETRIEVE
– CANCEL
– DELAY
• Task control
– SUSPEND
– ENQ & DEQ
• Storage control
– GETMAIN
– FREEMAIN
Version 2 SPI Confidential 81
F02a Interval control
Automatic time-ordered transaction initiation

Version 2 SPI Confidential 82


F02b Interval control
Automatic time-ordered transaction initiation (contd.)

Version 2 SPI Confidential 83


F03a Interval control
START

Version 2 SPI Confidential 84


F03b Interval control
START examples

Version 2 SPI Confidential 85


F04
Interval control
RETRIEVE
Syntax of RETRIEVE
EXEC CICS
RETRIEVE INTO(data-name)
[RTRANSID(data-name)]
[RTERMID(data-name)]
[QUEUE(data-name)]
END-EXEC

Sample
EXEC CICS
RETRIEVE INTO(ITEM-NUMBER)
RESP(RESPONSE-CODE)
END-EXEC

Ref:
EXEC CICS
START TRANSID(‘LST1’)
FROM(ITEM-NUMBER)
END-EXEC

Version 2 SPI Confidential 86


F05
Interval control
CANCEL
Syntax of CANCEL
EXEC CICS
CANCEL REQID(request-id)
END-EXEC

Version 2 SPI Confidential 87


F06a
Interval Control
DELAY - syntax
EXEC CICS
DELAY ( (INTERVAL(HHMMSS) )
(TIME(HHMMSS) )
(FOR (HOURS (HH)) (MINUTES(MM)) (SECONDS(SS)) )
(UNTIL (HOURS (HH)) (MINUTES(MM)) (SECONDS(SS)) )
(REQID (name))
END-EXEC.

INTERVAL : A 7 digit packed decimal (PIC S9(7) COMP-3) specifies the duration for delay
coded in the form of HHMMSS
TIME : A 7 digit packed decimal (PIC S9(7) COMP-3) specifies the time of the day when
the delay will end coded in the form of HHMMSS
FOR : Specifies that the HOURS,MINUTES and SECONDS options indicate a duration for
the delay.
UNTIL: Specifies that the HOURS,MINUTES and SECONDS options indicate a time of the
day when th DELAY will end.
HOURS : Specifies PIC S9(8)COMP in the range of 0 to 99
MINUTES: Specifies PIC S9(8)COMP in the range of 0 to 59
SECONDS: Specifies PIC S9(8)COMP in the range of 0 to 99
REQID : Specifies a 1-8 character request indenitifier that is associated with the DELAY
command.

Version 2 SPI Confidential 88


F06b
Interval Control
DELAY – contd.
The Delay command helps in suspending the task until a specified
time interval has elapsed or a specified time of day has arrived.
This is not used widely as there are not much good uses of this
command.
In some cases it might be necessary to force a minimum response
time on terminal transactions, and in such cases DELAY command
can be used.

Issue a DELAY command just before the SEND MAP command by


specifying the time limit in the TIME or UNTIL option. A better
alternative is to use POST,WAIT command.

The DELAY command can be used in one more possible area, i.e
when the program needs to retry an operation after a failure
allowing time for the operator to correct the problem that caused
the failure. In this case the task can be delayed for some time say
15 second before the retrying the operation. But make sure to
limit the number of retries so that the task doesn't wait
indefinitely.

Version 2 SPI Confidential 89


F06c
Interval Control
DELAY – contd.
There are two ways to use the HOURS,MINUTES,SECONDS options following
the FOR option.
If used in combination the ranges are 0-99 for hours, 0-59 for minutes and 0-
59 for seconds, if a single option is specified then a larger range can be
specified.
For Ex: FOR Minutes(1) Seconds(30) cane also be specified as SECONDS(90).

If the REQID option is used, then make sure to pass the request identifier
value to the other programs so that they can be used to CANCEL the
DELAY request.

POST and WAIT commands also achieve the same result.


The CANCEL command specified with the same request ID will
terminate/cancel the already issued DLEAY or POST command.

EXEC CICS CANCEL


REQID(id)
END-EXEC.

Version 2 SPI Confidential 90


F07
Task Control
SUSPEND.

Syntax

EXEC CICS
SUSPEND
END-EXEC

Version 2 SPI Confidential 91


F08
Task Control
ENQ and DEQ.
Syntax
EXEC CICS
{ENQ | DEQ} RESOURCE(data-name)
END-EXEC

Samples
EXEC CICS
ENQ RESOURCE(DSTINATION-ID)
END-EXEC

EXEC CICS
DEQ RESOURCE(DSTINATION-ID)
END-EXEC
Version 2 SPI Confidential 92
F09 Storage Control
GETMAIN
Syntax
EXEC CICS
GETMAIN SET(pointer)
FLENGTH(data-name | literal) [BELOW]
[INITIMG(data-name)]

Version 2 SPI Confidential 93


F10
Storage Control
FREEMAIN
Syntax
EXEC CICS
FREEMAIN DATA(data-name)
DATAPOINTER(pointer)
END-EXEC

Samples
EXEC CICS
FREEMAIN DATA(PRODUCT-RECORD)
END-EXEC

EXEC CICS
FREEMAIN DATAPOINTER(ADDRESS OF PRODUCT-RECORD)
END-EXEC
Version 2 SPI Confidential 94
G. Legacy coding conventions

Version 2 SPI Confidential 95


G01 Legacy coding conventions
• HANDLE AID
• HANDLE CONDITION

Version 2 SPI Confidential 96


G02a
Legacy coding conventions
HANDLE AID
Syntax of HANDLE AID Common options
EXEC CICS
HANDLE AID
option [(procedure-name)] …
PA1-PA3,
END-EXEC PF1-PF24,
ENTER,
CLEAR,
Samples ANYKEY
Handles two AID keys
EXEC CICS
HANDLE AID PF3(1100-PF3)
CLEAR(1100-CLEAR)
END-EXEC

Handles all AID keys except ENTER


EXEC CICS
HANDLE AID PF3(1100-PF3)
ANYKEY(1100-ANYKEY)
CLEAR
END-EXEC

Version 2 SPI Confidential 97


Legacy coding conventions
G02b HANDLE AID sample

Version 2 SPI Confidential 98


G03a
Legacy coding conventions
HANDLE CONDITION
Syntax of HANDLE CONDITION
EXEC CICS

HANDLE CONDITION condition-name [(procedure-name)] …


END-EXEC

Version 2 SPI Confidential 99


Legacy coding conventions
G03b HANDLE CONDITION sample

Version 2 SPI Confidential 100


Version 2 SPI Confidential 101

You might also like