FALSE

Page Nav

HIDE

Grid

GRID_STYLE

VSAM

1.   Access Methods An access method defines the technique by which data is stored and retrieved.   MVS/DFP access methods have their own d...

1.   Access Methods

An access method defines the technique by which data is stored and retrieved.  MVS/DFP access methods have their own data set structures to organize data, process data sets, and utility programs to process data sets.
The different types of dataset organizations in MVS are:
¨       Physical Sequential
¨       Partitioned
¨       Indexed Sequential
¨       Direct
¨       VSAM
VSAM is a high performance access method used in MVS.  It is used for direct or sequential processing of fixed and variable-length records on DASD.  Data organized by VSAM is cataloged for easy retrieval, and is stored in one of four types of data sets.  These data sets are described below.

1.1.     VSAM Dataset Types

1.1.1.    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.

1.1.2.    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.

1.1.3.    Linear Dataset (LDS)

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

1.1.4.    Relative Record Dataset (RRDS)

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

2.   Building blocks of a VSAM Dataset

2.1.     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.

2.2.     Control Interval (CI)

A control interval consists of the following:
¨       Logical records (LR)
¨       Free space (FS)
¨       Control information fields
Control Interval (CI)
Free Space is the space reserved within the CI for inserting new records in a KSDS or for lengthening the existing records.
Control information consists of two types of fields:
Control interval definition field (CIDF) - which is 4 bytes long, and contains information about the C.I., including the amount and location of free space.
Record definition fields (RDF) - which are 3 bytes long, and describe the length of records, and how many adjacent records are of the same length.

2.3.     Control Area

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)

2.4.     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.

2.4.1.    Index Component

Highest Index Set
2210
5000
.........


Index Set
1055
1600
FS

5000
FS
FS

Sequence Set
1010
1055
FS

1350
1600
FS

 

2.4.2.    Data Component

CA 1
1001
1002
1005
1010
FS
1020
1022
1030
1055
FS
FS
FS
FS


CA 2
1300
1305
1310
1350
FS
1400
1410
1415
1600
FS
FS
FS
FS
FS

 

2.5.     Index Levels

VSAM builds two levels of index for a KSDS: the sequence set and the index set.  Given below is a brief description of the sequence and the index sets.

2.5.1.    Sequence Set

The index records at the lowest level form the sequence set.  An entry in a sequence set record consists of the highest possible key in a control interval of the data component, paired with a pointer to that control interval.

2.5.2.    Index Set

A second level index record above the sequence set is called the index set.  An entry in an index set record consists of the highest possible key in an index record in the next lower level, and a pointer to the beginning of that index record.

2.6.     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  :
CA (CI-1 to CI-3) - Before split
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


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.

2.7.     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


F   Note: A Control Area split is always followed by a Control Interval split.

3.   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.

3.1.     Invoking Access Method Services

Access method services is invoked by executing a utility program called IDCAMS, or by issuing the same command from a TSO prompt.
//JOBNAME    JOB  (ACCTINFO),PROG NAME     (Job card)
//STEPNAME  EXEC  PGM=IDCAMS               (Step card)
//SYSPRINT    DD  SYSOUT=A                 (AMS messages go here)
//SYSIN       DD  *
    Functional commands
    Positional parameters
    Keyword parameters
    Sub-parameters
/*
//
F   Note:
1.       All functional commands and their parameters must be within column 2 and 72.
2.       To continue a functional command in the next line, a hyphen (continuation character) must be entered on the previous line.
3.       Absence of a hyphen as the last character indicates the end of a command.

3.2.     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:
¨       The name of the cluster.
¨       The volume(s) on which the data set will be allocated.
¨       The type of data set (KSDS, ESDS, RRDS or LDS).
¨       The space needed for the data set.
¨       For a KSDS, the length of the key and its offset from the beginning of the record.
¨       The record size, and whether it is fixed or variable in length.
¨       The control interval size.
¨       CI and CA Free Space.
The following keywords have to be used to define the different types of VSAM data sets:
1.        NONINDEXED for ESDS.
2.        INDEXED for KSDS.
3.        NUMBERED for RRDS.
4.        LINEAR for LDS.

Sample JCL to create an ESDS cluster

//TRGI01A  JOB  MSGCLASS=X,CLASS=I,REGION=1M,NOTIFY=TRGI01
//DEFKSDS  EXEC PGM=IDCAMS
//SYSPRINT DD   SYSOUT=A
//SYSIN    DD   *
   DEFINE CLUSTER(NAME(userid.TRG1.ESDS)         -
   VOLUMES(USER01)                -
   NONINDEXED                     -
   TRACKS(2,1)                    -
   RECORDSIZE(50,50)              -
   CONTROLINTERVALSIZE(4096)      -
   FREESPACE(10,20))              -
   DATA(NAME(userid.TRG1.ESDS.DATA))
/*

Sample JCL to create an RRDS cluster

//TRGI01A  JOB  MSGCLASS=X,CLASS=I,REGION=1M,NOTIFY=TRGI01
//DEFRRDS  EXEC PGM=IDCAMS
//SYSPRINT DD   SYSOUT=A
//SYSIN    DD   *
   DEFINE CLUSTER(NAME(userid.TRG1.RRDS)         -
   VOLUMES(USER01)                -
   NUMBERED                       -
   TRACKS(2,1)                    -
   RECORDSIZE(50,50)              -
   CONTROLINTERVALSIZE(4096)      -
   FREESPACE(10,20))              -
   DATA(NAME(userid.TRG1.RRDS.DATA))
/*

Sample JCL to create a KSDS cluster

//TRGI01A  JOB  MSGCLASS=X,CLASS=I,REGION=1M,NOTIFY=TRGI01
//DEFKSDS  EXEC PGM=IDCAMS
//SYSPRINT DD   SYSOUT=A
//SYSIN    DD   *
   DEFINE CLUSTER(NAME(userid.TRG1.KSDS)         -
   VOLUMES(USER01)                -
   TRACKS(2,1)                    -
   INDEXED                        -
   KEYS(9,0)                      -
   RECORDSIZE(50,50)              -
   CONTROLINTERVALSIZE(4096)      -
   FREESPACE(10,20))              -
   DATA(NAME(userid.TRG1.KSDS.DATA))   -
   INDEX((NAME(userid.TRG1.KSDS.INDEX))
/*

F   Note:
1.       The KEYS parameter indicates that the primary key is 9 bytes long and starts at position 0 of the record.  Remember that, in a VSAM data set, the first byte is byte 0, the second is byte 1, and so on.
2.       The RECORDSIZE parameter has two values.  The first value gives the average record length, while the second gives the maximum length.  When the average and the maximum are equal, the records are of fixed length.
3.       The primary key of a KSDS must be unique and cannot be modified while updating.

3.3.     Spanned Records

Sometimes a record is larger than the control interval size used for a particular data set.  The SPANNED parameter allows a record to extend across or span control interval boundaries, but not across control areas.
For KSDS, the entire key field of a spanned record must be in the first control interval.
Spanned records can only be used with KSDS and ESDS.

4.   Commands

4.1.     The REPRO Command

The Repro command is used for copying records to and from VSAM datasets.
REPRO INFILE(ddname) / INDATASET(‘data set name’) -
      OUTFILE(ddname) / OUTDATASET(‘data set name’) -
      FROMKEY(key) / TOKEY(key) -
      FROMNUMBER(number) / TONUMBER(number) -
      REPLACE / NOREPLACE -
      REUSE / NOREUSE
Where,
¨       INFILE & OUTFILE specifies the source and target ‘ddnames’
¨       INDATASET & OUTDATASET specifies the source and target data set names
¨       FROMKEY & TOKEY specifies the starting key value, ending key value (for a KSDS)
¨       FROMNUMBER & TONUMBER specify starting record number and ending record number (for a RRDS).
¨       REPLACE - When a KSDS is copied, each source record with a key matching a target record’s key replaces the target record.
¨       NOREPLACE - For each source record whose key matches a target record’s key, a “duplicate record” message is issued.
¨       REUSE - If the data set was originally defined with REUSE, the operation proceeds. If REUSE is specified and the dataset was originally defined with NOREUSE option, the data set must be empty; if not, the REPRO command terminates with an error.
Example :
//TRGI01A  JOB  MSGCLASS=X,CLASS=I,REGION=1M,NOTIFY=TRGI01
//LOADKSDS EXEC  PGM=IDCAMS
//SYSPRINT DD    SYSOUT=A
//SOURCE   DD    DSN=userid.INPUT.DATA,
//               DISP=OLD
//TARGET   DD    DSN=userid.KSDS.CLUSTER,
//               DISP=OLD
//SYSIN    DD    *
   REPRO                -
   INFILE ( SOURCE )    -
   OUTFILE ( TARGET )
/*
F   Note: Ensure the input file is in sorted order before doing REPRO.

Exercise

1.       Create a Physical Sequential file with Data required for Loading.
2.       Create a VSAM data set using Employee number, Employee address, Employee No, Employee sex, Employee Date of Birth, Employee Name.
3.       Copy the data from the PS into the VSAM dataset.

4.2.     The PRINT Command

The PRINT command is used to print the contents of both VSAM and non-VSAM datasets.  The contents of a dataset may be printed in any of the following three formats.
1.        Character Format:: The data set contents are printed in EBCDIC characters.  Any unprintable character will appear as a period.
2.        Hex Format: This format prints each character in a dataset as 2 hexadecimal digits.
3.        Dump Format: The dump format is a combination of character and hex formats.
Note: The Default format is DUMP.


PRINT INFILE(ddname) / INDATASET(‘data set name’) -
                FROMKEY(key) / TOKEY(key) -
      FROMNUMBER(number) / TONUMBER(number) -
                COUNT CHAR / HEX / DUMP
Example :
//TRGI01A  JOB  MSGCLASS=X,CLASS=I,REGION=1M,NOTIFY=TRGI01
//KSDSPRNT EXEC PGM=IDCAMS
//SYSPRINT DD   SYSOUT=A
//SYSIN    DD   *
   PRINT INDATASET('userid.TRG1.KSDS') CHAR
/*
//
Print records 4 through 7 of dataset ‘userid.INPUT.DATA’ in char format.
PRINT INDATASET(userid.INPUT.DATA) SKIP(3) COUNT(4) CHAR
Print 3 records from key 44444444 of dataset userid.TRG1.KSDS in char format.
PRINT INDATASET(userid.TRG1.KSDS) FROMKEY(44444444) COUNT(3) CHAR

Exercise

1.       Print a KSDS in Character Format and in Hex Format
2.       Use SKIP and COUNT options
3.       Use FROMKEY and TOKEY options

4.3.     The LISTCAT Command

All information about a dataset can be listed using this command.
LISTCAT  -
  ENTRIES (name of entries)  -
  ALL/ NAME/ HISTORY/ VOLUME/ ALLOCATION  -
  OUTFILE(ddname)

4.4.     The DELETE Command

This command can be used to delete VSAM and non-VSAM objects.  When a VSAM cluster is deleted, all its associations are automatically deleted.
DELETE (list of entries)  -
  CLUSTER/ ALTERNATEINDEX/ PATH  -
  ERASE  PURGE

4.5.     The VERIFY Command

If the batch job ends abnormally or the CICS system goes down, any VSAM files that are open at the time will be left open.  In this condition the index and data components may not be in sync, i.e., they may not be synchronized.  The VERIFY command closes the files, brings the index component up to date with the data component, and records the necessary changes in the catalog.
VERIFY DATASET(dsname)/ FILE(ddname) 

4.6.     The ALTER Command

The Alter command is used to change the characteristics of a VSAM dataset.
Example :
ALTER ‘userid.TRG.KSDS’  -
  NEWNAME (‘userid.TRG2.KSDS’) 

4.6.1.    The Alternate Index

In addition to the primary key field, records of a KSDS can also be accessed in any key sequence.  This is called an Alternate Key.  The alternate key need not be unique.

4.6.2.    The Alternate Index Cluster

An Alternate Index Cluster is a KSDS cluster consisting of an index and a data component which has key-pointer pair records for an alternate index.  This is applicable for ESDS and KSDS base clusters.

No comments