Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 2: CICS Architecture


CICS File Control

File Control (DFHFC) is the CICS component that reads and updates files. It gives your programs simple READ, WRITE, REWRITE and DELETE commands against VSAM datasets.

What is file control

  • File Control (DFHFC) is part of the CICS nucleus. Every file request from your program goes through it.
  • It supports VSAM datasets: KSDS (keyed, read by key), ESDS (entry-sequenced, read by RBA) and RRDS (relative record, read by record number).
  • It also supports BDAM datasets and CICS data tables (shared data tables and coupling facility data tables).
  • Each file is defined to CICS (FCT entry, or an RDO FILE resource) with its dataset name and processing options.

Reading, writing, updating and deleting

  • READ: read one record by key (KSDS), by RBA (ESDS) or by RRN (RRDS). Add the UPDATE option to lock the record for update.
  • WRITE: add a brand-new record to the file.
  • REWRITE: update the record you previously read with UPDATE.
  • DELETE: delete a record (VSAM only). You can delete the record just read, or by key.
  • Browse: STARTBR positions at a starting key, READNEXT and READPREV walk forward and backward, ENDBR ends the browse, RESETBR restarts it.

RLS and record locking

  • RLS (Record Level Sharing): VSAM files shared between CICS regions and batch jobs, with locking at the record level.
  • Non-RLS: CICS owns the file exclusively. Batch cannot open it while CICS has it open.
  • When you READ a record with UPDATE, CICS locks it. The lock is held until you REWRITE, DELETE, or reach a syncpoint.
  • Two tasks locking records in opposite order can deadlock. CICS detects the deadlock and abends one of the tasks.

Recovery

  • Recoverable files are journaled. If the task abends, CICS automatically backs out its file updates (dynamic backout).
  • EXEC CICS SYNCPOINT commits all recoverable updates made so far. ROLLBACK undoes them.
  • Always handle the file conditions: NOTFND (record not found), DUPREC (duplicate key), DUPKEY, INVREQ (bad request) and IOERR.
  • Never ignore a file error - a missed NOTFND means the program works with stale data from the last successful read.

Example - READ a VSAM record for update in COBOL

  • Read the customer record with key in WS-CUST-KEY and lock it for update.
  • * Read the customer record and lock it for update EXEC CICS READ FILE('CUSTFILE') INTO(WS-CUST-REC) RIDFLD(WS-CUST-KEY) KEYLENGTH(6) UPDATE END-EXEC
  • FILE names the CICS file definition. RIDFLD holds the key, and KEYLENGTH gives its length.
  • UPDATE locks the record. Follow with REWRITE to save changes, or the lock is released at the next syncpoint.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant