COBOL Considerations Identification Division n No differences Environment
COBOL Considerations Identification Division. n No differences Environment Division n n MUST be EMPTY in CICS Program! No SELECT statements allowed! Data Division n No FILE SECTION – (No SELECTS) CICS-Prg 1
COBOL Considerations (More) Data Division n WORKING-STORAGE SECTION. w Switches, Flags, Variables, Records, etc. w You get ‘fresh’ copy each time program loaded! n LINKAGE SECTION (New Item!!) w DFHCOMMAREA defined or CICS will! w Used to receive data from CICS. w CICS also inserts EIB Block definition CICS-Prg 2
COBOL Considerations (More) Procedure Division n n Uses most COBOL statements Also uses CICS Commands like: w SEND MAP w RECEIVE MAP w READ DATASET w WRITE DATASET w RETURN w 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: n n n 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 n n Can be nested (or not if careful!) Usually each path ends with RETURN Can use EVALUATE statement (Newer!) n n EVALUATE TRUE most common (New Dev) General WHEN OTHER for errors CICS-Prg 5
Sample CICS COBOL Program WORKING-STORAGE SECTION. n n n Switches, Flags, and Misc Variables COMMUNICATION-AREA (Your copy!) RESPONSE-CODE PIC S 9(08) COMP. RECORD Descriptions COPY Library for MAP Other COPY Members as needed CICS-Prg 6
Sample CICS COBOL Program LINKAGE SECTION. n 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 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 = DFHPF 3 or DFHPF 12 Exit Program WHEN OTHER Invalid key END-EVALUATE CICS-Prg 9
Basic CICS Commands General Structure: EXEC 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 S 9(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 (ABCODE used to identify storage dump Usually omitted!) CICS-Prg 20
CICS Program Design Event-driven design Structure Chart - Consider All Functions Identify Events and Context n n Any action that starts program List All (Valid) Possible User Actions Design Appropriate Response n n Processing required for an event Managing user interaction CICS-Prg 21
CICS Program Design COMMAREA usually stores ‘context’ n n 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 n n n Helps with design or Program Serves as Documentation of Program Sometimes replaced with ‘Structure Chart’ Structure Chart ‘Evolves’ into Design n 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: n n n n DISABLED DUPREC FILENOTFND INVREQ IOERR NOTAUTH NOTFND Dataset disabled Record already exists Dataset not in FCT Invalid request File I/O error User not authorized Record not in file CICS-Prg 25
Checking for Exceptions ALL CICS Commands allow RESP Parm 01 RESP-CODE PIC S 9(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 CICS-Prg 26
Preventing File Corruption PREVENT n n n Add ‘busy’ flag in record (Special Maint) All programs MUST follow procedure Extra I/O required (to Set/Reset flag) DETECT n n n 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 n n Withdraw from Savings – Deposit to Check Crash after withdraw? Where’s money? Must both be done or neither! (Atomic) CICS-Prg 28
- Slides: 28