27
File Handling & Temporary Storage Day4

File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

Embed Size (px)

Citation preview

Page 1: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

File Handling & Temporary StorageDay4

Page 2: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

2Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Objectives• Access Methods

– VSAM– BDAM

• VSAM Considerations– Random access– Sequential access

• Temporary Storage Control– Commands to read, write and delete– Design considerations– Examples

• Transient Data Control– Intrapartition TD queues– Extrapartition TD queues– Commands to read, write and delete– Examples

Page 3: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

3Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

CICS File Control

• VSAM– Allows read, browse, update and delete operations

• BDAM– Allows read, browse and update only– They are less efficient than VSAM– Can be replaced by a relative record VSAM dataset or ESDS addressed by

RBA

Page 4: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

4Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Types of VSAM Files

• ESDS - Entry Sequenced Data Set

• KSDS - Key Sequential Data Set

• RRDS - Relative Record Data Set

Page 5: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

5Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Alternate Indexes in VSAM

• Accessing same set of records in different ways

• Any number of alternate keys

• Alternate keys need not be unique

• Only KSDS and ESDS can have alternate keys

Page 6: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

6Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Random access - READ

MOVE +80 TO WS-EMP-REC-LEN.MOVE ‘10000’ TO WS-EMP-REC-KEY.MOVE 5 TO WS-EMP-KEY-LEN.EXEC CICS READ FILE (‘EMPFILE1’) INTO (WS-EMP-REC) LENGTH (WS-EMP-REC-LEN) RIDFLD (WS-EMP-REC-KEY) KEYLENGTH (WS-EMP-KEY-LEN)END-EXEC.

• Places the record in WS-EMP-REC

Page 7: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

7Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

GENERIC READ

MOVE +80 TO WS-EMP-REC-LEN.

MOVE ‘10’ TO WS-EMP-REC-KEY.

MOVE 2 TO WS-EMP-KEY-LEN.

EXEC CICS READ

FILE (‘EMPFILE1’)

INTO (WS-EMP-REC)

LENGTH (WS-EMP-REC-LEN)

RIDFLD (WS-EMP-REC-KEY)

KEYLENGTH (WS-EMP-KEY-LEN)

GENERIC

END-EXEC.

Page 8: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

8Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

READ Continues...

• READ COMMAND OPTIONS– EQUAL– GTEQ– UPDATE

• READ-UPDATE/REWRITE– Maintains exclusive control on the resource(on CI in case of

VSAM file) until • REWRITE is done • Transaction ends normally or abnormally• Control over resource is released by program using UNLOCK command.

Page 9: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

9Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

REWRITE• To rewrite records into file.

EXEC CICS REWRITE FILE (‘EMPFILE’) FROM (WS-EMP-REC) LENGTH (WS-EMP-REC-LEN)END-EXEC.

• This command updates a record. • Prior to this command the record must be read

with a READ UPDATE command.

Page 10: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

10Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

WRITE

• To write records into file.

MOVE +80 TO WS-EMP-REC-LEN.MOVE ‘11000’ TO WS-EMP-REC-KEY.MOVE 5 TO WS-EMP-KEY-LEN.EXEC CICS WRITE FILE (‘EMPFILE’) FROM (WS-EMP-REC) LENGTH (WS-EMP-REC-LEN) RIDFLD (WS-EMP-REC-KEY) KEYLENGTH (WS-EMP-KEY-LEN)END-EXEC.

Page 11: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

11Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

DELETE

• Read the record with UPDATE option and then delete it with the following command.

EXEC CICS DELETE

FILE(‘EMPFILE’)

END-EXEC.

• Use the following command to delete the record directly.

MOVE ‘12345’ TO EMP-REC-KEY.

EXEC CICS DELETE

FILE(‘EMPFILE’)

RIDFLD (EMP-REC-KEY)

END-EXEC.

Page 12: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

12Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

GROUP DELETE

• MOVE ‘11’ TO WS-EMP-REC-KEY.

• MOVE 2 TO WS-EMP-KEY-LEN.

EXEC CICS DELETE

FILE (‘EMPFILE’)

RIDFLD (WS-EMP-REC-KEY)

KEYLENGTH (WS-EMP-KEY-LEN)

GENERIC

NUMREC (WS-NUM-REC-DEL)

END-EXEC.

Page 13: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

13Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Transaction deadlocks• Exclusive control on CI.

• Exclusive control may cause transaction deadlocks. Make sure to use UNLOCK when you are not rewriting

• In pseudo-conversation, at the end of transaction, all locks are released.

Page 14: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

14Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Sequential access - Browsing• STARTBR

• READNEXT

• READPREV

• RESETBR

• ENDBR

Page 15: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

15Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

STARTBR

• This establishes a browse session.

EXEC CICS STARTBR

FILE (‘EMPFILE’)

RIDFLD (EMP-REC-KEY)

KEYLENGTH(KEY-LEN)

GTEQ/EQUAL/GENERIC

END-EXEC.

Page 16: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

16Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

READNEXT/READPREV

EXEC CICS READNEXT/READPREV

FILE (‘EMPFILE’)

INTO (EMP-REC)

LENGTH (EMP-REC-LEN)

RIDFLD (EMP-REC-KEY)

END-EXEC.

Page 17: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

17Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

RESETBR

• Establish a new browsing position with in the same browse.

MOVE ‘12345’ TO EMP-REC-KEY.

EXEC CICS RESETBR

FILE (‘EMPFILE’)

RIDFLD (EMP-REC-KEY)

GTEQ

END-EXEC.

Page 18: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

18Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

ENDBR

• End browse operation

EXEC CICS ENDBR

FILE (‘EMPFILE’)

END-EXEC.

Page 19: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

19Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Sequential access – VSAM ESDSMove Low-values to VSAM-ESDS-RBA

EXEC CICS STARTBR

DATASET (‘filename’)

RIDFLD(ESDS-RBA)

RBA

EQUAL

END-EXEC

EXEC CICS READNEXT

DATASET (‘filename’)

INTO(FILE-AREA)

RIDFLD(ESDS-RBA)

LENGTH(WS-LEN)

RBA

END-EXEC

Page 20: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

20Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Temporary Storage

• COMMAREA (Communication Area)

• CWA (Common Work Area)

• TWA (Transaction Work Area)

• TSQ (Temporary Storage Queue)

• TDQ (Transient Data Queue)

Page 21: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

21Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

TSQ Commands

• WRITEQ TS

EXEC CICS WRITEQ TS QUEUE (qname) FROM (recarea) LENGTH (length) option (option)…END-EXEC.

Page 22: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

22Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

TSQ Commands

• READQ TS

EXEC CICS READQ TS

QUEUE (qname)

INTO (recarea)

LENGTH (length)

option

END-EXEC

Page 23: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

23Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

TSQ Commands

• DELETEQ TS

EXEC CICS DELETEQ TS

QUEUE (qname)

END-EXEC.

Page 24: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

24Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Transient Data Queue

• 2 types of TDQ– Intra-partition – Extra-partition

• Difference between TDQ and TSQ– TDQ to be defined in DCT

– No modify or Rewrite option in TDQ

– TDQ can be read only sequentially

– A destructive read is performed on TDQ

– A trigger can be set on Intrapartition TDQ

– No counterpart to the MAIN option available in TSQ

Page 25: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

25Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

TDQ Commands

EXEC CICS WRITEQ TD

QUEUE (qname)

FROM (recarea)

LENGTH (length)

END-EXEC

EXEC CICS READQ TD

QUEUE (qname)

INTO (recarea)

LENGTH (length)

END-EXEC

EXEC CICS DELETEQ TD

QUEUE (qname)

END-EXEC

DFHDCT entry

TYPE=INTRA

DESTID=qname

TRANSID=EMPL

TRIGLEV=2000

Page 26: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

26Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Summary• What is VSAM?• What are the types of VSAM files?• When do transaction deadlocks happen and how

to avoid?• What are the commands for sequential access?• How is sequential access of ESDS done?• What is the difference between TSQ and TDQ?• What are the commands used to access TSQ and

TDQ?

Page 27: File Handling & Temporary Storage Day4 2 Copyright © 2005, Infosys Technologies Ltd ER/CORP/CRS/TP01/003 Version No: 1.0 Objectives Access Methods –VSAM

27Copyright © 2005, Infosys Technologies Ltd

ER/CORP/CRS/TP01/003 Version No: 1.0

Thank You!