VSAM Questions
Question:
What is VSAM?
Answer:
VSAM is Virtual Storage Access Method. It is an IBM provided access method for
accessing files.
Question:
How many types of VSAM datasets are there?
Answer:
4 types:
·
Key
Sequenced Dataset, KSDS
·
Entry
Sequenced Dataset, ESDS
·
Relative
Record Dataset, RRDS
·
Linear
Dataset, LDS
Question:
What is a Cluster?
Answer:
In VSAM terminology, a Dataset is called as a Cluster. A Cluster has two
components:
·
Index
Component
·
Data
Component
Question:
What is Control Interval, CI?
Answer:
CI is VSAM’s equivalent of a Block. It is the unit of data that is actually
transmitted when records are read or written. A CI consists of records, free
space and control field.
Question:
What is Control Area?
Answer:
It is fixed length contiguous DASD storage containing a number of CI. In short,
it is a collection of CI.
Question:
How do you specify the CA size?
Answer:
You don’t, it is computed by VSAM.
Question:
What is KSDS?
Answer:
It is an Indexed dataset. You can have one primary index and one or more
secondary index.
Question:
What is an alternate index?
Answer:
As the name suggests, it is an index in addition to the primary index in KSDS.
The records can be accessed either using primary index or secondary index.
Question:
Can an alternate index be non-unique?
Answer:
Yes it can. But the primary index must be unique.
Question:
What is a Path?
Answer:
A path is a connection between the alternate index and the records in the base
cluster. A path is used to tell the system whether a primary key or an
alternate key is retrieving a record.
Question:
What is CI split?
Answer:
In KSDS, when a new record is inserted and there in no space left for the
record in CI, then the CI splits, moving some records to one of the free CI.
This is CI split.
CI split is not a problem for KSDS
because the records are accessed using the index. CI split cannot take place in
other VSAM dataset types.
Question:
What happens if there is no free CI available to perform a CI split?
Answer:
In that case the CA split occurs and VSAM obtains a new CA from the secondary
allocation (if primary allocation has exhausted) and moves half of the CI to
the new CA.
Question:
What are spanned records?
Answer:
Records that cannot fit in one CI. In such cases, VSAM spills the remainder of
the record into the next CI. Records can span CI but not CA.
Question:
What is ESDS?
Answer:
It is a sequential dataset and does not have an index component.
Question:
Can ESDS have primary index?
Answer:
No
Question:
Can an ESDS have an alternate index?
Answer:
Yes, the index is constructed on the RBA (memory address) of the record. This
is usually used in CICS. Batch COBOL doesn’t allow alternate index on ESDS.
Question:
Can you insert/delete records in ESDS?
Answer:
No. You can only read/write.
Question:
What is RRDS?
Answer:
It’s a VSAM equivalent of an array. Each record can be accessed using an index,
referred to as relative record number (RRN).
Question:
Can a RRDS have an alternate index?
Answer:
No
Question:
Can a RRDS have spanned record?
Answer:
No
Question:
What is LDS?
Answer:
It has no records but a long string of bytes. DB2 tables store their data as
LDS.
Question:
How can you create a VSAM dataset?
Answer:
Using IDCAMS, which can manage not only VSAM datasets but non-VSAM datasets
too. It can be invoked in following ways:
·
Using
JCL
·
Using
TSO command line option
·
From
Application program
Question:
What are the basic IDCAMS commands:
Answer:
They are:
·
DEFINE:
Used to create cluster, alternate index, catalog
·
BUILDINDEX:
Used to build alternate index after it has been created.
·
IMPORT/EXPORT:
Used to import and export cluster, Alternate index, catalog to a different (but
compatible) system.
·
LISTCAT:
Used to get dataset attributes, space allocation info etc.
·
PRINT:
Used to view the dataset.
·
REPRO:
Used to load an empty VSAM cluster, merge two clusters, create backup etc.
·
VERIFY:
Used to verify data integrity and update catalog info.
Question:
How do you check return codes from IDCAMS commands?
Answer:
Using LISTCC and MAXCC condition codes. LASTCC contains the return code from
most recently executed IDCAMS command and MAXCC maintains the highest return
code encountered so far.
Question:
How do you create a variable block size VSAM dataset?
Answer:
The DEFINE CLUSTER command takes a parameter called RECORDSIZE. It specifies
the average and maximum record length. If you make average and maximum record
length same, then you create a fixed block size VSAM. If they are not the same,
then a variable block VSAM is created.
Question:
How do you define primary key while creating a KSDS?
Answer:
The DEFINE CLUSTER command takes a parameter called KEYS (L, N) where L is the
length of the key and N is the offset position in the record.
Question:
While creating a VSAM cluster, how do you make it a KSDS?
Answer:
By using proper keyword in DEFINE CLUSTER command:
·
INDEXED
for KSDS
·
NONINDEXED
for ESDS
·
NUMBERED
for RRDS
Question:
How do you get VSAM return codes from a host program during VSAM file handling?
Answer:
It is done using FILE STATUS clause for the file as:
FILE STATUS IS WS-COBOL-STATUS, WS-VSAM-STATUS
Where WS-COBOL-STATUS is defined as PIC X (2).
Where WS-VSAM-STATUS is defined as PIC 9(6)
01
WS-VSAM-STATUS
05 WS-VSAM-RC PIC
99.
05 WS-VSAM-FUNC PIC 99.
05 WS-VSAM-FEEDBACK PIC
99.
Question:
If access mode is sequential, how do you update a record?
Answer:
Use the REWRITE verb in COBOL after opening the file in I-O mode. However
before using REWRITE, the record to be modified must be read using READ.
Question:
If access mode is random/dynamic, how do you update a record?
Answer:
Move the record key value to the key and use REWRITE. There is no need to read
the record first.
Question:
What is the difference between an Unloaded dataset and an Empty dataset?
Answer:
An unloaded dataset is one, which is empty and was never loaded with any data.
An Empty dataset is one, which is now empty, but did have some records
previously. It has its Highest used relative byte address (HURBA) greater than
zero.
Question:
Can you open an empty dataset in OUTPUT mode?
Answer:
No, because it’s HURBA is greater than zero. You must open it in I-O mode or
EXTEND mode.
Question:
Can you open an unloaded dataset in OUTPUT mode?
Answer:
Yes.
Question:
Can you load a KSDS sequentially using a COBOL program?
Answer:
Yes, but the input record must be in the primary key order otherwise we will
get a file status of 21 (out of sequence) or 22 (duplicate). The sequential
load is done by using WRITE command without KEY option.
Question:
Give a brief description of how you will sequentially access a KSDS dataset
using COBOL?
Answer:
The following steps can be used:
1.
In
SELECT clause specify SEQUENTIAL ACCESS
2.
In
SELECT clause specify the COBOL file status and the VSAM file status.
3.
Open
the KSDS in INPUT mode
4.
Use
COBOL READ command to read records.
5.
Use
CLOSE command when finished.
Question:
Give a brief description of how you will randomly access a KSDS dataset using
COBOL?
Answer:
The following steps can be used:
1.
In
SELECT clause specify RANDOM ACCESS
2.
In
SELECT clause specify the COBOL file status and the VSAM file status.
3.
Open
the KSDS in I-O mode
4.
Use
MOVE command to move the record key value to the key field.
5.
Use
COBOL READ command to read the record.
6.
Use
CLOSE command when finished.
Question:
If access mode is SEQUENTIAL, how do you update/delete a KSDS record?
Answer:
We will read the file sequentially till we reach the desired record and then
move new values to that record and use REWRITE command, or use DELETE command.
Question:
If access mode is RANDOM, how do you update/delete a KSDS record?
Answer:
Move the record key value to the KEY and the new details to the record field
and use REWRITE use REWRITE command, or use DELETE command.
Question:
What is dynamic access?
Answer:
It’s a combination of random and sequential access. After finding the desired
record using random access, we can start reading sequentially from that point
on. COBOL uses START command and READ NEXT command to support dynamic access.
Question:
Give a brief description of how you will dynamically access a KSDS dataset
using COBOL?
Answer:
The following steps can be used:
1.
In
SELECT clause specify DYNAMIC ACCESS
2.
In
SELECT clause specify the COBOL file status and the VSAM file status.
3.
Open
the KSDS in INPUT or I-O mode
4.
Use
START to locate the record where you want to start reading.
5.
Use
COBOL READ NEXT command to read records sequentially.
6.
Use
CLOSE command when finished.