cics-prg1 cobol considerations identification division. no differences environment division must be...
TRANSCRIPT
CICS-Prg 1
COBOL Considerations
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 2
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 3
COBOL Considerations (More)
Procedure Division Uses most COBOL statements Also uses CICS Commands like:
SEND MAPRECEIVE MAPREAD DATASETWRITE DATASETRETURNXCTL
CICS-Prg 4
Where are WE?
Program must be able to determine!Always starts at beginning of ProgramStarts with initialized Working-StorageCan use several methods: EIBCALEN (First time program loaded) COMMAREA (Tran-ID, EIBAID) Hidden Data on Screen
CICS-Prg 5
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 6
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 7
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 commarea0 (ZERO) means there is NO commarea
CICS-Prg 8
Sample CICS COBOL Program
PROCEDURE DIVISION (Where are we?)IF first-time
SEND Initial-MapELSE
IF <ENTER>Process Screen
ELSEProcess Function-Key
END-IFEND-IFSEND MAP
CICS-Prg 9
Sample CICS COBOL Program
PROCEDURE DIVISIONEVALUATE TRUE
WHEN EIBCALEN = 0Send Initial MAP
WHEN EIBAID = DFHENTERProcess Screen Data
WHEN EIBAID = DFHPF3 or DFHPF12Exit Program
WHEN OTHERInvalid key
END-EVALUATE
CICS-Prg 10
Basic CICS Commands
General Structure:EXEC CICS
CICS COMMAND OPTION(value) …(Parameters as needed)
END-EXEC
CICS-Prg 11
Basic CICS Commands
EXEC CICSSEND MAP(name)
[ MAPSET(name) ][ FROM(data-area) ][ MAPONLY | DATAONLY ][ ERASE | ERASEUP ][ CURSOR [ (value) ] ]
END-EXEC
CICS-Prg 12
Basic CICS Commands
EXEC CICSRECEIVE MAP(map-
name)[ MAPSET(mapset-
name) ] INTO(data-area)
END-EXEC
CICS-Prg 13
Basic CICS Commands
EXEC CICSRETURN [ TRANSID(name) ]
[ COMMAREA(data-area) ][ LENGTH(data-
value) ]END-EXEC Length – PIC S9(4) COMP or Literal
CICS-Prg 14
Program Control Commands
EXEC CICSXCTL PROGRAM(name)
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]END-EXECNOTE: Program name must be in PPT.Works like COBOL ‘GO TO’ statement.
CICS-Prg 15
Program Control Commands
EXEC CICSLINK PROGRAM(name)
[ COMMAREA(data-area) ][ LENGTH(data-value) ]
END-EXECNOTE: Program name must be in PPT.Works like COBOL ‘PERFORM’ statement.
CICS-Prg 16
Basic CICS Commands
EXEC CICSREAD DATASET(filename)
INTO(data-area) RIDFLD(data-area)[ RRN | RBA ][ UPDATE ]
END-EXEC
CICS-Prg 17
More CICS Commands
EXEC CICSWRITE DATASET(filename)
FROM(data-area) RIDFLD(data-area)[ RRN | RBA ]
END-EXEC
CICS-Prg 18
More CICS Commands
EXEC CICSREWRITE
DATASET(filename) FROM(data-area)
END-EXECNOTES:
Record MUST be READ with UPDATE!data-area - NOT have to match Read
CICS-Prg 19
More CICS Commands
EXEC CICSDELETE DATASET(filename)
[ RIDFLD(data-area) ][ RRN | RBA ]
END-EXECNOTE: If no RIDFLD last READ is
Deleted
CICS-Prg 20
Basic CICS Commands
EXEC CICSABEND [ ABCODE(name) ]
END-EXEC
(ABCODE used to identify storage dump -
Usually omitted!)
CICS-Prg 21
CICS Program Design
Event-driven designStructure Chart - Consider All FunctionsIdentify 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 22
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 23
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 24
More CICS Commands
EXEC CICSUNLOCK DATASET(filename)
END-EXECNOTE: 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 25
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 26
Checking for ExceptionsALL CICS Commands allow RESP Parm01 RESP-CODE PIC S9(8) COMP.
IF RESP-CODE = DFHRESP(NORMAL)MOVE ‘Y’ TO OK-COMMAND
ELSEIF RESP-CODE = DFHRESP(NOTFND)
MOVE ‘N’ TO REC-NOT-FOUNDELSE
PERFORM DISPLAY-MISC-ERROREND-IF
END-IF
CICS-Prg 27
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 28
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)