+ All Categories
Home > Documents > COBOL DAY 7&8

COBOL DAY 7&8

Date post: 10-Apr-2015
Category:
Upload: api-3838727
View: 1,070 times
Download: 0 times
Share this document with a friend
121
VSAM Overview
Transcript
Page 1: COBOL DAY 7&8

VSAM

Overview

Page 2: COBOL DAY 7&8

VSAM (Virtual Storage Access Method )

VSAM is an integral part of MVS. At the end of this course, you, the user, will know VSAM in detail.

know the different types of VSAM data sets

be able to create, delete and alter VSAM data sets, with indexes and alternate indexes

know the organization of VSAM data sets

Page 3: COBOL DAY 7&8

Access Methods

An access method defines the technique by which data is stored and retrieved. The different types of dataset organizations in MVS are:

Physical Sequential

Partitioned

Indexed Sequential

Direct

VSAM

Page 4: COBOL DAY 7&8

What is VSAM?

VSAM is Virtual Storage Access Method

It is a method used to move data between Disk and Main Storage

VSAM operates in Virtual Environment

Page 5: COBOL DAY 7&8

Application Operating System

VSAM

Request Reply

VSAM

VSAM acts as interface between

Operating System and Application Program

Page 6: COBOL DAY 7&8

Main Storage Disk

VSAM

DATA DATA

VSAM

Interface between Main Storage and Disk

Page 7: COBOL DAY 7&8

File access methods

Data (Records) is retrieved

Sequential (Reading from beginning to end)

Random (Records are read by the value in the key)

Direct (Records are read based on their physical location/address on disk)

VSAM provides all these methods

One access method supporting all types of data retrieval

Page 8: COBOL DAY 7&8

Traditional access methods

QSAM (Queried Sequential Access Method)

BSAM (Basic Sequential Access Method)

for ‘flat’ files

ISAM (Index Sequential Access Method)

for Index files

BDAM (Basic Direct Access Method)

for direct access files

Page 9: COBOL DAY 7&8

VSAM Dataset Types

Entry Sequenced Dataset (ESDS)

ESDS contains records in the order in which they are entered. Records are added to the end of the data set, and can be accessed sequentially.

Key Sequenced Dataset (KSDS)

KSDS contains records in ascending collating sequence. Records can be accessed by a field called a key, or by a relative byte address (RBA - relative position of the record from the beginning of the dataset), or sequentially.

Linear Dataset (LDS)

LDS contains data that has no record boundaries. The manipulation of the data is completely controlled by the user.

Relative Record Dataset (RRDS)

RRDS contains records in the order of relative record number. These records can be accessed only by this number.

Page 10: COBOL DAY 7&8

CLUSTERINDEX

DATA

VSAM data set organization

VSAM Data Set can contain three major components

CLUSTER (Catalog entry)

INDEX

DATA (Actual data)

Data Set is referred by cluster name in JCL

Page 11: COBOL DAY 7&8

CI

Record Record .......

VSAM internals

CONTROL INTERVAL (CI)

VSAM stores Data and Index in Control Intervals (CI)

CI is similar to ‘Block’

Page 12: COBOL DAY 7&8

DASD I/O Buffer

R1 R2 R3

CI

CONTROL INTERVAL

CI is the unit of retrieval between DASD and I/O Buffer (Virtual Storage)

R1 R2 R3

Page 13: COBOL DAY 7&8

Control Interval

CI contains

Records (or DATA)

Free space (Optional)

Control Information Definition Field (CIDF)

Record Definition field (RDF)

Page 14: COBOL DAY 7&8

Building blocks of a VSAM Dataset

Logical Record

Logical records of VSAM data sets are stored in a different manner from logical records in non-VSAM data sets. VSAM stores records in control intervals.

Control Interval (CI)

A control interval consists of the following:

Logical records (LR)

Free space (FS)

Control information fields LR LR LR LR..FS....FS...RDF CIDF

Free Space is the space reserved within the CI for inserting new records in a KSDS or for lengthening the existing records.

Page 15: COBOL DAY 7&8

3 bytes, Length of RecordHow many successive records have same length 4 bytes long, One per CI

Indicates Free space, where and how much

R1 R2 R3 FreeSpace

RDF

RDF

CI DF

CONTROL INTERVAL

CIDF & RDF are VSAM control functions

Used by VSAM to access data

Page 16: COBOL DAY 7&8

CONTROL AREA

Control Area

CIs are grouped into CA

The control intervals in a VSAM data set are grouped together into Control Areas.

A VSAM data set is actually composed of one or more control areas. The maximum size of a control area is a cylinder, and the minimum size is one track.

Control Area (CA)

LR LR LR LR.. FS....FS... RDF CIDFLR LR LR LR.. FS....FS... RDF CIDFLR LR LR LR.. FS....FS... RDF CIDF

Page 17: COBOL DAY 7&8

Cluster

VSAM datasets are defined as Clusters.

A Cluster is a combination of the data component and the index component.

The Index component is applicable only in the case of a KSDS.

The data component holds data records.

The index component holds the index records to access the required information from the data component

Highest Index Set

1300 1305 1310 1350 FS

1400 1410 1415 1600 FS

FS FS FS FS FS1001 1002 1005 1010 FS

1020 1022 1030 1055 FS

FS FS FS FS FS

1055

1600 FS 5000 FS FS

1010 1055 FS 1350 1600 FS

2210

5000

Index Set

Sequence Set

DATA COMPONENT (CA1)

Data Component (CA2)

Page 18: COBOL DAY 7&8

Control Interval Split

When a data set is first loaded, the key sequence of records and their physical order are the same.

However, when records are inserted, control interval split can occur, causing the data control intervals to have a physical order that is different from the key sequence.

For example, try to insert '1004' in CI-1 shown below :

A Control Interval Split occurs and CI-1 is split exactly into two half CI's. CI-3, which is a free control interval is used, and some logical records of CI-1 are moved into CI-3. CI-3 is placed after CI-2 and it is not inserted in between CI-1 and CI-2.

1001 1002 1005 1010 FS

1020 1022 1030 1055 FS

FS FS FS FS

CA-1 (CI-1 to CI-3) - After split

1001 1002 1004 FS

1020 1022 1030 1055 FS

1005 1010 FS FS

CA-1 (CI-1 to CI-3) - Before split

Page 19: COBOL DAY 7&8

Control Area Split

Now, if record ‘1025’ is inserted, there is no free control interval for a CI split to occur. Hence, a CA (control area) split occurs. The CA-1 is split into two half control areas; some of the Control intervals of CA-1 are moved into the newly created CA (CA-2).

CA-1 (CI-1 to CI-3) - After split

1001 1002 1004 FS

1020 1022 FS FS FS

FS FS FS FS

CA-2 (CI-1 to CI-3)

1025 1030 1055 FS

1005 1010 FS FS

FS FS FS FS

Page 20: COBOL DAY 7&8

Types of VSAM data sets

ESDS Entry Sequenced Data Set

KSDS Key Sequenced Data Set

RRDS Relative Record Data Set

LDS Linear Data Set

Page 21: COBOL DAY 7&8

ESDS

Similar to Sequential File

Sequenced by the order in which data is entered/loaded

New Records are added at the end only (chronological order)

Supports both Fixed and Variable formats

Contains only CLUSTER & DATA components

Page 22: COBOL DAY 7&8

Only sequential access in Batch Cobol Programs

Random access is supported in on-line applications (CICS) using Relative Byte Address (RBA)

Alternate Index is supported in on-line applications (CICS)

NO primary index

ESDS (Contd...)

Page 23: COBOL DAY 7&8

CI

RBA of R1 is 80

RBA

Record location relative to the beginning of the file(Relative Byte Address)

R1 R2 R380 40 60

Page 24: COBOL DAY 7&8

Access Method Services (AMS)

Access Method Services is a service program that helps you to allocate and maintain VSAM data sets and catalogs.

IDCAMS is the name of the utility program used to perform the following operations on VSAM data sets.

Creating a Data set

Loading a VSAM data set.

Printing a Data set

Deleting a Data set

Error Detection for KSDS Data set

Creating Generation Data Groups (GDG) etc.

Page 25: COBOL DAY 7&8

INVOKING ACCESS METHOD

IDCAMS UTLITY

Page 26: COBOL DAY 7&8

Defining a VSAM Cluster

The Define Cluster command is used to allocate VSAM data sets. The basic information required for defining a VSAM data set is:

Name of the cluster.

Volume(s) on which the data set will be allocated.

Type of data set (KSDS, ESDS, RRDS or LDS).

Space needed for the data set.

For a KSDS, the length of the key and its offset from the beginning of the record.

Record size, and whether it is fixed or variable in length.

Control interval size.

CI and CA Free Space.

The following keywords have to be used to define the different types of VSAM data sets:

NONINDEXED for ESDS.

INDEXED for KSDS.

NUMBERED for RRDS.

LINEAR for LDS.

Page 27: COBOL DAY 7&8

Sample JCL to create an ESDS cluster

Freespace(PCT1,PCT2)

PCT1=> PCT FREE SPACE IN each CI

PCT2=> PCT Of unused CI in CA

RECORDSIZE(N1,N2)

N1=> AVG RECL

N2=> MAX RECL

//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID

//DEFKSDS EXEC PGM=IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

DEFINE CLUSTER(NAME(LEM0UXX.TEST.ESDS) -

VOLUMES(LEM001) -

NONINDEXED -

TRACKS(2,1) -

RECORDSIZE(50,50) -

CONTROLINTERVALSIZE(4096) -

FREESPACE(10,20)) -

DATA(NAME(LEM0UXX.TEST.ESDS.DATA))

/*

NONINDEXED - ESDS

Page 28: COBOL DAY 7&8

COBOL AND ESDS

OVERVIEW

Page 29: COBOL DAY 7&8

ESDS

Similar to Sequential File

Sequenced by the order in which data is entered/loaded

New Records are added at the end only (chronological order)

Supports both Fixed and Variable formats

Contains only CLUSTER & DATA components

Page 30: COBOL DAY 7&8

Only sequential access in Batch Cobol Programs

Random access is supported in on-line applications (CICS) using Relative Byte Address (RBA)

Alternate Index is supported in on-line applications (CICS)

NO primary index

ESDS (Contd...)

Page 31: COBOL DAY 7&8

FILE-CONTROL Paragraph  

Format: 

SELECT [OPTIONAL] File-name-1 ASSIGN TO Assignment-name-1

SEQUENTIAL

[ ORGANIZATION IS INDEXED

RELATIVE

SEQUENTIAL

[ACCESS MODE IS RANDOM

DYNAMIC

 

[FILE STATUS IS Data-name-1]

 

 

 

 

Page 32: COBOL DAY 7&8

ORGANIZATION

SEQUENTIAL => ESDSINDEXED => KSDSRELATIVE => RRDS

ACCESS MODE OPTIONS

ESDS : SEQUENTIAL KSDS : SEQUENTIAL or RANDOM or DYNAMICRRDS: SEQUENTIAL or RANDOM or DYNAMIC

Page 33: COBOL DAY 7&8

ESDS

ORGANIZATION IS SEQUENTIAL

ACCESS MODE IS SEQUENTIAL

INPUT OUTPUT INPUT-OUTPUT

EXTEND

READ YES - YES -

WRITE - YES YES

DELETE

REWRITE YES

Page 34: COBOL DAY 7&8

VSAM === ESDS

ORGANIZATION IS SEQUENTIAL.ACCESS MODE = SEQUENTIAL

OVERVIEW

Page 35: COBOL DAY 7&8

CREATING ESDS

Page 36: COBOL DAY 7&8

Writing Data in ESDS

Page 37: COBOL DAY 7&8

Writing Data in ESDS

Page 38: COBOL DAY 7&8

Writing Data in ESDS

Page 39: COBOL DAY 7&8

RUNNING A PROGRAM

Page 40: COBOL DAY 7&8

View the data from ESDS

REPRO COMMAND

Page 41: COBOL DAY 7&8

PRINT ESDS EXAMPLE

Overview

Page 42: COBOL DAY 7&8

PRINT ESDS

Page 43: COBOL DAY 7&8

PRINT ESDS

Page 44: COBOL DAY 7&8

PRINT ESDS

Page 45: COBOL DAY 7&8

KSDS (KEY SEQUENTIAL DATA SET )

Page 46: COBOL DAY 7&8

Sample JCL to create a KSDS cluster

//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID

//DEFKSDS EXEC PGM=IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

DEFINE CLUSTER(NAME(LEM0UXX.TEST.KSDS) -

VOLUMES(LEM001) -

TRACKS(2,1) -

INDEXED -

KEYS(9,0) -

RECORDSIZE(50,50) -

CONTROLINTERVALSIZE(4096) -

FREESPACE(10,20)) -

DATA(NAME(LEM0UXX.TEST.KSDS.DATA)) -

INDEX((NAME(LEM0UXX.TEST.KSDS.INDEX))

/*

KEYS(N1,N2)

N1=> length of the Key(Bytes)

N2=> is starting byte position

of Key in Record

RECORDSIZE(N1,N2)

N1=> AVG RECL

N2=> MAX RECL

Freespace(PCT1,PCT2)

PCT1=> PCT FREE SPACE IN each CI

PCT2=> PCT Of unused CI in CA

INDEXED - KSDS

Page 47: COBOL DAY 7&8

SELECT & ASSIGN Syntax

Page 48: COBOL DAY 7&8

READ statement

Page 49: COBOL DAY 7&8

WRITE & REWRITE statement

Page 50: COBOL DAY 7&8

KSDS

ORGANIZATION IS INDEXED

ACCESS MODE IS SEQUENTIAL

INPUT OUTPUT INPUT-OUTPUT

READ YES - YES

WRITE - YES

DELETE YES

REWRITE YES

START YES YES

Page 51: COBOL DAY 7&8

INDEX FILE

ORGANIZATION IS INDEXED.ACCESS MODE = SEQUENTIAL

OVERVIEW

Page 52: COBOL DAY 7&8

CREATING KSDS

Page 53: COBOL DAY 7&8

WRITING A KSDS

Page 54: COBOL DAY 7&8

WRITING A KSDS

Page 55: COBOL DAY 7&8

WRITING KSDS

Page 56: COBOL DAY 7&8

RUNNING A KSDS

Page 57: COBOL DAY 7&8

Running a KSDS

Page 58: COBOL DAY 7&8

READING INDEX FILE-KSDS

ORGANIZATION IS INDEXED.ACCESS MODE = SEQUENTIAL

OVERVIEW

Page 59: COBOL DAY 7&8

READING A KSDS

Page 60: COBOL DAY 7&8

READING A KSDS FILE

Page 61: COBOL DAY 7&8

EXECUTE A PROGRAM FOR READING DATA FROM KSDS

Page 62: COBOL DAY 7&8

SPOOL OUTPUT

Page 63: COBOL DAY 7&8

SPOOL OUTPUT

Page 64: COBOL DAY 7&8

START & DELETE statement

Page 65: COBOL DAY 7&8

START :Position a Record

Page 66: COBOL DAY 7&8

START COMMAND

Page 67: COBOL DAY 7&8

START COMMAND

Page 68: COBOL DAY 7&8

DELETE COMMAND

Page 69: COBOL DAY 7&8

DELETE COMMAND

Page 70: COBOL DAY 7&8

EXECUTE A PROGRAM AFTER COMPILE

Page 71: COBOL DAY 7&8

PRINT THE KSDS DATASET

Page 72: COBOL DAY 7&8

PRINT THE KSDS

Page 73: COBOL DAY 7&8

KSDS ORGANIZATION IS INDEXEDACCESS MODE IS RANDOM

Page 74: COBOL DAY 7&8

KSDS

ORGANIZATION IS INDEXED

ACCESS MODE IS RANDOM

INPUT OUTPUT INPUT-OUTPUT

READ YES - YES

WRITE - YES YES

DELETE YES

REWRITE YES

START

Page 75: COBOL DAY 7&8

KSDS – RANDOM- WRITE

Page 76: COBOL DAY 7&8

KSDS – Random -WRITE

Page 77: COBOL DAY 7&8

KSDS –RANDOM MODEREAD Operation

Overview

Page 78: COBOL DAY 7&8

KSDS – RANDOM -READ

Page 79: COBOL DAY 7&8

KSDS – RANDOM -READ

Page 80: COBOL DAY 7&8

KSDS ORGANIZATION IS INDEXEDACCESS MODE IS DYNAMIC

Page 81: COBOL DAY 7&8

KSDS

ORGANIZATION IS INDEXED

ACCESS MODE IS DYNAMIC

INPUT OUTPUT INPUT-OUTPUT

READ YES - YES

WRITE - YES YES

DELETE YES

REWRITE YES

START YES YES

Page 82: COBOL DAY 7&8

KSDS- DYNAMIC MODE WRITE OPERATION

Overview

Page 83: COBOL DAY 7&8

KSDS –DYNAMIC- WRITE

Page 84: COBOL DAY 7&8

KSDS –DYNAMIC-WRITE

Page 85: COBOL DAY 7&8

KSDS –DYNAMIC-READ

Page 86: COBOL DAY 7&8

KSDS-DYNAMIC-READ

Page 87: COBOL DAY 7&8

RRDS

Overview

Page 88: COBOL DAY 7&8

Sample JCL to create an RRDS cluster

//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID

//DEFRRDS EXEC PGM=IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

DEFINE CLUSTER(NAME(LEM0UXX.TEST.RRDS) -

VOLUMES(LEM001) -

NUMBERED -

TRACKS(2,1) -

RECORDSIZE(50,50) -

CONTROLINTERVALSIZE(4096) -

FREESPACE(10,20)) -

DATA(NAME(LEM0UXX.TEST.RRDS.DATA))

/*

RECORDSIZE(N1,N2)

N1=> AVG RECL

N2=> MAX RECL

Freespace(PCT1,PCT2)

PCT1=> PCT FREE SPACE IN each CI

PCT2=> PCT Of unused CI in CA

NUMBERED - RRDS

Page 89: COBOL DAY 7&8

RELATIVE-RANDOM-WRITE

Page 90: COBOL DAY 7&8

RELATIVE-RANDOM-WRITE

Page 91: COBOL DAY 7&8

RELATIVE-RANDOM-READ

Page 92: COBOL DAY 7&8

RELATIVE-RANDOM-READ

Page 93: COBOL DAY 7&8

RELATIVE-DYNAMIC-READ

Page 94: COBOL DAY 7&8

RELATIVE-DYNAMIC-READ

Page 95: COBOL DAY 7&8

RELATIVE-DYNAMIC-READ

Page 96: COBOL DAY 7&8

ALTERNATE INDEX

Overview

Page 97: COBOL DAY 7&8

ALTERNATE INDEXESALTERNATE INDEXES

Used whenever the data is required to be retrieved on the basis of more than one field

EMPNO ENAME SALARY

101 RAJESH 5000

102 RAMESH 6000

103 RANDY 7000

104 SURESH 8000

e.g., Can be defined for both KSDS & ESDS

EMPNO ISBASE KEY

ENAME ISALTERNATE KEY

Page 98: COBOL DAY 7&8

Reduce data redundancyCan have duplicatesEasy to define using IDCAMSAllow datasets to be accessed sequentially or randomlyCan be updated automatically

ALTERNATE INDEXESALTERNATE INDEXES

Page 99: COBOL DAY 7&8

Disadvantages

Performance degradation

Complex update logic

Page 100: COBOL DAY 7&8

Steps for Creating Alternate IndexSteps for Creating Alternate Index

Define AIX using IDCAMS DEFINE AIX

Specify Alternate Index Path using IDCAMS DEFINE PATH

Build AIX & populate it using IDCAMS BLDINDEX

Page 101: COBOL DAY 7&8

Sample JCL to create an AIX cluster

Freespace(PCT1,PCT2)

PCT1=> PCT FREE SPACE IN each CI

PCT2=> PCT Of unused CI in CA

RECORDSIZE(N1,N2)

N1=> AVG RECL

N2=> MAX RECL

//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID

//DEFKSDS EXEC PGM=IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

DEFINE AIX (NAME(LEM0UXX.TEST.AIX.CLUSTER) –

RELATE (LEM0UXX.INFILE.KSDS) -

VOLUMES(LEM001) -

KEY (10, 35) -

TRACKS(2,1) -

NONUNIQUEKEY -

RECORDSIZE(49,49) -

UPGRADE

CONTROLINTERVALSIZE(4096) -

FREESPACE(10,20)) -

DATA(NAME(LEM0UXX.TEST.AIX.DATA))

INDEX(NAME(LEM0UXX.TEST.AIX.INDEX))

/*

UNIQUE /NONUNIQUE

UPGRADE-> VSAM AUTOMATIC

Updates the AIX for all

ADD,UPDT,DEL of Base cluster

KEY ( N1,N2)

N1-> LENGTH OF AIX key

N2-> KEYS start Loc in BASE CLUSTER

Page 102: COBOL DAY 7&8

• Syntax : UPGRADE/NOUPGRADE

• UPGRADE specifies that records in AIX are to be updated• automatically whenever the base cluster is updated

UPGRADE/NOUPGRADEUPGRADE/NOUPGRADE

Page 103: COBOL DAY 7&8

BUILDING AN INDEX

Overview

Page 104: COBOL DAY 7&8

BUILD INDEX

//JOB CARD

//STEP1 EXEC PGM=IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

BLDINDEX -

INDATASET(LEM0UXX.KSDS.CLUSTER') -

OUTDATASET('LEM0UXX.KSDS.AIX.CLUSTER') -

/*

BUILD INDEX is used

To load records in

AIX after it has been def

Page 105: COBOL DAY 7&8

PATH AND ALTERNATE INDEX

Overview

Page 106: COBOL DAY 7&8

DEFINE PATH

//JOB CARD

//STEP1 EXEC PGM = IDCAMS

//SYSPRINT DD SYSOUT=*

//SYSIN DD *

DEFINE PATH -

( NAME ( LEM0UXX.KSDS.PATH) –

PATHENTRY(LEM0UXX.KSDS.AIX.CLUSTER) –

UPDATE )

/*

//

Path Establishes

A Bridge Between

BASE CLUSTER & AIX

Page 107: COBOL DAY 7&8

ALTERNATE Index Example

Page 108: COBOL DAY 7&8

Define BASE CLUSTER

Page 109: COBOL DAY 7&8

LOADING DATA INTO BASE CLUSTER

Page 110: COBOL DAY 7&8

LOADING DATA INTO BASE CLUSTER

Page 111: COBOL DAY 7&8

LOADING DATA INTO BASE CLUSTER

Page 112: COBOL DAY 7&8

EXECUTING A PROGRAM TO LOAD DATA

Page 113: COBOL DAY 7&8

EXECUTING A PROGRAM TO LOAD DATA

Page 114: COBOL DAY 7&8

DEFINING AIX

RECORDSIZE(N1,N2)

N1= LENGTH OF BASE CLUSTER KEY(3)

+ LENGTH OF AIX KEY(5) + 5 for CI

Page 115: COBOL DAY 7&8

Build index

Page 116: COBOL DAY 7&8

Create path for Bridge

Page 117: COBOL DAY 7&8

READING RECORDS BY ALTERNATE INDEX

Page 118: COBOL DAY 7&8

READING RECORD BY ALTERNATE KEY

Page 119: COBOL DAY 7&8

READING RECORD BY ALTERNATE KEY

Page 120: COBOL DAY 7&8

EXECUTE A READ PROGRAM BY ALTERNATE KEY

DD1-> BASE CLUSTER

DD11-> PATH NAME

DDNAME SHOULD BE IN ORDER

Page 121: COBOL DAY 7&8

SPOOL OUTPUT


Recommended