What is Virtual Storage Access Method (VSAM) ?- Definition from Trenovision

VSAM

VSAM (Virtual Storage Access Method ) is an access method for IBM’s mainframe operating system, MVS, now called z/OS.
VSAM succeeded and expanded upon an earlier IBM file access method, ISAM (Indexed Sequential Access Method).
Using VSAM, an enterprise can organize records in a file in physical sequence (the sequential order that they were entered), logical sequence using a key (for example, the employee ID number), or by the relative record number on direct access storage devices (DASD).
VSAM keeps disk records in a unique format that is not understandable by other access methods.
 


VSAM Dataset types

There are four types of VSAM datasets:

  • Entry Sequenced Data Set (ESDS)
  • Key Sequenced Data Set (KSDS)
  • Linear Data Set (LDS)
  • Relative Record Data Set (RRDS)

The primary difference among these types of data sets is the way their records are stored and accessed . Conventional (non-VSAM) access methods generally provide only a single type of dataset organization.
 

Entry Sequenced Data Set (ESDS)

In ESDS each record is identified for access by specifying its physical location – the byte address of the first data byte of each record in relationship to the beginning of the dataset.

  • Records can be accessed randomly as well as sequentially.
  • New records are always added at the end of the data set.
  • Cannot change the record length.
  • Cannot be physically deleted.
  • Records in an ESDS may be of variable length.

ESDS datasets are similar to Basic Sequential Access Method (BSAM) or Queued Sequential Access Method (QSAM) datasets.
 

Key Sequenced Data Set (KSDS)

In KSDS, each record is identified for access by specifying its key value- a sequence of characters embedded in each data record which uniquely identify that record from all other records in the dataset.
Components of KSDS

  • Data component contains the records that hold the user data, including the key fields.
  • Index component contains the key fields and pointers to the location of the record to which that key field belongs.

KSDS datasets are similar to Indexed Sequential Access Method (ISAM) datasets.
 


The storage organization of VSAM data set

  • A data set consists of a data component and additionally, an index component for a KSDS.
  • Each component consists of one or more control areas.
  • A control area may consist of many control intervals.
  • A control interval may have one or more records.
  • For a data component, a record may span many control intervals.



Linear data set (LDS)

LDS is similar to ESDS, which does not contain control information (how many records there are, how long each record is, and how much free space is left in that control intervals etc.,) LDS does not contain CIDF and RDF.
 

Relative Record Data Set (RRDS)

In RRDS, each record is identified for access by specifying its record number – the sequence number relative to the first record in the database

  • The entire data is a string of fixed length slots. Each slot occupies a fixed position and is identified by its position relative to the first slot of the data set. The relative position of each slot is called the Relative Record Number (RRN).
  • Records in an RRDS may be inserted, retrieved, updated and deleted both sequentially and randomly.
  • Records in an RRDS are always fixed in length.

RRDS datasets are similar to Basic Direct Access Method (BDAM) datasets.
 

Control Intervals

There are 4 components in a CI :

  • First component consists of records
  • Second component is called CIDF (Control Interval Description Fields) – 4 bytes long
  • Third component is called RDF (Record Description Field) – 3 bytes long
  • 4th component is free space.

 

Control Area

  • Control Interval – is the smallest unit of information transferred between I/O buffers and the data set. A CI may vary in size from 512 to 32,768 bytes.
  • A control area consists of a minimum of two control intervals. The minimum size of a control area is one track, while the maximum size is one cylinder.
  • A record size is larger than the CI size (minus 7 bytes), the record must be contained in more than one CI. Such record is called a spanned record.



Dataset types – Summary

  • KSDS and ESDS can have up to 253 unique (it is not advisable for more than 5 alternate unique keys) and non-unique alternate keys. RRDS do not support alternate keys.
  • Records can be physically deleted from KSDS and RRDS files, whereas they cannot be deleted from ESDS files.
  • KSDS files are subject to CI and CA splits. ESDS and RRDS don’t have them.
  • Records can be of variable length in KSDS and ESDS. RRDS must have only fixed length records.
  • A KSDS or an ESDS may have spanned records, an RRDS cannot.

 

Access Method Services –Utilities used

Pre-VSAM data management -utility programs

  • IEBGENER to copy the contents of sequential datasets
  • IEHMOVE and IEBCOPY to copy, move, reorganize, expand, backup and restore the contents of partitioned dataset
  • IEBISAM to load, backup, restore, and reorganize the contents of ISAM datasets

However, there is only a single utility for managing all of the
housekeeping needs of VSAM –IDCAMS
It is also known by the functionality it provides – Access Method
Services – or simply AMS.
AMS commands cannot be directly used in TSO prompt and can
be used only with IDCAMS.
 

What is AMS ?

VSAM

Types of AMS Commands

All the AMS commands depicted in the previous diagram fall
under two broad categories namely :
Functional Commands

  • Commands that are used to perform a certain Function are called Functional Commands Ex: DEFINE, ALTER etc

Modal Commands

  • Commands that are used to perform conditional execution of Functional commands are called Modal commands Ex: IF.. THEN.. ELSE..,DO etc

JCL for invoking AMS

A JCL to invoke IDCAMS is given as:
Eg:
//IDCAMS11 JOB ‘AAA BBBB’,CLASS=A,MSGLEVEL=(1,1),MSGCLASS=A
//IDCAMS1 EXEC PGM=IDCAMS,REGION=4096K
//SYSPRINT DD SYSOUT=A
//SYSIN DD
* /* UTILITY COMMAND STATEMENTS */ /* //
 
 


VSAM Cluster

VSAM cluster is nothing but an association of the index, sequence set and data portions of the dataset.
The operating system takes the responsibility of giving program access to the cluster by which access is given to all parts of the dataset simultaneously.
The space occupied by a VSAM cluster is divided into contiguous areas called Control Intervals (CI) and about this concept we have seen in detail in our earlier section.
There are two main components present in a VSAM cluster and they
are as given below:

  • The data component
  • The index component

Data Component of VSAM Cluster : Data records are present in the data component of a VSAM cluster.
Index Component of VSAM Cluster : Index records that correspond to the data component are present in the index component of a VSAM key-sequenced cluster.
 

Defining VSAM clusters

The command used for defining the VSAM cluster is DEFINE CLUSTER which defines the entry name, name of the catalog to contain this definition and its password.
Organization detail like sequential, indexed, or relative, Device and volumes that the data set will occupy, Space required for the data set, Record size and control interval.
 


Type of Cluster

  • INDEXED KSDS
  • NON INDEXED ESDS
  • NUMBERED RRDS
  • LINEAR LDS

KSDS

  • KEYS parameter is mandatory
  • Index component is created
  • Free space parameter has an effect
  • Indexed parameter is the default parameter with clusters

A Sample JCL with IDCAMS utility to define a KSDS cluster is given in the following slide.
 

JCL to define a KSDS cluster

Example of KSDS: After submitting the JCL, it would generate a cluster with dataset name along with a data component & index component.
//JOBNAME    JOB . . .
//STEP1          EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//SYSIN             DD  *
DEFINE CLUSTER(NAME(PROJECT.GROUP.KSDS)  –
VOLUMES(USER01)                                                              –
CYLINDERS(10,5)                                                                 –
CONTROLINTERVAL(4096)                                              –
FREESPACE(10,20)                                                              –
KEYS(6,0)                                                                                –
RECORDSIZE(47,47)                                                           –
DATA                                                                                         –
(NAME(PROJECT.GROUP.KSDS.DATA)                          –
INDEX                                                                                       –
(NAME(PROJECT.GROUP.KSDS.INDEX)                       –
CONTROLINTERVALSIZE(1024)  )
/*
//
 

Defining an ESDS

  • FREESPACE parameter is not used.
  • KEYS parameter has no meaning.
  • No index component.
  • NON INDEXED is used.

JCL to define a ESDS cluster

Example of ESDS: After submitting the JCL, it would generate a cluster with dataset name with a data component
//JOBNAME    JOB . . .
//STEP1          EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//SYSIN DD *
DEFINE CLUSTER ( NAME( PROJECT.GROUP.TYPE )      –
RECORDSIZE(80 80)            –
VOLUMES(USER01)              –
NONINDEXED  )
DATA ( NAME ( PROJECT.GROUP.TYPE.DATA )    –
CYLINDERS ( 15 5 ) )
/*
//
 

Defining a RRDS

  • NUMBERED parameter is used
  • Variable length records are not supported

JCL to define a RRDS cluster

Example of RRDS: After submitting the JCL, it would generate a cluster with dataset name with a data component.
//JOBNAME    JOB . . .
//STEP1          EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//SYSIN DD *
DEFINE CLUSTER ( NAME( PROJECT.GROUP.TYPE )      –
RECORDSIZE(80 80)                       –
VOLUMES(USER01)                         –
NUMBERED  )
DATA ( NAME ( PROJECT.GROUP.TYPE.DATA )    –
CYLINDERS (10  10) )
/*
//

Defining a LDS

  • LINEAR parameter is used
  • Control interval is always with 4096 bytes

 

JCL to define a KSDS cluster

Example of LDS: After submitting the JCL, it would generate a cluster with dataset name with a data component
//JOBNAME    JOB . . .
//STEP1          EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//SYSIN DD *
DEFINE CLUSTER ( NAME( PROJECT.GROUP.TYPE )      –
CYLINDERS(10 10)                          –
VOLUMES(USER01)                         –
CISZ(4096)                 –
LINEAR)
/*
//
 


How to Load VSAM Data Sets

Editing of records into a VSAM dataset is not possible by using
an ISPF edit option, or by using option 3.4 Loading of records
are done by two methods:
Using the REPRO command

  • Repro is a command which is used to copy or load the records into a VSAM file from a PS or from another VSAM file. There are different types of options under REPRO commands.

Using a COBOL program

  • File handling with COBOL application programs.

 

Constraints/Considerations for loading

The Following facts have to be taken into consideration while loading into VSAM files

  • Records being loaded into a KSDS must be pre-sorted in ascending order by key,

Keys should be Unique with no redundancy

  • Records being loaded into an ESDS need not be arranged prior to loading . ESDS records are arranged chronologically(by time of arrival) rather than by any other field
  • Fixed-length RRDS records are loaded by order of their RRN which may be either User supplied or VSAM supplied. As the RRN is not part of the logical record it is not require pre-sorting.
  • Variable-length RRDS records must be Pre arranged in ascending order by unique key values (no duplicates) in the input data set. VSAM assigns RRN to these records in case they are arranges sequentially.

Records can be loaded in one job or in several jobs. If Multiple jobs are used to Load records then they are stored in the same way as that of the preceding job .
 

Loading a KSDS

//JOBNAME    JOB . . .
//STEP1        EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//INPUT DD DSN=PROJECT.GROUP.INPUT, DISP=OLD
//OUTPUT DD DSN= PROJECT.GROUP.KSDS,DISP=OLD
//SYSIN             DD  *
REPRO                           –
INDATASET(INPUT)           –
OUTDATASET(OUTPUT)
/*
//

Loading an ESDS

//JOBNAME    JOB . . .
//STEP1        EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//INPUT DD DSN=PROJECT.GROUP.INPUT, DISP=OLD
//OUTPUT DD DSN= PROJECT.GROUP.ESDS,DISP=OLD
//SYSIN             DD  *
REPRO                           –
INFILE(INPUT)           –
OUTFILE(OUTPUT)
/*
//

Loading a RRDS

//JOBNAME    JOB . . .
//STEP1        EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//INPUT DD DSN=PROJECT.GROUP.INPUT, DISP=OLD
//OUTPUT DD DSN= PROJECT.GROUP.RRDS,DISP=OLD
//SYSIN             DD  *
REPRO                           –
INFILE(INPUT)           –
OUTFILE(OUTPUT)
/*
//

REPRO Command

Now that we have seen example of Loading new records into VSAM files ,we now delve  into  ways to copy , replace and manipulate on the existing records. All this is single handedly managed by The REPRO command
In its most basic form , a REPRO command will look as below
REPRO INFILE(input)
OUTFILE(output)
where input= DD card for Input DSN
Output= DD card for output DSN
The following slides depicts example of how to use REPRO commands for various purposes
 

Options of REPRO Command

REPLACE
//SYSIN DD *
REPRO                                            –
INFILE(PROJECT.GROUP.INPUT)         –
OUTFILE(PROJECT.GROUP.KSDS)    –
REPLACE
/*
REUSE
//SYSIN DD *
REPRO                                           –
INFILE(PROJECT.GROUP.INPUT)        –
OUTFILE(PROJECT.GROUP.KSDS)  –
REUSE
/*

  • SKIP and COUNT

//SYSIN DD *
REPRO                            –
INFILE(PROJECT.GROUP. KSDS)       –
OUTFILE(PROJECT.GROUP.KSDS1)    –
SKIP(3)                                           –
COUNT(2)
/*
FROM KEY and TO KEY
REPRO                             –
INFILE(INPUT)      –
OUTFILE(OUTPUT)  –
FROMKEY(333333)                           –
TOKEY(555555)
/*
FROM ADDRESS and TO ADDRESS
FROM NUMBER and TO NUMBER
 


Printing a Data Set

//JOBNAME    JOB . . .
//STEP1          EXEC  PGM = IDCAMS
//SYSPRINT     DD      SYSOUT=*
//INPUT DD DSN=PROJECT.GROUP.INPUT, DISP=OLD
//SYSIN             DD  *
PRINT                     –
INFILE(INPUT)          –
SKIP(3)                    –
COUNT(2)                 –
CHAR
/*
//