Professional Documents
Culture Documents
C3156 3Prg
C3156 3Prg
C3156 3Prg
Identification Division.
No differences
Environment Division
MUST be EMPTY in CICS Program!
No SELECT statements allowed!
Data Division
No FILE SECTION – (No SELECTS)
CICS-Prg 1
COBOL Considerations (More)
Data Division
WORKING-STORAGE SECTION.
Switches, Flags, Variables, Records, etc.
You get ‘fresh’ copy each time program loaded!
LINKAGE SECTION (New Item!!)
DFHCOMMAREA defined or CICS will!
Used to receive data from CICS.
CICS also inserts EIB Block definition
CICS-Prg 2
COBOL Considerations (More)
Procedure Division
Uses most COBOL statements
Also uses CICS Commands like:
SEND MAP
RECEIVE MAP
READ DATASET
WRITE DATASET
RETURN
XCTL
CICS-Prg 3
Where are WE?
Program must be able to determine!
Always starts at beginning of Program
Starts with initialized Working-Storage
Can use several methods:
EIBCALEN (First time program loaded)
COMMAREA (Tran-ID, EIBAID)
Hidden Data on Screen
CICS-Prg 4
Where are We? (More)
Beginning of Program must determine!
Can use series of ‘IF’ statements
Can be nested (or not if careful!)
Usually each path ends with RETURN
Can use EVALUATE statement (Newer!)
EVALUATE TRUE most common (New Dev)
General WHEN OTHER for errors
CICS-Prg 5
Sample CICS COBOL Program
WORKING-STORAGE SECTION.
Switches, Flags, and Misc Variables
COMMUNICATION-AREA (Your copy!)
RESPONSE-CODE PIC S9(08) COMP.
RECORD Descriptions
COPY Library for MAP
Other COPY Members as needed
CICS-Prg 6
Sample CICS COBOL Program
LINKAGE SECTION.
DFHCOMMAREA PIC X(nnn).
If you don’t code it, CICS Will!
The commarea (if any) placed here!
EIBCALEN gives length of commarea
0 (ZERO) means there is NO commarea
CICS-Prg 7
Sample CICS COBOL Program
PROCEDURE DIVISION (Where are we?)
IF first-time
SEND Initial-Map
ELSE
IF <ENTER>
Process Screen
ELSE
Process Function-Key
END-IF
END-IF
SEND MAP
CICS-Prg 8
Sample CICS COBOL Program
PROCEDURE DIVISION
EVALUATE TRUE
WHEN EIBCALEN = 0
Send Initial MAP
WHEN EIBAID = DFHENTER
Process Screen Data
WHEN EIBAID = DFHPF3 or DFHPF12
Exit Program
WHEN OTHER
Invalid key
END-EVALUATE
CICS-Prg 9
Basic CICS Commands
General Structure:
EXEC CICS
CICS COMMAND
OPTION(value) …
(Parameters as needed)
END-EXEC
CICS-Prg 10
Basic CICS Commands
EXEC CICS
SEND MAP(name)
[ MAPSET(name) ]
[ FROM(data-area) ]
[ MAPONLY | DATAONLY ]
[ ERASE | ERASEUP ]
[ CURSOR [ (value) ] ]
END-EXEC
CICS-Prg 11
Basic CICS Commands
EXEC CICS
RECEIVE MAP(map-name)
[ MAPSET(mapset-name) ]
INTO(data-area)
END-EXEC
CICS-Prg 12
Basic CICS Commands
EXEC CICS
RETURN [ TRANSID(name) ]
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
Length – PIC S9(4) COMP or Literal
CICS-Prg 13
Program Control Commands
EXEC CICS
XCTL PROGRAM(name)
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
NOTE: Program name must be in PPT.
Works like COBOL ‘GO TO’ statement.
CICS-Prg 14
Program Control Commands
EXEC CICS
LINK PROGRAM(name)
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
NOTE: Program name must be in PPT.
Works like COBOL ‘PERFORM’ statement.
CICS-Prg 15
Basic CICS Commands
EXEC CICS
READ DATASET(filename)
INTO(data-area)
RIDFLD(data-area)
[ RRN | RBA ]
[ UPDATE ]
END-EXEC
CICS-Prg 16
More CICS Commands
EXEC CICS
WRITE DATASET(filename)
FROM(data-area)
RIDFLD(data-area)
[ RRN | RBA ]
END-EXEC
CICS-Prg 17
More CICS Commands
EXEC CICS
REWRITE DATASET(filename)
FROM(data-area)
END-EXEC
NOTES:
Record MUST be READ with UPDATE!
data-area - NOT have to match Read
CICS-Prg 18
More CICS Commands
EXEC CICS
DELETE DATASET(filename)
[ RIDFLD(data-area) ]
[ RRN | RBA ]
END-EXEC
NOTE: If no RIDFLD last READ is Deleted
CICS-Prg 19
Basic CICS Commands
EXEC CICS
ABEND [ ABCODE(name) ]
END-EXEC
CICS-Prg 20
CICS Program Design
Event-driven design
Structure Chart - Consider All Functions
Identify Events and Context
Any action that starts program
List All (Valid) Possible User Actions
Design Appropriate Response
Processing required for an event
Managing user interaction
CICS-Prg 21
CICS Program Design
COMMAREA usually stores ‘context’
Get Key
Add Customer
Change Customer
Delete Customer
Response to same key can be different
depending on ‘context’ (ENTER key)
CICS-Prg 22
CICS Program Design
Event/Response Chart
Helps with design or Program
Serves as Documentation of Program
Sometimes replaced with ‘Structure Chart’
Structure Chart ‘Evolves’ into Design
Start with Major Functions
Add Detail as Needed
Assign Paragraph Numbering (If Used)
CICS-Prg 23
More CICS Commands
EXEC CICS
UNLOCK DATASET(filename)
END-EXEC
NOTE: If READ/UPDATE command is
used and you determine that record
does not need to be updated. Usually
not needed as record is unlocked when
the task is terminated.
CICS-Prg 24
Exception Conditions
Most Common Exceptions:
DISABLED Dataset disabled
DUPREC Record already exists
FILENOTFND Dataset not in FCT
INVREQ Invalid request
IOERR File I/O error
NOTAUTH User not authorized
NOTFND Record not in file
CICS-Prg 25
Checking for Exceptions
ALL CICS Commands allow RESP Parm
01 RESP-CODE PIC S9(8) COMP.
IF RESP-CODE = DFHRESP(NORMAL)
MOVE ‘Y’ TO OK-COMMAND
ELSE
IF RESP-CODE = DFHRESP(NOTFND)
MOVE ‘N’ TO REC-NOT-FOUND
ELSE
PERFORM DISPLAY-MISC-ERROR
END-IF
END-IF
CICS-Prg 26
Preventing File Corruption
PREVENT
Add ‘busy’ flag in record (Special Maint)
All programs MUST follow procedure
Extra I/O required (to Set/Reset flag)
DETECT
Save copy and compare before updating
OR – Add Maint-Timestamp and check it
Notify User to get latest version of data
CICS-Prg 27
Avoiding Deadlock
Sometimes called ‘Deadly Embrace’
Happens when records from multiple
files must be updated as a unit
Withdraw from Savings – Deposit to Check
Crash after withdraw? Where’s money?
Must both be done or neither! (Atomic)
CICS-Prg 28