Download - CICS COMANDOS
CICS-PrgCICS-Prg 11
COBOL ConsiderationsCOBOL 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-PrgCICS-Prg 22
COBOL Considerations (More)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-PrgCICS-Prg 33
COBOL Considerations (More)COBOL Considerations (More)
• Procedure Division– Uses most COBOL statements– Also uses CICS Commands like:
• RETURN• XCTL• SEND MAP• RECEIVE MAP• READ DATASET
CICS-PrgCICS-Prg 44
Where are WE?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-PrgCICS-Prg 55
Where are We? (More)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– EVALUATE TRUE most common (New Dev)– General WHEN OTHER for errors
CICS-PrgCICS-Prg 66
Sample CICS COBOL ProgramSample 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-PrgCICS-Prg 77
Sample CICS COBOL ProgramSample 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-PrgCICS-Prg 88
Sample CICS COBOL ProgramSample 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-PrgCICS-Prg 99
Sample CICS COBOL ProgramSample CICS COBOL Program
• PROCEDURE DIVISIONEVALUATE TRUE
WHEN EIBCALEN = 0First time in Program
WHEN EIBAID = DFHENTERProcess Screen
WHEN EIBAID = DFHPF3 or DFHPF12Exit Program
WHEN OTHERInvalid key
END-EVALUATE
CICS-PrgCICS-Prg 1010
Basic CICS CommandsBasic CICS Commands
• General Structure:EXEC CICS
CICS COMMAND
OPTION(value) …
(Parameters as needed)
END-EXEC
CICS-PrgCICS-Prg 1111
Basic CICS CommandsBasic CICS Commands
EXEC CICS
RETURN [ TRANSID(name) ]
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
Length – PIC S9(4) COMP or Literal
CICS-PrgCICS-Prg 1212
Basic CICS CommandsBasic CICS Commands
EXEC CICS
XCTL PROGRAM(name)
[ COMMAREA(data-area) ][ LENGTH(data-value) ]
END-EXEC
CICS-PrgCICS-Prg 1313
Basic CICS CommandsBasic CICS Commands
EXEC CICSSEND MAP(name)
[ MAPSET(name) ][ FROM(data-area) ][ MAPONLY | DATAONLY ][ ERASE | ERASEUP ][ CURSOR [ (value) ] ]
END-EXEC
CICS-PrgCICS-Prg 1414
Basic CICS CommandsBasic CICS Commands
EXEC CICS
RECEIVE MAP(map-name)
[ MAPSET(mapset-name) ]
INTO(data-area)
END-EXEC
CICS-PrgCICS-Prg 1515
Basic CICS CommandsBasic CICS Commands
EXEC CICS
READ DATASET(filename)
INTO(data-area)
RIDFLD(data-area)
[ RRN | RBA ]
[ UPDATE ]
END-EXEC
CICS-PrgCICS-Prg 1616
Basic CICS CommandsBasic CICS Commands
EXEC CICS
ABEND [ ABCODE(name) ]
END-EXEC
(ABCODE used to identify storage dump -
Usually omitted!)
CICS-PrgCICS-Prg 1717
CICS Program DesignCICS 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-PrgCICS-Prg 1818
CICS Program DesignCICS 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-PrgCICS-Prg 1919
CICS Program DesignCICS 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-PrgCICS-Prg 2020
More CICS CommandsMore CICS Commands
EXEC CICS
WRITE DATASET(filename)
FROM(data-area)
RIDFLD(data-area)
[ RRN | RBA ]
END-EXEC
CICS-PrgCICS-Prg 2121
More CICS CommandsMore 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-PrgCICS-Prg 2222
More CICS CommandsMore CICS Commands
EXEC CICS
DELETE DATASET(filename)
[ RIDFLD(data-area) ]
[ RRN | RBA ]
END-EXEC
NOTE: If no RIDFLD last READ is Deleted
CICS-PrgCICS-Prg 2323
More CICS CommandsMore 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-PrgCICS-Prg 2424
Exception ConditionsException 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-PrgCICS-Prg 2525
Checking for ExceptionsChecking for Exceptions
• ALL CICS Commands allow RESP Parm• 01 RESP-CODE PIC S9(8) COMP.IF RESP-CODE = DFHRESP(NORMAL)
MOVE ‘Y’ TO OK-COMMANDELSE
IF RESP-CODE = DFHRESP(NOTFND)MOVE ‘N’ TO REC-NOT-FOUND
ELSEPERFORM DISPLAY-MISC-ERROR
END-IFEND-IF
CICS-PrgCICS-Prg 2626
Preventing File CorruptionPreventing 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-PrgCICS-Prg 2727
Avoiding DeadlockAvoiding 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-PrgCICS-Prg 2828
Program Control CommandsProgram Control Commands
EXEC CICS
RETURN [ TRANSID(name) ]
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
CICS-PrgCICS-Prg 2929
Program Control CommandsProgram 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-PrgCICS-Prg 3030
Program Control CommandsProgram Control Commands
EXEC CICS
XCTL PROGRAM(name)
[ COMMAREA(data-area) ]
[ LENGTH(data-value) ]
END-EXEC
NOTE: Program name must be in PPT.
CICS-PrgCICS-Prg 3131
Terminal HandlingTerminal Handling
• CURSOR Positioning (in SEND MAP)– IC option in DFHMDF Macro (ATTRB Parm)
• If more than one – LAST position is used.
– DIRECT Cursor Positioning• CURSOR(nnn) where nnn is position on screen• Displacement from start of the screen• ( Row – 1 ) * 80 + ( Column – 1 )• 0 is Row 1, Column 1• 1919 is Row 24, Column 80 (24 by 80 Screen)• Changes in screen require changes to program
(Not used much - too complex!)
CICS-PrgCICS-Prg 3232
Terminal Handling (More)Terminal Handling (More)
• CURSOR Positioning (in SEND MAP)– Symbolic Cursor Positioning (Preferred!)
• CURSOR – with no position parameter!• Specify the FIELD where the CURSOR goes• Place –1 in the LENGTH Attribute of the field
where the cursor is to be placed• ‘FIELD NAME’ with ‘L’ appended is LENGTH• If more than one – FIRST position is used.• BINARY HALFWORD - PIC S9(04) COMP.
CICS-PrgCICS-Prg 3333
Terminal Handling (More yet)Terminal Handling (More yet)
• Determining the position of CURSOR when the user types an AID key.– EIBCPOSN – in EIB Block (binary halfword)– READ only-Available before RECEIVE MAP– Can be used to determine user selection
instead of requiring user to enter character
CICS-PrgCICS-Prg 3434
Attribute ModificationAttribute Modification
• Symbolic Map includes Attribute byte
• ‘Field Name’ with ‘A’ appended
• Cryptic ‘bit’ codes and names used
• Copy library supplied by IBM (Horrible)
• Most shops have their own copy book
• We don’t have ‘extended attributes’!
CICS-PrgCICS-Prg 3535
Editing Input DataEditing Input Data
• All data entered should be validated
• Required data must be present
• Numeric data needs to be ‘normalized’
• Alpha data should not be spaces
• Meaningful error messages displayed
• Very tedious coding required!
• Do checking from ‘bottom to top’!
CICS-PrgCICS-Prg 3636
Misc CICS CommandsMisc CICS Commands
EXEC CICS
SEND TEXT FROM(data-area)
[ LENGTH(data-value) ]
[ ERASE ]
[ FREEKB]
END-EXEC
NOTE: No FREEKB user must hit RESET!
CICS-PrgCICS-Prg 3737
Misc CICS CommandsMisc CICS Commands
EXEC CICS
HANDLE AID
option(procedure name)
…
END-EXEC
CICS-PrgCICS-Prg 3838
Misc CICS CommandsMisc CICS Commands
• HANDLE AID Options:– PA1-PA3 Program Attention Keys– PF1-PF24 Program Function Keys– ENTER The ENTER Key– CLEAR The CLEAR Key– ANYKEY Any key not Specified
(Except the ENTER key)
CICS-PrgCICS-Prg 3939
Handle AID Example (Old)Handle AID Example (Old)
EXEC CICS
HANDLE AID PF3(900-MENU)
CLEAR(850-CLEAR)
ENTER(700-ENTER)
ANYKEY(750-ERROR)
END-EXEC
NOTE: HANDLE AID sets up RECEIVE MAP!
Not executed when encountered! In OLD Progs.
CICS-PrgCICS-Prg 4040
Error ProcessingError Processing
• There are over 70 CICS error Conditions
• Mercifully only a few are handled
• TWO Methods of handling exceptions:– HANDLE CONDITION (Old Method)
• Similar in function to HANDLE AID
– RESPONSE Code checking• Allows cleaner program structure
CICS-PrgCICS-Prg 4141
Strange Exception - MAPFAILStrange Exception - MAPFAIL
• MAPFAIL Condition– Raised by RECEIVE MAP with no data
• User entered no data but pressed AID key• User pressed CLEAR key or PA key
– Simplest to PREVENT it from occurring• Check EIBAID to see what key was pressed• Don’t issue RECEIVE MAP if PA or CLEAR hit• Include ‘DUMMY’ field with MDT set ON
CICS-PrgCICS-Prg 4242
HANDLE CONDITION (Old!)HANDLE CONDITION (Old!)
EXEC CICS
HANDLE CONDITION
condition(procedure-name)
condition(procedure-name)
… up to 16 per statement
END-EXEC
CICS-PrgCICS-Prg 4343
HANDLE CONDITIONHANDLE CONDITION
• Common CONDITIONS– DUPREC Record already exists– MAPFAIL No data sent by user– NOSPACE No space left in file– NOTOPEN Data set not OPEN– NOTFND Record not in file– PGMIDERR Program not in PPT– ERROR ALL conditions not coded
CICS-PrgCICS-Prg 4444
HANDLE CONDITION ExampleHANDLE CONDITION Example
EXEC CICS
HANDLE CONDITION
MAPFAIL(500-NO-DATA)
DUPREC(600-DUPLICATE)
NOTOPEN
END-EXEC
NOTE: Condition by itself will nullify it!
CICS-PrgCICS-Prg 4545
HANDLE CONDITION (Notes)HANDLE CONDITION (Notes)
• Not an executable command
• Establishes paragraph to correct error
• Can issue multiple times
• Last one executed is in effect
• Causes ‘GO TO’ to paragraph named
• Done BEFORE CICS Command executed
• OLD method of coding – AVOID!
CICS-PrgCICS-Prg 4646
RESPONSE CHECKING RESPONSE CHECKING (NEW!)(NEW!)
• ADD ‘RESP’ option to CICS Command
• Define binary fullword PIC S9(8) COMP
• Name that field in each RESP option
• COPY of EIBRESP from EIB
• EIBRESP2 (RESP2) also available– Not many CICS Commands use it– Seldom needed as RESP is usually enough
CICS-PrgCICS-Prg 4747
USE General ERROR HandlingUSE General ERROR Handling
• Most shops have a standard error handling method
• If not, use sample linkage on Page 255
• Sample program is on Page 257
• Called whenever a condition is not handled in the program
• Displays error to user and terminates
CICS-PrgCICS-Prg 4848
LINKAGE SECTIONLINKAGE SECTION
• Used to access data left by previous execution of a program
• Data should be moved to your W/S!
• Each execution starts with initial W/S
• Define COMMAREA in Working-Storage
• DEFINE DFHCOMMAREA in Linkage
• RETURN references Working-Storage
CICS-PrgCICS-Prg 4949
Executive Interface BlockExecutive Interface Block
• EIB definition added by CICS Compiler• In Linkage Section after DFHCOMMAREA• Contains several useful fields
– EIBCALEN, EIBAID, EIBCPOSN, EIBDATE, EIBTIME, EIBTRNID, EIBTRMID, EIBRSRCE
• Most kept current by CICS (Page 212)• You can update a few of them-EIBTRNID
CICS-PrgCICS-Prg 5050
EIB Useful FieldsEIB Useful Fields
• EIBCALEN Length of COMMAREA• EIBAID Current AID Key pressed• EIBCPOSN Position of CURSOR• EIBDATE Task DATE (00YYDDD)• EIBTIME Task Time (0HHMMSS)• EIBTRNID Transaction of Task• EIBTRMID Terminal ID of Task• EIBRSRCERecently used Resource Name• EIBDS Recently accessed Data Set
CICS-PrgCICS-Prg 5151
DEBUGGING EIB FIELDSDEBUGGING EIB FIELDS
• EIBFN Last CICS Command• EIBRESP Completion Status• EIBRESP2 More Completion Status• EIBRCODE Response Code (OLD)• EIBRSRCE Recent Resource Name
– MAP Map Name– PRG CTL Program Name– FILE CTL Data Set Name
CICS-PrgCICS-Prg 5252
Access to Heavy StuffAccess to Heavy Stuff
• CWA Common Work Area– Installation defined (Sometimes handy)
• CSA Common System Area
• TWA Transaction Work Area
• TCTUA Terminal Control Table User Area
• Must establish Addressability if needed
CICS-PrgCICS-Prg 5353
Infrequently Needed StuffInfrequently Needed Stuff
EXEC CICS
ADDRESS CWA(pointer)
[ CSA(pointer) ]
[ TWA(pointer) ]
[ TCTUA(pointer) ]
END-EXEC
CICS-PrgCICS-Prg 5454
Infrequently Needed StuffInfrequently Needed Stuff
EXEC CICS
ADDRESS CWA(ADDRESS OF CWA)
END-EXEC
NOTE: Holdovers from MACRO-Level CICS
Seldom needed any more!