Professional Documents
Culture Documents
VSAMMAT
VSAMMAT
VSAMMAT
VSAM
VSAM
(VIRTUAL STORAGE ACCESS METHOD)
1
VSAM
Day-wise Schedule...................................................................................................4
1. INTRODUCTION TO VSAM..............................................................................5
Features of VSAM...................................................................................................5
Advantages of VSAM..............................................................................................5
VSAM history..........................................................................................................6
2. VSAM Catalogs......................................................................................................7
Vsam catalog............................................................................................................8
Control Interval......................................................................................................10
Spanned Records....................................................................................................11
ESDS......................................................................................................................13
KSDS......................................................................................................................13
KSDS Structure......................................................................................................14
4. IDCAMS COMMANDS......................................................................................20
5. LISTCAT..............................................................................................................30
2
VSAM
VERIFY.................................................................................................................44
DELETE.................................................................................................................44
PRINT....................................................................................................................45
ALTER...................................................................................................................46
9. Generation DataSets............................................................................................50
11. Appendix-A...........................................................................................................60
VSAM ASSIGNMENT.........................................................................................60
References..............................................................................................................62
13. Appendix-C...........................................................................................................63
14. Appendix-D...........................................................................................................64
3
VSAM
Day-wise Schedule
Day-1
What is catalog?
Types of VSAM datasets
IDCAMS command
COBOL Considerations for ESDS
Listcat overview
Day-2
Introduction to Alternate index
Define Aix
Define path
BLDIndex
COBOL Considerations for AIX
Day-3
IDCAM commands
REPRO, EXPORT/IMPORT
VERIFY, ALTER, DELETE
Additional options on
IDCAMS command
KEYRANGES, IMBED,
REPLICATE
Day-4
READPW, MASTERPW, UPDATEPW options
Creating and using Generation Dataset Groups
Deleting and altering GDGs
4
VSAM
VSAM Introduction
An ACCESS METHOD is a component of the operating system.
It is an interface between the application program and the physical operation of storage
devices.
• Intro Diag.
Application Program
Access Method
Operating Sy stem
Physical
Storage
– Ability to move the same data to a different operating system ( cross Region &
Cross System)
– Basic access methods provide the most low-level services for accessing
datasets.
5
VSAM
– When new records are added, a new storage location is calculated. This leads
to large gaps between records.
Features of VSAM
VSAM (Virtual Storage Access Method) is a high-performance access method used in
mainframe operating systems like OS/VS1, MVS, MVS/XA, DOS/VS etc.
VSAM makes efficient use of the virtual storage of MVS. Hence the name Virtual Storage
Access Method.
VSAM can only manipulate data that resides on a DASD (Direct Access Storage Device).
VSAM is one coherent file storage system used to store and retrieve data. It is not a database
management system like IDMS or DB2. It does not provide for relationships among the data.
The existing databases like IMS or DB2 may be implemented using VSAM.
VSAM is not a programming language. But you can access VSAM dataset through
programming languages like COBOL or PL/I. It is not a communication system like VTAM
or CICS. It has no equivalent for a ‘PDS’ type of file organization.
6
VSAM
Advantages of VSAM
Data retrieval is faster because of an efficiently organized index. The index is small because
it uses a key compression algorithm.
Insertion of records is easy due to embedded free space in the cluster. However, the free
space causes datasets to require more space on the disk.
Records can be physically deleted and space occupied by them can be reused without any
reorganization.
Cross-system (MVS & VSE) Compatibility. VSAM datasets can be imported and imported
in MVS and VSE systems.
Device Independence (Access Via Catalog). The application programmer need not be
concerned with Block size, volume and other control information, as access to VSAM dataset
it always through the Catalog and all control information are stored in the catalog entry of the
dataset.
Datasets can be physically distributed over various volumes based on key ranges
Disadvantages of VSAM
To allow easy manipulation of records in a dataset, free space must be left in the dataset. This
increases the disk space required. However no free space is required for datasets used for
read-only purposes.
7
VSAM
VSAM files are often called clusters. A cluster is the set of catalog entries that represent a
file. A cluster consists of one or two components. All VSAM datasets consist of a data
component in which data records are placed. For KSDS, there is an additional index
component, which contains the indexes used to access records in the data component. ESDS
RRDS and LDS have data component only and no index component
In an ESDS, records are stored in the order in which they were entered.
New records are always added at the end of the dataset (Append).
Random access is possible using the Relative Byte Address (RBA) of the record. The RBA of
the record is the number of bytes in the file before the beginning of that record.
Records can be updated in place but the record length cannot be changed.
An RRDS is a series of continuous fixed-length slots. Each slot may or may not contain a
record. Each slot is identified by its position relative to the first slot in the dataset.
This relative position is called the Relative Record Number (RRN) of the slot.
RRDS records can be inserted, retrieved, updated and deleted and Records can be accessed
sequentially and randomly.
RRDS records are of fixed length. When a record is deleted, the slot remains empty till a
new record is inserted in it. The new record will have the same RRN as the record deleted.
RRDS is not suitable for applications which leave many slots empty as this wastes storage
space.
8
VSAM
These datasets are stored in sequence of some key field in the record. The data component
and index component are separated. The keys are stored in a separate index and records are
accessed through the index. Individual records can be accessed randomly on the basis of the
record key. Locating the record is a two stage process.
An LDS has no logical record structure. It does not contain control information required by
VSAM to organize a dataset into logical records.
The absence of such control information allows very high access speed It is mostly used by
DB2.
These datasets consist of a stream of bytes which are accessed and written as 4k blocks
accessed by Relative Byte Address
VSAM history
VSAM was introducted in 1973. This version had only Entry Sequence Datasets and Key
Sequenced Datasets. In 1975 Relative Record Datasets and alternate indexes for KSDS was
added. In 1979 DF/EF VSAM was introduced with Integrated Catalog Facility (ICF).
DFP/VSAM Ver 1 was introduced in 1987 to run under the MVS/XA architecture.
DFP/VSAM version 2 introduced Linear Datasets (LDS)
9
VSAM
Master catalog
User catalog
There’s only one Master catalog per system. The entries in the master catalog may point to
VSAM or non-VSAM dataset, user catalogs, system datasets or other objects.
User catalogs contain same type of information as master catalog. All user catalogs must be
cataloged into master catalog.
Access to a dataset can only be made through a master or user catalog. Therefore all VSAM
datasets have to be cataloged. Non-VSAM datasets can also be cataloged. Catalogs are
protected by RACF.
Master
Catal og
VS AM User
Non-VSAM Catalogs
data sets
data sets
VS AM Non-VSAM
data sets data sets
VSAM Catalog
Vsam catalog
Catalogs maintain the following information
The relatively permanent and temporary parts of the information are stored separately.
10
VSAM
The part of the catalog storing stable information is called the Basic Catalog Structure (BCS).
It was physically stored as a single KSDS and the volatile information is stored in several
VVDS (VSAM Volume DataSets).
Each volume having VSAM datasets has a VVDS on it. A VVDS is physically an ESDS. A
VVDS has a standard name: SYS1.VVDS.Vxxx where xxx is the volume label of that
volume.
Vsam records
VSAM records can be fixed or variable length. Records can also be spanned across the CI.
VSAM space allocation depends on whether the dataset is cataloged in an ICF or the older
VSAM type catalog. For VSAM datasets cataloged in the newer ICF-type catalogs, dedicated
space is allocated dynamically when the cluster is created with the DEFINE CLUSTER
command.
Each VSAM dataset cataloged in an ICF catalog has its own VTOC entry. These VSAM
datasets can have 1 primary and 122 secondary allocation unlike OS dataset which can have
only 1 primary and 15 secondary extends on a volume.
VSAM maintains detailed information in its catalogs about DASD space allocated to VSAM
files. This allocation information stored in the catalog is more comprehensive and flexible
than the equivalent information stored for a non-VSAM file in VTOC.
Control Interval
A control interval is the unit of data VSAM transfers between virtual and disk storage. It is
similar to the concept of block size in non-VSAM files. Each control interval can contain
more than one logical record.
The size of CI must be between 512 bytes to 32K. Up to 8K bytes it must be multiple of 512;
beyond this it is multiple of 2K. The length of the CI is specified at file creation time ie.
During DEFINE CLUSTER command.
CI is the unit of data that is actually transmitted when records are read / written
11
VSAM
A Control Interval consists of records, free space and control field information as shown
below.
In the Control Interval shown above Rec1, Rec2, Rec3 are records. Free Space is where new
records can be inserted.
CF
RDF CIDF
Control Interval Descriptor Field (CIDF) which is of 4bytes contains information about
available space within CI. Record Descriptor Field (RDF) contains the length of each record
and how many adjacent records are of the same length. There’s one RDF for each record in
variable length records.
There will be only two RDF’s per CI in case of fixed length files. One RDF specifies the
length of the record and the second RDF specifies how many records are there in the CI. Each
RDF is of 3 bytes.
Control Areas
Control Area is a fixed length unit of contiguous DASD storage. Control Area consists of
many Control Intervals and is VSAM’s internal unit for allocating space within a cluster.
12
VSAM
The Control Area size can vary from one track to one cylinder depending on unit of
allocation. There is no way a Control Area size can be defined. VSAM computes it internally.
CONTROL AREA
CONTROL INTERVAL
CONTROL INTERVAL
CONTROL INTERVAL
CONTROL INTERVAL
CONTROL INTERVAL
Spanned Records
Spanned records are records larger than the specified CI size. That is they span more than one
CI. So one spanned record may be stored in several CIs.
Each CI that contains a record segment of a spanned record has two RDFs. The right RDF
gives the length of the segment and the left gives the update number of the segment. Spanned
records can exist only in ESDS and KSDS.
A CI that contains a record segment of a spanned record contains no other data. Records can
span Control Intervals but not Control Areas. For KSDS the entire key field of the spanned
record must be in the first Control Interval.
Logical Record 1
13
VSAM
ESDS
ESDS is a sequential dataset. Records are retrieved in the order in which they are written to
the dataset. Additions are made always at the end of the file. Records can be retrieved
randomly by using RBA (Relative Byte Address). RBA is an indication of how far, in bytes,
each record is displaced from the beginning of the file.
KSDS
In Key Sequenced Datasets logical records are placed in the dataset in the ascending collating
sequence by the key field.
Key must be in same position in each record and key data must be contiguous
When a new record is added to a dataset it is inserted in its collating sequence by key
DATA Component: - Contains control areas which in turn contains Control Intervals as
shown in below
14
VSAM
KSDS Structure
Index Set
,
Sequence Set
The first level of index is called a Sequence set. The Sequence set consists of Primary keys
and pointers to the Control Intervals holding records with these primary keys. The Sequence
set is always in sequential order of the primary keys. The Control Intervals may be in any
order. VSAM uses the Sequence Set to access records in the KSDS sequentially.
The index component is a separate entity with a different CI size, a different name and can be
stored on a different volume.
Sequence Set
15
VSAM
CI CI CI CI
Index Set
Index
component
Sequence Set Sequence Set
CA1 CA2
CI CI CI CI CI CI CI CI
Figure 3.7 Contents of Index Set
16
VSAM
New
Record
After Inserting
17
VSAM
New
Record Full
Control Interval
FSPC US CF
Empty
Control
Interval
18
VSAM
Sequence Set
I 0 K 100
New
Record
100
200
FSPC US CF
19
VSAM
E 0 I 200 K 100
0
RecordA RecordB RecordC FSPC US CF
100
RecordJ RecordK FSPC US CF
200
20
VSAM
DEFINE
MODAL COMMANDS
IF
SET
PARM
BUILDINDEX
REPRO
PATH
DELETE
VERIFY
IMPORT/EXPORT
ALTER
LISTCAT
The example shown below is a skeleton JCL for executing IDCAMS commands. The PGM
parameter specifies that the program to be executed is IDCAMS utility program. The
statements that follow SYSIN DD * are IDCAMS commands. The end of data is specified by
/*.
21
VSAM
Optionally JOBCAT and STEPCAT statements may be coded to indicate catalog names for a
job/step, in which concerned dataset may be cataloged
Every IDCAMS command starts with a verb followed by object which takes some
parameters. In the code given below DEFINE is the verb CLUSTER is the object which takes
a dataset KASSHKU.KSDS.CLUSTER as parameter
DEFINE CLUSTER -
NAME(KASSHKU.KSDS.CLUSTER) -
CYL/TRK/BYTE(5, 1) -
VOLUMES (BS3013) -
INDEXED -
)
Creating a cluster
Comments:
/* comment */
or
/* -----
*/
22
VSAM
The IDCAMS Commands return certain codes which have the following interpretation
Condition code:
The condition codes are stored in LASTCC/MAXCC. LASTCC stores the condition
code for the previous command and MAXCC stores the maximum code returned by
all previous commands. Both LASTCC and MAXCC contain zero by default at the
start of IDCAMS execution. You can check the condition code of the previous
command and direct the flow of execution or terminate the JCL.
Syntax of IF statement
IF LASTCC/MAXCC
comparand VALUE -
THEN -
command
ELSE
Command
Operator(s) are : EQ / NE / GT / LT / GE / LE
Hyphen is required after then to indicate the continuation of the command on the next line.
Comment is assumed as null command. ELSE is optional. LASTCC and MAXCC values can
be changed using the SET command.
Note : LASTCC and MAXCC can also be set to any value between 0-16
e.g.
SET LASTCC = 4
Setting MAXCC has no effect on LASTCC. Setting LASTCC changes the value of MAXCC,
if LASTCC is set to a value larger than MAXCC. Setting MAXCC = 16 terminates the job
23
VSAM
.........
REPRO INFILE (INDD) -
OUTFILE (OUTDD)
................
IF LASTCC EQ 0 -
THEN -
PRINT OUTFILE (INDD)
ELSE
PRINT INFILE (OUTDD)
IF MAXCC LT 4 -
THEN -
DO
/* COMMENT */
Command
Command
END
ELSE
Command
DEFINE CLUSTER
….
IF LASTCC > 0 THEN
SET MAXCC = 16
ELSE
REPRO
……
Clusters are created and named with the DEFINE CLUSTER command.
Format : NAME(Cluster-Name)
Cluster name :- The name to be assigned to the cluster
24
VSAM
The high-level qualifier is important because in most installations this technique ensures that
VSAM datasets are cataloged in the appropriate user catalog.
The space allocation parameter specifies space allocation values in the units shown below:
Format :
CYLINDERS(Pri Sec)
TRACKS(Pri Sec)
RECORDS(Pri Sec)
KILOBYTES(Pri Sec)
MEGABYTES(Pri Sec)
Primary: Number of units of primary space to allocate. This amount is allocated once when
the dataset is created
Allocating space in RECORDS must be avoided as this might result in an inefficient Control
Area size.
This VOLUMES parameter assigns one or more storage volumes to your dataset. If Multiple
volumes, then it must be of the same device type.
Format :
VOLUMES(volser) or VOLUMES(volser ........ volser)
25
VSAM
Example :
VOLUMES(BS3011)
VOLUMES(BS3011 BS3040 BS3042)
You can store the data and index (in case of KSDS clusters) on separate volumes as
this may provide a performance advantage for large dataset
This parameter tells VSAM what size records to expect. The AVE and MAX are average and
maximum values for variable length record. If records are of fixed length, avg and max
should be the same.
Format :
RECORDSIZE(avg max)
e.g. :
RECORDSIZE(80 80) [Fixed Length records]
RECORDSIZE(80 120) [Variable Length records]
RECORDSIZE can be assigned at the cluster or data level
Note :
This parameter allows large record to span more than one control interval. However records
cannot span Control Areas. The resulting free space in the spanned control interval is
unusable by other records, even if they fit logically in the unused bytes. [NONSPANNED is
the default & it means that records cannot span control intervals.
26
VSAM
DEFINE CLUSTER -
(NAME(KASSHKU.ESDS.CLUSTER) -
NONINDEXED -
RECORDSIZE(125 125) -
NONSPANNED -
VOLUMES (BLR01) -
REUSE ) -
DATA(NAME(KASSHKU.ESDS.DATA))
The DATA parameter tells IDCAMS that you are going to create a separate data component.
This parameter is optional for ESDS and RRDS datasets. You should code the NAME
parameter of DATA for KSDS datasets, in order to operate on the data component by itself.
Format :
DATA (NAME (dataname) Parameters)
Format :
INDEX(NAME(indexname) Parameters)
indexname : The name you choose to name the index component
INDEX(NAME(DA0004T.LIB.KSDS.INDEX))
When you code the DATA and INDEX parameters, you usually coda a NAME parameter for
them. If you omit the NAME parameter for DATA and INDEX, VSAM appends .DATA
or .INDEX as the low-level qualifier.
27
VSAM
This parameter defines the length and offset of the primary key in a KSDS record.
The offset is the primary key’s displacement (in bytes) from the beginning of the record.
Format :
KEYS (length offset)
Example :
KEYS(8 0)
VSAM records begin in position zero.
Note :
Default is KEYS(64 1) [Key is in bytes 2 thru 65]
DEFINE CLUSTER(
NAME(DA0001T.LIB.KSDS.CLUSTER) -
INDEXED -
KEYS(4 0) -
FSPC(10 20) -
RECORDSIZE(125 125) -
NONSPANNED -
VOLUMES (BS3013) -
NOREUSE ) -
DATA(NAME(DA0001T.LIB.KSDS.DATA)) -
INDEX(NAME(DA0001T.LIB.KSDS.INDEX))
/*
//
JCL for D
efining a KSDS Cluster
er
This FREESPACE parameter, which applies to the KSDS, allocates some percentage of
control interval and control area for planned free space. This free space can be used for
adding new records or for expanding existing variable records. FREESPACE applies only to
the data component
28
VSAM
Format :
FREESPACE(%CI %CA)
Too much free space results in more I / O, especially when doing sequential processing. Too
little results in excessive control interval and control area split
Note :
Default is FREESPACE(0 0)
The REUSE parameter specifies that the cluster can be opened a second time as a
reusable cluster. NOREUSE is the default, and specifies the cluster as non-reusable.
Format :
REUSE | NOREUSE
Some application call for temporary dataset or workfile that must be created, used and
deleted each time the application runs. To simplify these applications, VSAM lets you create
reusable files. The reusable file is a standard VSAM KSDS, ESDS or RRDS. The only
difference is that, if you open an existing reusable file for output processing, VSAM treats the
file as it were empty. Any records already present in the file are ignored.
This parameter specifies the Control Interval size. It is usually abbreviated CISZ.
Format :
CI
SZ (bytes)
Example :
CISZ (4096)
Remark : Control Interval is VSAM’s equivalent of a block and it is the unit of data that is
actually transmitted when records are read or written.
29
VSAM
ESDS is processed sequentially, so the CISZ should be relatively large, depending on the size
of the record. For sequential processing with larger records you may choose a CISZ of 8k.
For datasets processed randomly as well as sequentially (for backup at night) choose a CISZ
for random processing and then allocate extra buffers for sequential processing with the AMP
JCL parameter.
RRDS is usually processed randomly, so the CISZ should be relatively small, depending on
the size of the record.
SHAREOPTIONS
This parameter tells VSAM whether you want to let two or more jobs to process your file at
the same time. It specifies how a VSAM dataset can be shared
Format :
CROSS REGION value : Specifies the value for cross region sharing. Cross region sharing
is defined as different jobs running on the same system using Global Resource Serialization
(GRS), a resource control facility available only under MVS/XA and ESA.
CROSS SYSTEM value : Specifies the value for cross system sharing means different jobs
running on different system in a NONGRS environment.
Values :-
multiple read OR single write
multiple read AND single write
multiple read AND multiple write
Default :- SHAREOPTIONS(1 3)
30
VSAM
18. LISTCAT
LISTCAT’s basic function is to list information about VSAM and NONVSAM objects. With
LISTCAT you can also view password and security information, usage statistics, space
allocation information, creation and expiration dates etc.
Format 1:
Options are :
HISTORY
VOLUME
ALLOCATION
ALL
ENTRIES (ENT) requires you to specify each level of qualification, either explicitly or
implicitly, using an asterisk as a wild card character.
Examples:
LISTCAT
ENT(DA0001T.VSAM.KSDS.CLUSTER) -
CLUSTER -
ALL -
LISTCAT
LISTCAT
ENT(DA0001T.VSAM.KSDS.CLUSTER) -
DATA -
ALL -
LISTCAT
ENT(DA0001T.VSAM.KSDS.CLUSTER) -
ALL
31
VSAM
//SYSPRINT DD SYSOUT=*
//SYSINDD *
LISTCAT -
ENTRIES(DA0001T.LIB.KSDS.CLUSTER) ALL
/*
Format 2:
LISTCAT LEVEL(level) options
LEVEL by definition lists all lower levels. VSAM assumes that qualifier to be the high-level
qualifier and list every entry with that high level qualifier .
Example
The above will list all entries with DA0001T as high level qualifier , anything in the second-
level qualifier and KSDS in the third-level qualifier . That is it would list
DA0001T.ABC.KSDS and DA0001T.TEST.KSDS.AIX, DA0001T.TEST.KSDS.DATA .
If you analyze the output of the LISTCAT command there is ALLOCATION information
which shows two fields HURBA and HARBA.
HIGH-ALLOC-RBA indicates the Relative Byte Address(plus 1) of the last allocated data
control area. This value reflects the total space allocation for the data component.
HIGH-USED-RBA indicates the Relative Byte Address(plus 1) of the last used data control
area. This value reflects the portion of the space allocation that is actually filled with data
records.
There are actually to HURBAs one in the VSAM control block of the cluster and one in the
catalog entry for the cluster.
You can write application programs (in COBOL, PL/I Assembler Language, in CICS) and
use the statements provided by these languages to write and read VSAM datasets
32
VSAM
VSAM cluster
HARBA
Data space
allocated but
empty
HURBA
Data space
loaded with
records
33
VSAM
34
VSAM
35
VSAM
36
VSAM
37
VSAM
38
VSAM
39
VSAM
40
VSAM
41
VSAM
42
VSAM
43
VSAM
44
VSAM
45
VSAM
46
VSAM
47
VSAM
48
VSAM
RELATE Parameter
Format:
RELATE(base cluster name)
This parameter establishes the relationship between the base cluster and the alternate index
via the use of the base cluster name. It is unique to the DEFINE AIX command, and it is
required.
Format:
RECORDSIZE(avg max)
This parameter specifies the average and maximum length of each alternate index record.
There are two types of alternate indexes.
KSDS unique alternate index: You can create a unique alternate index by specifying the
UNIQUEKEY parameter. The records of unique alternate indexes are of fixed length. The
length of a unique alternate index built over a KSDS is derived as follows:
49
VSAM
For example if a unique alternate index on Soc-Sec-No is built on our KSDS cluster
Employee then the RECORDSIZE will be calculated as follows:-
5 Bytes fro HouseKeeping + size of alternate key + Size of Primary Key that the alternate
= 5 + 9 + 8 = 22
Therefo
re recordsize parameter will be coded as RECORDSIZE(20 20)
Avgerage Record length = 5 bytes for House Keeping + size of the alternate key + size of
the primary key x average no of records the alternate index key can point to
Maximum Record length = 5 bytes for House Keeping + size of the alternate key + size of
the primary key x maximum no of records the alternate index key can point to
Define an Alternate Index Path using the IDCAMS DEFINE PATH command. The path
forms a connection between the alternate index and the base cluster. Path name becomes a
catalog entry but path does not contain any records. The path name is specified in the JCL for
applications that access records via the alternate index.
50
VSAM
UPDATE vs NOUPDATE
Records may be accessed by applications by the alternate index path alone, without opening
the base cluster. In such cases any changes made to data will be reflected in the alternate
index records if the UPDATE option is specified. If NOUPDATE is specified then the
alternate index records will not be automatically updated.
The UPDATE/NOUPDATE option of DEFINE PATH works in tandem with the UPGRADE
/ NOUPGRADE of the DEFINE AIX command.
UPGRADE specifies that any changes made in the base cluster records will be reflected
immediately in the alternate index records if the base cluster is opened in the application.
Fortunately UPGRADE and UPDATE are defaults for their respective commands.
The final step in creating an alternate index is to actually build and populate it with records.
The BLDINDEX command does the following:
The data component of the base cluster is read sequentially and pairs of key pointers
are extracted. These pairs consist of the alternate key field and its corresponding
primary key field. VSAM creates a temporary file with these records.
These records are the data component of the Alternate Index. VSAM now constructs
the index component just as it does for the KSDS.
Note: The Alternate Index can be built only after the base cluster has been both defined and loaded
with atleast 1 record.
//SYSPRINT DD SYSOUT =*
51
VSAM
//DD1 DD DSN=DA0001T.LIB.KSDS.CLUSTER,
// DISP=OLD
//IDCUT1 DD UNIT=SYSDA,SPACE=(TRK, (2, 1))
//IDCUT2 DD UNIT=SYSDA,SPACE=(TRK, (2, 1))
// SYSIN DD *
BLDINDEX -
INFILE(DD1) -
OUTDATASET(DA0001T.LIB.KSDS.AUTHNAME.AIX) -
INTERNALSORT
/*
//
JCL to build Alternate Index
Disposition of base cluster is DISP=OLD as the BLDINDEX needs absolute control of the
base cluster. Output dataset can be Alternate index cluster or pathname
The INTERNALSORT uses virtual storage whereas EXTERNAL SORT uses disk space.
INTERNALSORT is the default. If you want an external sort to be performed then include
IDCUT1 and IDCUT2 DD statements in your JCL and specify EXTERNALSORT in the
BLDINDEX command.
DEFINE Cluster
(NAME(DA0001T.LIB.KSDS.CLUSTER)
.
)
DEFINE AIX
(NAME(DA0001T.LIB.KSDS.AUTHNAME.AIX) RELATE(DA0001T.LIB.KSDS.CLUSTER)
.
)
DEFINE PATH (NAME(DA0001T.LIB.KSDSK.AUTHNAME.PATH)
PATHENTRY(DA0001T.LIB.KSDS.AUTHNAME.AIX)
.
)
BLDINDEX
INDATASET(DA0001T.LIB.KSDS.CLUSTER)
OUTDATASET(DA0001T.LIB.KSDS.AUTHNAME.AIX)
.
52
VSAM
53
VSAM
REPRO
REPRO command can operate on non-VSAM datasets. It is an all-purpose load and backup
utility command and can be used in place of IEBGENER.
54
VSAM
While it is not possible to edit the input to REPRO, you can limit the input by providing the
optional parameters.
FROMKEY and TOKEY parameters: FROMKEY specifies the key of the input records at
which to begin reading. TOKEY specifies the key to stop reading or the last input record.
SKIP and COUNT parameters. SKIP specifies the number of input records to skip before
beginning to copy. COUNT specifies the number of output records to copy. You can specify
both. For example skip 10 records and copy next 10
//DD1 DD DSN=DA0001T.INPUT.KSDS,DISP=OLD
//DD2 DD DSN=DA0001T.OUTPUT.KSDS, DISP=OLD
//SYSINDD *
REPRO -
INFILE(DD1) -
OUTFILE(DD2) -
FROMKEY(A001) -
TOKEY(A069)
FROMADDRESS (RBA)
TOADDRESS(RBA)
FROMNUMBER (RRN)
TONUMBER(RRN)
COUNT (NO.)
SKIP(NO)
55
VSAM
//JOBNAME DA0001TA…
//STEP10 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT = *
//DD2 DD DSN=DA0001T.KSDS.INV.BACKUP(+1),
// DISP=(NEW,CATLG,DELETE),UNIT=TAPE,
// VOL=SER=32970,LABEL=(1,SL),
// DCB=(RECFM=FB,LRECL=80)
//SYSIN DD *
REPRO
INDATASET(DA0001T.KSDS.INV.CLUSTER) –
OUTFILE(DD2)
/*
//
In the example above INDATASET is the input file and DD2 is the output tape dataset
which is a part of the GDG while is more or less like a physical sequential file. (Ref to
chapter 10 for more on GDG’s )
When you DELETE-DEFINE-REPRO a VSAM dataset it has the following effects on the
KSDS.
The dataset is reorganized that is the Control Interval and Control Area splits are
eliminated
Free space is redistributed throughout the dataset as specified in the FREESPACE
parameter.
Primary index is rebuilt, however the DELETE command deletes the base cluster as
well as its indexes. So the alternate indexes have to be redefined
ESDS or RRDS need not be reorganized because the record position is fixed permanently by
sequence of entry or record number.
56
VSAM
//DD1 DD DSN=DA0001T.LIB.KSDS.BACKUP(0),
// DISP=OLD, UNIT=TAPE,LABEL=(1,SL)
//SYSIN DD *
DELETE DA0001T.LIB.KSDS.CLUSTER
/* DEFINE CLUSTER NAME(DA0001T.LIB.KSDS.CLUSTER) -
INDEXED -
KEYS(4 0) -
RECORDSIZE(80 80) -
VOLUMES(BS3013) -
) -
DATA(NAME(DA0001T.LIB.KSDS.DATA)) -
INDEX(NAME(DA0001T.LIB.KSDS.INDEX))
REPRO -
INFILE(DD1) -
OUTDATASET(DA0001T.LIB.KSDS.CLUSTER)
/*
The REPRO command can also be used to merge two datasets into one. The target dataset
can be a nonempty KSDS, ESDS or RRDS. If the target dataset is an ESDS, the merged
records are added to the end of the existing dataset.
EXPORT/IMPORT Commands
The EXPORT/IMPORT commands can be used for backup and recovery . You can export a
dataset, alternate index or a catalog to a different system.
Cluster deletion and redefinition not required during import as input dataset already contains
catalog information
57
VSAM
Like REPRO KSDS datasets are reorganized however three steps of REPRO are replaced by
one
Disadvantages:
EXPORT
FORMAT :
Optional parameters
Example :
EXPORT DA0001T.LIB.KSDS.CLUSTER -
OUTFILE(DD2)
The output dataset from an EXPORT must always be a sequential dataset (usually on a tape)
IMPORT
Format :
IMPORT -
INFILE(ddname) | INDATASET(dsname) -
OUTFILE(ddname) | OUTDATASET(dsname) -
Optional parameters:
58
VSAM
59
VSAM
Format :
VERIFY FILE(ddname/passwd)
or
VERIFY DATASET(entryname/passwd)
VERIFY entryname/passwd (TSO)
VERIFY DATASET(DA0001T.LIB.KSDS.CLUSTER)
Remark :
DELETE
- logically deletes dataset
- catalog entry deleted
Format :
DELETE entryname
/passwd -
optional parameters
DELETE DA0001T.LIB.KSDS.CLUSTER -
ERASE
Example 8.2 Deleting a Cluster
60
VSAM
FORCE | NOFORCE
PURGE | NOPURGE
SCRATCH | NOSCRATCH
PRINT
The default output destination for PRINT is SYSPRINT.
prints in CHAR/HEX/DUMP format
limiting
Format 1 :
PRINT INDATASET (entryname/passwd) -
Format 2 :
PRINT INFILE (ddname/passwd) - parameters like REPRO are available
Options
CHAR | DUMP | HEX
COUNT (number)
FROMADDRESS, [TOADDRESS]
FROMKEY, [TOKEY]
FROMNUMBER, [TONUMBER]
OUTFILE (ddname)
SKIP (number)
61
VSAM
ALTER
Used to change certain attributes of a previously defined VSAM object
Following can be done with ALTER
change names
Add volumes/Remove volumes
Change Keys and uniqueness
Change record size
Change Upgrade option
Change % of FREESPACE etc.
Format :
ALTER entryname/passwd parameters
Options :
ADDVOLUMES (volumes)
AUTHORIZATION(entry string)
BUFFERSPACE (size)
ERASE | NOERASE
FREESPACE(ci% ca%)
MASTERPW(password)
NEWNAME(newname)
READPW (password)
SCRATCH | NOSCRATCH
SHAREOPTIONS
(cross region cross system)
TO(date) |FOR(days)
UPDATE | NOUPDATE
UPDATEPW(password)
UPGRADE | NOUPGRADE
The ORDERED Parameter tells VSAM to assign the KEYRANGES values to the volumes,
one by one, in the order in which the KEYRANGES and VOLUMES are specified.
Format :
ORDERED | UNORDERED
62
VSAM
Examp
le :
KEYRANGES( (0001 1000) -
(1001 2000) -
(2001 3000)) -
VOLUMES (BS3013 -
BS3014 -
BS3001)
Note : When you code ORDERED, you must code the same no. of VOLUMES as KEYRANGES.
The IMBED Parameter directs VSAM to place the sequence set on the first track of the Data
Control Area and duplicate it as many times as it will fit.
Advantage : reduces rotational delay
Format :
IMBED | NOIMBED
The REPLICATE Parameter directs VSAM to duplicate each index record as many times as
it will fit on its assigned track. It applies to a KSDS index component only.
Format :
REPLICATE | NOREPLICATE
Example :
INDEX(NAME(DA0001T.LIB.KSDS.INDEX) -
IMBED -
REPLICATE -
)
VSAM provides a hierarchical list of parameters that you can specify for a non-DFSMS-
managed VSAM dataset. However DFSMS-managed dataset you must use a security package
like RACF.
63
VSAM
Format :
MASTERPW(password)
Allows the highest level of access to all cluster components, including DELETE and ALTER
authority
Format :
UPDATEPW(password)
Format :
READPW(password)
Example :
MASTERPW(TRGDEPT)
At the execution time, a password can be coded explicitly in the PASSWORD clause of a
COBOL SELECT clause
Format :
AUTHORIZATION (entry-point password)
Example :
AUTH(MYRTN ‘TRGDEPT’)
ALTER -
DA0001T.LIB.KSDS.CLUSTER -
NEWNAME(A2000.MY.CLUSTER)
64
VSAM
ALTER -
DA0001T.LIB.KSDS.INDEX -
FREESPACE(30 30)
The following attributes are unalterable. You have to DELETE the cluster and redefine it
with new attributes.
CISZ
Cluster type,
IMBED/REPLICATE
REUSE | NOREUSE
65
VSAM
3. Generation DataSets
Although there are many different uses for sequential datasets, many sequential files have one
characteristics in common : they are used in cyclical application
for example, sequential dataset that contains transaction posted daily against a master file is
cyclical; each days transactions, along with the processing required to post them, from one
cycle. Similarly a sequential dataset used to hold the backup copy of a master file is cyclical
too; each time a new backup copy is made, new cycle is begun.
In most of the cyclical applications, it’s good idea to maintain versions of the files used for
several cycles. That way if something goes wrong, you can recreate the processing that
occurred during previous cycles to restore the affected files to a known point. Then the
processing can continue from that point
For this MVS provides a facility called generation data group, GDG is a collection of two or
more chronologically related versions of the same file. Each version of the file or member of
the GDG, is called a generation dataset. A generation dataset may reside on tape or DASD. It
is generally sequential (QSAM) or direct(BDAM) file. ISAM and VSAM files can’t be used
in GDGs.
As each processing cycle occurs a new generation of dataset is added to the generation data
group. The new version becomes the current generation; it replaces the old current
generation, which becomes a previous generation.
Figure above is the structure of a generation data group. There are 3 previous generations,
note that generations are numbered relative to the current generation, file.c1(0).
Relative generation numbers are adjusted when each processing cycle completes, so that the
current generation is always referred to as relative generation 0.
MVS uses the generation data group’s catalog entry to keep track of relative generation
numbers. As a result, GDGs must be cataloged and each generation dataset that’s a part of the
group must be cataloged too.
When you create a generation data group’s catalog entry, you specify how many generations
should be maintained Example: You might specify that five generations including the current
generation should be maintained. Then during each processing cycle, the new version of the
file becomes the current version.
66
VSAM
Although MVS lets you use relative generation numbers to simplify cyclical processing,
MVS uses “Absolute Generation Numbers” in the form GnnnnV00 to identify each
generation dataset uniquely. GnnnnV00 represents the chronological sequence number of the
sequence number of the generation, beginning with G0000.
V00 is a version number, which lets you maintain more than one version of a generation.
Each time a new generation dataset is created, mvs adds one the sequence number. The
sequence and version numbers are stored as a part of the file’s dataset name, like this:
filename.GnnnnV00
35 chars 9 chars
// IN DD DSN=DA0002T.MASTER, DISP=SHR
// OUT DD DSN=DA0002T.MASTER.DAY(+1),
DISP= (NEW,CATLG,DELETE),
UNIT=3390, VOL=SER=BP0031,
SPACE= (CYL,(10,5),RLSE),
DCB=(PROD.GDGMOD,
BLKSIZE=23440,LRECL=80,RECFM=FB)\
67
VSAM
//DA0003TA JOB
//UPDATE EXEC PGM=PAY3200
//OLDMAST DD DSN=MMA2.PAY.MAST(0),DISP=OLD
//NEWMAST DD DSN=MMA2.PAY.MAST(+1),
DISP= (NEW,CATLG),UNIT=3300,
VOL=SER=BS3001,
DCB=(LRECL=80,BLKSIZE=1600)
//PAYTRAN DD DSN=MMA2.PAY.TRAN,DISP=OLD
//PAYLIST DD SYSOUT=*
//REPORT EXEC PGM=PAY3300
//PAYMAST DD DSN=MMA2.PAY.MAST(+1),DISP=OLD
//PAYRPT DD SYSOUT=*
//JOB1 JOB
//UPDATE EXEC PGM=PAY3200
//OLDMAST DD DSN=MMA2.PAY.MAST(0),DISP=OLD
//NEWMAST DSN=MMA2.PAY.MAST(+1),
DISP=(NEW, CATLG), UNIT=3300,
VOL=SER=BS3001,
DCB=(LRECL=80, BLKSIZE=1600)
//PAYTRAN DD DSN=MMA2.PAY.TRAN,DISP=OLD
//PAYLIST DD SYSOUT =*
//JOB2 JOB ...........
//REPORT EXEC PGM=PAY3300
//PAYMAST DD DSN=MMA2.PAY.MAST(0),DISP=OLD
//PAYRPT DD SYSOUT=*
GDG’s are a
group of datasets which are related to each other chronologically and functionally.
Generations can continue until a specified limit is reached. The LIMIT parameter
specifies total number of generations that can exist at any one time.
Once limit is reached the oldest generation is deleted.
GDG Index
have to be created using the IDCAMS command ‘DEFINE GDG’ before datasets that are to
be included in them can be made a part of them.
Model containing parameter information of the datasets to be included in the GDG has to be
specified.
All datasets within a GDG will have the same name. Generation number of a dataset, within a
GDG is automatically assigned by OS when created. Datasets within a GDG can be
referenced by their relative generation number. Generation 0 always references current
generation
68
VSAM
Creation of GDGs
Specification
Name of GDG
Number of generations
Limit …. maximum no of datasets in a GDG.
Action to be taken when limit is reached
NOEMPTY…
EMPTY …
SCRATCH ….
NOSCRATCH …
69
VSAM
Name of the model containing the GDG DCB parameter’s is coded in the DCB parameter of
the DD statement
Example :
70
VSAM
ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVE
ACCESS MODE IS SEQUENTIAL/INDEXED/DYNAMIC
RECORD KEY IS primary Key Dataname
ALTERNATE KEY IS Alternate Key Dataname [With Duplicates]
FILE STATUS IS status-key.
FD Entry
If KSDS then key field must match with length and position of KEYS parameter in DEFINE
CLUSTER information
File Processing
In JCL there must be a DD statement for base cluster and one or more DD statement for
alternate index path name.
Note: There is no COBOL standard for assigning ddnames to alternate indexes, so a quasi-
standard has emerged whereby a sequential number is appended to the eighth character of the base
cluster ddname.
//LIBMAST DD DSN=DA0001T.LIB.KSDS.CLUSTER,
// DISP=SHR
//LIBMAST1 DD DSN=DA0001T.LIB.KSDS.NAME.PATH,
// DISP=SHR
//LIBMAST2 DD DSN=DA0001T.LIB.KSDS.DEPT.PATH,
// DISP=SHR
Example 10.2 JCL to access AIX
71
VSAM
Remark:
No matter how many alternate indexes you specify in the program, there’s only one ASSIGN
clause pointing to the ddname of the base cluster.
FD : Should have record description having primary key dataname and alternate key
dataname
Key of Reference.
The key that is currently being used to access records is called the key of reference. When the
program opens the dataset, the primary key becomes, by default, the key of reference. The
primary key remains the key of reference when accessing records until it is changed. To start
accessing records by an alternate index key, you merely change the key of reference by using
the KEY phrase as part of one of the following statements.
START EMP-MAST
KEY IS EQUAL TO EMP-NAME.
Example 10.6 START verb
72
VSAM
Invalid key.
2 1 Sequence error.
2 Duplicate key.
3 No record found.
4 Key outside boundary of dataset.
Logic error :
4 1 OPEN of dataset already open.
2 CLOSE for dataset not open.
3 READ not executed before REWRITE.
4 REWRITE of different-record size.
6 READ after EOF reached.
7 READ attempted for dataset not opened I-O
or INPUT.
8 WRITE for dataset not opened OUTPUT,I-O
or EXTEND.
9 DELETE or REWRITE for dataset not opened I-O.
73
VSAM
9 6 VSAM-no DD statement.
7 VSAM OPEN successful.Dataset integrity verified.
I/O error handling is one vital area where VSAM dataset processing differs from non-VSAM
dataset processing. When processing non-VSAM datasets, most programmers code their
application programs to ignore errors, because the access method would abend the program if
a serious I/O error occurs. Not so when processing VSAM datasets.
VSAM places program control in the hands of the programmer, not the O/S. For this reason,
it is important to check the COBOL status key designated in the FILE STATUS clause after
every I/O operation. For some error keys you'll want to abend the program immediately; for
others you can just display the key, the record, and an informative message and continue
processing.
For these status key values, continue processing normally :
00 successful I/O.
02 duplicate alternate key encountered (expected).
10 end of file.
For these status key values, bypass the record, display pertinent information, and continue
processing :
Note: You may want to have the program count the number of times these key values are returned and
terminate the program if the counter reaches an unacceptable number, which would likely to indicate
that your input is bad
74
VSAM
75