0% found this document useful (0 votes)
477 views110 pages

Understanding VSAM: File Organization & Access

VSAM is a data access method in IBM mainframe systems that provides file organization and access for application development. It supports sequential, indexed, relative, and linear data set organizations. VSAM files are referred to as clusters and include a data component and optional index component. Key features include dynamic space allocation, rapid access and insertion of records, and data recovery capabilities.

Uploaded by

Vivian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
477 views110 pages

Understanding VSAM: File Organization & Access

VSAM is a data access method in IBM mainframe systems that provides file organization and access for application development. It supports sequential, indexed, relative, and linear data set organizations. VSAM files are referred to as clusters and include a data component and optional index component. Key features include dynamic space allocation, rapid access and insertion of records, and data recovery capabilities.

Uploaded by

Vivian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd

VSAM

Virtual Storage Access


Method

1
VSAM
 Introduction to VSAM
 VSAM Objects
 VSAM Data Organization
 VSAM Services (AMS)
 Alternate Index Processing
 COBOL Programming using VSAM
Introduction to
VSAM
 Data Organization Methods
 Drawbacks of Native Access Methods
 Requirements of an Access Methods
 What is VSAM ?
 VSAM File Organizations
 VSAM
IBM licensed program which provides file
organization and access needs for
application development
 Supports Sequential, Indexed, Relative and
Linear data sets
 VSAM files are referred to as clusters
VSAM

 VS COBOL II supports only VSAM and


not ISAM or BDAM

 VSAM is not a DBMS or language or a


communication system
Features of
VSAM

 File information is stored in central VSAM


catalog
 Password protection for files with read,
update and full access modes
 Space allocation is dynamic
 Rapid access and insertion of records
Features of VSAM

 Free space used for automated file


reorganization
 JCL’s for VSAM files are simpler
 Portability of data between systems
 Ease of conversions between access
methods
 Data recovery is possible after failures
VSAM
Objects
 Cluster

 Logical Record

 Control Interval

 Control Area
VSAM Objects
 Index Component
– Sequence Set
– Data Set
 Generic Catalog Facility
(VSAM Catalog)
 Integrated Catalog Facility (ICF)
VSAM Clusters

 Cluster is a logical name for a VSAM


dataset
 Includes data component and in case of
KSDS the index component as well
 Data and Index are two physical datasets
viewed as a cluster
Logical Record

 Unit of Information used to


store data in a VSAM data set
Control Interval

 Records in VSAM are stored in Control


Intervals
 Unit of information that VSAM transfers
between virtual storage and disk storage
 Size of a CI is defined at the time of
creation of dataset
 Spanned records occupy more than one CI
CI (Contd.)
 CI contains four areas
– Logical Record area (LRA) - contains data
records
– CI Free Space (FSPC) - space reserved for future
insertions
– Unused Space (US) - space which is never used
(CI size may not be a multiple of record size)
– Control Fields ( CF) - control information on the
CI ( one CIDF) and data records contained within
(one or more RDF)
Control Area

 Fixed length unit of DASD storage


 CA consists of many CI’s
 VSAM’s internal unit for allocating space
within a cluster
 VSAM computes an optimum CA size which
can vary depending on the unit of allocation
CI Splits

 Occurs when there in no space for record


insertion within a CI
 Record is added at the point of split
 Subsequent records after insertion point are
written on to a fresh CI
 Each CA has a percentage of free CI’s
 Only KSDS have CI splits
CA Splits

 Occurs when there in no space for record


insertion due to an absence of free CI’s

 Split is similar to a CI split

 CA splits continue until space allocation


limits are exceeded
VSAM File
Organization

 VSAM supports three types of file


organization
– Sequential - Entry Sequenced Datasets (ESDS)
– Indexed - Key Sequenced Datasets (KSDS)
– Relative - Relative Record Datasets (RRDS)

 VSAM also support Linear Datasets (LDS)


VSAM File
Organization (Contd.)

 ESDS
– Records are stored in order which they are
entered
 KSDS
– Key uniquely identifies record
– Consists of data and index component
– Index points to relative location in file
VSAM File Organization
(Contd.)

 RRDS
– Record has a relative record number
– Number is used to access the record
 LDS
– Data is stored as a long stream of
bytes with no division into records
Entry Sequenced Data
Sets (ESDS)

 Has only a data component


 Insertion of records midway or physical
deletion is not possible
 Record can be replaced with one of a similar
lengths
 New records added at the end of the data set
Entry Sequenced Data
Sets (ESDS)

 Sequential or Direct access is possible


through RBA
 Fixed or Variable Length records
 Can have spanned records
 Ideal for applications where sequence of
data is not important and order corresponds
to sequence of events
Relative Record
Datasets (RRDS)

 Contains fixed length records


 Records have a relative record number
through which they are accessed
 Direct access is possible without the
overhead of an index
 Cannot have spanned records
Relative Record
Datasets (RRDS)

 Sequential or direct access is possible


 Records can be inserted deleted or
moved without affecting position of
other records
 VSAM first calculates address of CI and
then record position within it
 Suitable for applications that use fixed
length records
Key Sequenced
Datasets (KSDS)

 Records are stored in key sequence


 Each record has a key field that
contains unique value
 Index relates key value with
relative location of data records
Key Sequenced
Datasets (KSDS)
 Data and index are separate entries
 Records can be fixed or variable length
 Spanned records are also possible
 Permits setting up an alternate index
 Accessed sequentially or skip
sequentially
 With sequential access records are read in
consecutive order based on primary key
KSDS (Contd.)
 Index set points to sequence set which in
turn points to CI containing the records
 Sequence set is the first level of index
– Contains highest primary key value for the CI
and pointer to the CI
 Key field occupies the same position in
each record
 Key field is specified by the offset and the
length
KSDS (Contd.)
 KSDS makes full use of available space
for record insertion and deletion
 When there is insufficient room to add
more records a CI split occurs
 KSDS is ideal when random or dynamic
access is required
KSDS (Contd.)
 Sequential access is slow as records must
still be accessed through the index
 KSDS has two components : - Data and
Index
 Data component contains records and
index components stores record location
KSDS - Index Component
 Each KSDS has a data and index component
 Index component consists of index sets and
sequence sets
KSDS - Sequence
 Lowest level of Index
Sets
 Index entry consists of a sequence set
consists of :
– Primary record key of a data record contained
in the CI which it points to
– Pointer to the CI containing the record

KSDS - Sequence Sets
Pointer is the relative byte address of the CI
from the beginning of the dataset
 CI may not be in sequential order
 Sequence set is always in sequential order of
record keys
KSDS - Index Set
 Second level of Index
 Each entry on an index set consists of a
primary key
 A pointer to sequence set that contains the
primary key
 Index set can have one or more levels
 The highest level has only one record
Hurba

 Highest Used Relative Byte Address


 EOF marker for a VSAM dataset
 It is the last Relative Byte Address used
by the dataset
 Stored in the VSAM catalog
VSAM - Alternate Index
(AIX)

 Data may need to be accessed in an order


other than by key Sequence
– All employees from a department
 AIX provides an effective way to address
the above need
 AIX provides an alternate path to access
KSDS records by alternate key
VSAM - Alternate Index
(AIX)

 AIX is a KSDS which contains


– Index Component contains alternate keys
– Data Component contains primary key values
for respective records
 Relationship between alternate index and
the base cluster is called the path
VSAM - Alternate Index
(AIX)

 Base Cluster contains


– Primary Key (Emp No)
– Data Component (Emp Name)
 Alternate Index consists of :
– Alternate Key (Emp name)
– Primary key (Emp No)
Alternate Index (AIX)
Contd.

 Unique employee number therefore no


duplicate records in base cluster
 AIX built on employee name can be non
unique
 Each record in AIX Data portion has a
pointer to the base index
 Path links a record in AIX to
corresponding record in base cluster
AIX : Unique Key

 Alternate key corresponds to one


primary key
 Alternate key is Emp-AC-NO
 For accessing a emp record with emp-
AC-NO 1467 VSAM searches AIX
Retrieves primary Key 11003
Uses that value to locate record in the
base cluster
AIX with Non Unique
Key
 Alternate key corresponds to more than
one primary key
 Access is required of all employees from a
given department
 Two alternate indexes (ACCAIX and
DEPTAIX) are defined for a single base
cluster (EMP-MAST)
AIX with Non Unique
Key

 Each alternate Index is related to the


base cluster through a path
 Path is processed to access data in
order of the alternate key
AIX Access
Method
 Access is made via the alternate key
 AIX returns the corresponding primary key
 Index component of the base cluster is
searched
 Corresponding address of the data record is
retrieved
 Record is accessed with this address from
the data component
Insertion of Records
 When a new record is inserted all AIX have
to be updated (Upgrading)
 AIX can be made upgradable if so defined
during file creation
 Base cluster Upgrade set is collection of
upgradable AIX for a base cluster
 Single insert can result in several physical
I/O operations
Insertion of Records
(Contd.)

 AIX which are not automatically


upgraded have to be rebuilt
 Upgrades are entered in order which
they are made and not in prime key
sequence
 Rebuilding also resequences records in
prime key sequence
AIX -
Considerations
 AIX maintenance increases the overhead
 Use if AIX should be avoided
 Base cluster is the target for any update
operation
 Updates made through multiple AIX
paths may affect the integrity of the base
cluster
 All updates should therefore be made via
the base cluster or a single AIX path
Integrated Catalog
Facility

 ICF was developed to overcome the


disadvantages of VSAM catalogs

 Supported by MVS/XA, MVS/ESA


environments
Integrated Catalog
Facility
 Each VSAM dataset cataloged under ICF
has its own VTOC entry
 ICF also has one Master and several User
catalogs
 ICF catalog has
– One Basic Catalog Structure (BCS)
– One or more VSAM Volume Datasets
(VVDS)
ICF -
Advantages
 Multiple catalogs (upto 36 ) can share a
volume for their datasets
 Space management restrictions are fewer
resulting in better space utilization
 Information is divided between BCS (fixed)
and VVDS (variable)
 Improved performance due to the reduction
in the amount of IO’s
Access Method Services
- AMS

 Access Method Services are a set of data


management facilities provided by VSAM
 Uses a command processor called IDCAMS
 IDCAMS can be invoked :
– Interactively with TSO commands
– In batch mode using JCL statements
Basic IDCAMS
 Commands
Commands
Object Type
-DEFINE Cluster,Alternate
Index , Catalog.
– BUILDINDEX Alternate Index.
– IMPORT/EXPORT Cluster
– LISTCAT Catalog Entries
– PRINT Cluster
– REPRO Clusters
– VERIFY Cluster
IDCAMS
 Multiple IDCAMS commands can be
executed per job

 IF / THEN / ELSE construct can be


used in IDCAMS
IDCAMS
 Conditional logic is based on two
condition code registers
– LASTCC & MAXCC
– Registers are populated by IDCAMS after
every command execution
– LASTCC contains condition code of the last
executed IDCAMS command
– MAXCC contains maximum value of all
condition codes from all previous commands
executed in the current job
IDCAMS
 Multiple commands after THEN or ELSE
are embedded in a DO / END construct
 A hyphen ' - ' is used to continue
parameters of a single command on the
next line
 Plus ' + ' is used to continue sub-parameters
of a parameter on next line
IDCAMS
– EXAMPLE:
 IF MAXCC LT 4

 THEN
 /*some comment*/
 command 1
 ELSE
 /*other comment*/
 DO
 command 2
 command 3
 command 4
DEFINE
Cluster
 DEFINE Cluster Command
 Creates a VSAM cluster and names it
 For a KSDS usually DATA and
INDEX parameters are also coded
DEFINE Cluster
 EXAMPLE :
 DEFINE CLUSTER -
 (NAME(U3000.LIBR.KSDS.CLUSTER) -
 -
 DATA -
 (NAME(U3000.LIBR.KSDS.DATA) -
 -
 INDEX -
 (NAME(U3000.LIBR.KSDS.INDEX) -
 )
Define Cluster
(Cont.)
 DEFINE CLUSTER -
 NAME (‘dataset name’) -
 SPACE(primary secondary) -
 | CYLINDERS (pri. sec.)/ TRACKS (pri. sec.)
 | RECORDS (pri. sec.)/ KILOBYTES (pri. sec.)
 | MEGABYTES (pri. sec.)
 VOLUMES(vol-ser. No.) -
 RECORDSIZE(avg. Max.) -
 KEYS(length offset) -
 DATASET-TYPE
 | INDEXED / NONINDEXED/| NUMBERED
Define Cluster
(Cont.)

– Example (DEFINE KSDS) : -


 DEFINE CLUSTER
 NAME(U3000.LIBR.KSDS.CLUSTER) -
 CYL(5 1) -
 VOLUMES(VS0212) -
 RECORDSIZE(80 80) -
 KEYS(7 0) -
 INDEXED -
Loading Data - Repro
Command
 Repro command is an all purpose load
and backup utility command
 Equivalent of IEBGENER
 Can even be used in place of
IEBGENER for non-VSAM datasets
Loading Data -
Repro Command

 Can load VSAM cluster with records and


build data & index components for KSDS
 Can merge data from two VSAM datasets
 Can backup VSAM data on to a physical
Sequential and later restore/rebuild the
VSAM dataset
Repro Command -
Syntax

REPRO -
INFILE(ddname) -
OUTFILE(ddname) -
optional parameters
 Loading a KSDS is similar but ensure the
data is in sorted order (key sequence)
Repro Command -
Syntax

//KEVCOL00 JOB ...


//LOADSTEP EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//DD1 DD DSN=KEVCOL.INPUT.DATA,DISP=OLD
//DD2 DD DSN=KEVCOL.ESDS.CLUSTER,DISP=OLD
//SYSIN DD *
REPRO -
INFILE(DD1) -
OUTFILE(DD2)
/*
AMS
Performance
 Parameters are set so asParameters
to :
– Reduce the number of I/Os.
– Make the required I/Os faster.
– Optimize DASD utilization.

– CISZ FREESPACE
– BUFFERSPACE RECOVERY / SPEED
– SPANNED KEYRANGES
– REUSE IMBED REPLICATE
CISZ
Parameter
 CISZ is the minimum unit of I/O for
VSAM
 One CI of data is passed via VSAM
buffers between DASD and main memory
 CI thus corresponds to a block in OS
terminology
CISZ
Parameter

 FORMAT:
 CONTROLINTERVALSIZE (bytes) or
 CISZ (bytes)
 VSAM requires that the CISZ size
should be a multiple of 512 bytes
upto a max. of 32768 bytes
CISZ Parameter
Guidelines
 For Sequential processing of a KSDS,
large CI size is optimum
 Reduces physical I/Os by increasing
records contained per CI
 For Random processing of KSDS, small
CI size is optimum
CISZ
Parameter
Guidelines
 Makes physical I/Os faster by reducing
data transfer time
 If not specified VSAM calculates a
default CISZ
 Generally only Data component CISZ is
specified while Index component is
allowed to default
FREESPACE
Parameter
 FORMAT
 FREESPACE ( ci% ca%)
 ci% - Percentage of a Control Interval
to be left free for expansion.
 ca% - Percentage of a Control Area to
be left free for expansion.
 FREESPACE applies only to KSDS
 Allocated free space is used for adding
new records
FreeSpace -
Guidelines
 The FREESPACE parameter is coded on
the following criteria : -
– Type of processing required
– The expected rate of growth
– The frequency of dataset Reorganization.
 Larger free space increases no of I/Os
 Detrimental for sequential processing
FreeSpace -
Guidelines

 Small free space increases split-activity

 Detrimental for random processing

 FREESPACE can be used with


KEYRANGES parameter
BufferSpace Parameter

 VSAM Buffers
– A buffer is a temporary work area in
virtual storage used to transfer data
between DASD and main memory.
– Buffer holds one Control Interval of data
– Data Buffer size= CISZ of data C.I.
– Index Buffer size = CISZ of index C.I
BufferSpace
Parameter

 VSAM allocates 2 data buffers and 1


index buffer for a KSDS by default

 Default can be overridden by


BUFFERSPACE parameter in DEFINE
CLUSTER command
BufferSpace
Parameter
 Format : -
 BUFFERSPACE(bytes) or
 BUFSP(bytes)
 Example : -
 DEFINE CLUSTER
 NAME(‘U3000.LIB2.KSDS.CLUSTER) -
 BUFFERSPACE(20480) -
 CISZ(2048) -
 ..................Total Buffers allocated = 10
DEFINE CLUSTER
 DEFINE CLUSTER
-Example
-
 (NAME(U3000.LIBR.KSDS.CLUSTER) -
 CYLINDERS(5 1) -
 RECORDSIZE(80 80) -
 KEYS(4 0) -
 KEYRANGES((0001 5000) -
 (5001 9999)) -
 VOLUMES(VS0100 -
 VS0101) -
 ORDERED -
 NOREUSE -
 INDEXED -
 SPEED -
 ) -
 DATA -
 (NAME(U3000.LIBR.KSDS.DATA) -
 CISZ(4096) -
 BUFSP(40960) -
 FREESPACE(20 10) -
 ) -
 INDEX -
 (NAME(U3000.LIBR.KSDS.INDEX) -
 IMBED -
 REPLICATE -
 )
LISTCAT
Command
 LISTCAT used to view :
– Dataset attibutes
– Password and security information
– Dataset creation and expiration dates
– Dataset usage statistics
– High allocated and used RBA
– C.I. and C.A. split activity
LISTCAT
Command
 LISTCAT needs following inputs :
– Name of the object you want to list
– Name of the catalog that contains the
entry(implicit or explicit)
– Password for the concerned catalog if it is
password protected
– Information (parameters) to be displayed
LISTCAT
(Contd...)
 Following Objects can be listed using
LISTCAT
 CLUSTER or CL
 DATA
 INDEX or IX
 ALTERNATEINDEX or AIX
 PATH
 USERCATALOG or UCAT
 GENERATIONDATAGROUP or GDG
 NONVSAM or NVSAM
 SPACE or SPC
 PAGESPACE or PGSPC
LISTCAT (Contd...)
 LISTCAT format (basic parameters)
 LISTCAT
 CATALOG(name)
 | ENTRIES(entry name) options or
 | LEVEL(level)
 Object to be listed
 | NAME(type) or
 | HISTORY or
 | VOLUME or
 | ALLOCATION or
 | ALL
Alternate Index
 Creating an Alternate Index is a 3 step
process :
– Define the alternate index using
 DEFINE AIX command.

– Define an alternate index path to establish a


connection between the index and the base
cluster on which it is defined using
 DEFINE PATH command.
Alternate
Index
– Build the alternate index and populate
it for existing records using
 BLDINDEX command.
Building
Step 1: Defining the Alternate Index
//STEP01 EXEC PGM=IDCAMS
AIX
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE AIX -
(NAME(A2000.LIB.KSDS.AUTHNAME.AIX) -
VOLUMES(VS0101) -
RELATE(A2000.LIB.KSDS.CLUSTER) -
UPGRADE -
CYLINDERS( 2 1) -
KEYS(25 9) -
RECORDSIZE(70 100) -
FREESPACE(20 10) -
SHAREOPTIONS(1) -
NONUNIQUEKEY -
) -
DATA -
(NAME(A2000.LIB.KSDS.AUTHNAME.DATA)) -
INDEX -
(NAME(A2000.LIB.KSDS.AUTHNAME.INDEX))
/*
Building
AIX
(Contd.)
STEP 2 : SPECIFYING THE ALTERNATE INDEX PATH
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE PATH -
(NAME(A2000.LIB.KSDS.AUTHNAME.PATH) -
PATHENTRY(A2000.LIB.KSDS.AUTHNAME.AIX) -
UPDATE)
/*
STEP 3 : BUILDING THE INDEX
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//IDCUT1 DD DSN=A2000.BLDINDEX.WRKFLE1,DISP=OLD,
// AMP=‘AMORG’,UNIT=3380,VOL=SER=MBT001
//IDCUT2 DD DSN=A2000.BLDINDEX.WRKFLE2,DISP=OLD,
// AMP=‘AMORG’,UNIT=3380,VOL=SER=MBT001
//SYSIN DD *
BLDINDEX -
INDATASET(A2000.LIB.KSDS.CLUSTER) -
OUTDATASET(A2000.LIB.KSDS.AUTHNAME.AIX) -
INTERNAL SORT
/*
VSAM files in
COBOL
 VSAM file organization correspond to COBOL
file types :
° KSDS Indexed Files
° ESDS Sequential Files
° RRDS Relative Files
 KSDS files can be processed through primary or
alternate indexes
 VSAM error processing has to be taken care of as
well
VSAM/COBOL -
KSDS
 KSDS files can be processed :
– Sequentially i.e. accessing records in Key
Sequence
– Randomly :accessing records by specifying a
key value
– Dynamically : Accessing records both
sequentially and randomly
Sequential Processing -
KSDS
 KSDS sequential processing with Primary
Index
 Select statement contains information
about the file
 SELECT <FILENAME>
ASSIGN TO <SYSTEM-NAME>
ORGANISATION IS INDEXED
[ACCESS MODE IS SEQUENTIAL]
RECORD KEY IS <DATA-NAME1>
[FILE STATUS IS <DATA-NAME2>]
Sequential Processing -
KSDS
 Access mode clause name mode for program

 Mode can be different in other programs

 Record Key names the primary key


Sequential Processing -
KSDS (Contd.)
 File status names the COBOL status
– Should be checked after each IO
– Program should be abended in case of serious
error
 FILE SECTION - Entries
 FD file-name
LABEL RECORDS ARE STANDARD
[RECORD CONTAINS <N> CHARACTERS]
 FD describes the primary and alternate keys
used in processing
Sequential Processing -
 PROCEDURE DIVISION

KSDS (Contd.)
OPEN INPUT file-name1
OUTPUT file-name2
I-O filename3
 START FILENAME | KEY IS EQUAL TO | <data-name>
=
GREATER THAN
>
NOT LESS THAN
NOT <
[INVALID KEY imperative statement]

 READ file-name [NEXT] RECORD


[INTO identifier ]
[AT END imperative -statement]

 WRITE record-name
[FROM identifier ]
[INVALID KEY imperative -statement]

 REWRITE record-name
[FROM identifier ]
[INVALID KEY imperative -statement]

 DELETE file-name RECORD


[INVALID KEY imperative -statement]

 CLOSE file-name
Random Processing -
KSDS
 In SELECT statement ACCESS mode should
be specified as RANDOM
 FD statements are same as in Sequential
Processing
 START position is absent
READ file-name RECORD
[INTO identifier]
[INVALID KEY imperative statement]
Random Processing -
KSDS
 Omit INVALID key clause as system
executes this only for few error conditions

 FILE-STATUS code should be checked after


every IO operation
Dynamic
Processing
 Dynamic access is used to switch
between sequential and random access
 In SELECT statement ACCESS mode
should be specified as DYNAMIC
 Sequential as well as random READ
statements are used while dynamic
processing
Dynamic
Processing
 Use OPEN I-O for updating records
 Use OPEN INPUT for reading records
sequentially or randomly
 Use the START statement to place File
Position Indicator at the record where
processing should begin
VSAM Error
Handling
 VSAM places Program Control in the hands of the programmer and not
the OS
 COBOL File-Status Key checked after every IO operation
 List of Common COBOL Status key values are :
 00 Successful Completion
 07 Wrong Fixed Length Record
 10 End of File
 21 Sequence Error
 22 Duplicate Key
 23 Record not found
 24 or higher serious error conditions
 30 System Errors - Hardware Transmission
 90 VSAM Logic Error
 91 Improper Password
 92 Trying read or write a record to a file that is not opened
 93 Problem in the allocation Storage Space or File Contention
VSAM Error Handling
 00 Successful Completion
 07 Wrong Fixed Length Record
 10 End of File
 21 Sequence Error
 22 Duplicate Key
 23 Record not found
 24 or higher serious error conditions
 30 System Errors - Hardware Transmission
 90 VSAM Logic Error
 91 Improper Password
 92 Trying read or write a record to a file that is not opened
 93 Problem in the allocation Storage Space or File
Contention
VSAM Error Handling -
Considerations
 System Operators may ignore system error
messages but are likely to notice error
messages printed by the system
 Programs terminated by the stop run will
have terminated normally as far as the OS
is concerned
VSAM Error Handling -
Considerations
 If program is part of a procedure involving
various job steps
– Steps following will run even though the program
did not run as intended
 The solution is to terminate or abend a
program when the error occurs
 System Operators are trained to notice jobs
that abend
VSAM Error Handling
- Considerations
(Contd)
 Program should give a CALL to MVS
Assembly Language Sub Programs to
provide a direct means for abend
 Example :
 ABEND200 START 0
SAVE (14,12)
ABEND 200,DUMP
END
VSAM Error Handling
- Considerations
(Contd)
 ABEND200 causes an ABEND, prints a
Storage Dump and sets the user return code
to 200
 Subsequent job steps can check the return
code to determine if the job should continue
 One must define a SYSUDUMP dataset in
the JCL for the Program
KSDS with Alternate
Index
Sequential Processing
 SELECT filename
ORGANISATION IS INDEXED
[ACCESS MODE IS SEQUENTIAL]
RECORD KEY IS dataname-1
ALTERNATE RECORD KEY IS dataname-2
[WITH DUPLICATES]
[FILE STATUS IS data-name-2]
– Similar to sequential processing by a
primary key
KSDS with Alternate
Index
Sequential Processing
– WITH DUPLICATES phrase specifies whether
alternate key is unique or not unique
– Must be consistent with AMS definition
– No change in the FD statement
 Procedure Division Statements
– START statement has same format except in
KEY clause alternate KEY is specified
– Alternate Key becomes key of reference
KSDS with Alternate
Index
Random Processing
 Most I/O statements are same as for
random processing by primary key
 READ and REWRITE statements are
coded differently
 READ file-name RECORD
[INTO identifier]
KEY is data-name
[INVALID KEY imperative-statement]
KSDS with Alternate
Index
Random Processing
 If key clause is omitted program uses the
primary key as key of reference
 REWRITE : if primary key of a record in a
KSDS is to be changed
– DELETE the existing record
– WRITE a new record with new record key
 For changing the alternate key REWRITE
the record with new key
VS COBOL II for
KSDS
 Compiler has several enhancements :
– FILE STATUS IS dataname [vsam-code]
 Additional information is provided about
the status of VSAM I/O operations
 01 VSAM-CODE-FIELD COMP
05 VSAM-RETURN-CODE PIC 99.
05 VSAM-FUNCTION-CODE PIC 99.
05 VSAM-FEEDBACK-CODE PIC 99.
VS COBOL II for
KSDS

– LABEL RECORDS ARE STANDARD


clause is optional
– START statement has additional
operators =, > , <, >=
– Structured delimiters for I/O verbs e.g.
READ ..... END-READ
COBOL for ESDS
 SELECT file-name
ASSIGN to system-name
ORGANISATION IS SEQUENTIAL
[ACCESS MODE IS SEQUENTIAL]
RECORD KEY IS data-name1
[FILE STATUS IS data-name-2 [vsam-code]]
– FD statement
BLOCK CONTAINS clause is optional
COBOL for ESDS
– Procedure Division statement
OPEN EXTEND option is available
– Alternate Index is not supported for batch
COBOL programs
– Skip-Sequential processing is not allowed
– Records can only be read sequentially
– START, INVALID KEY is not supported
– No facility to delete a record
– Efficient way of processing data
COBOL for ESDS
(Contd.)
 ESDS Select clause
 SELECT LOG-TRAN ASSIGN to AS-
LOGTRAN
ORGANISATION IS SEQUENTIAL
– AS prefix for the ddname signifies
Addressed sequential
– Should be included for a ESDS
 ACCESS MODE IS SEQUENTIAL
COBOL for ESDS
(Contd.)

– ORGANISATION clause can be


omitted (default)
 PASSWORD IS LOG-UPDATEPW
– If dataset is password protected,
password should be provided for
 FILE STATUS is STAT1, STAT2
– COBOL status key should be
checked after every operation
COBOL for RRDS

 No primary key or physical index


 Alternate Index not supported either for
batch or online applications
 Access is considerably faster as an index is
not used an RBA is provided
 Sequential, Random and Dynamic access
is provided for
COBOL for RRDS
(Contd.)
 DELETE and REWRITE are fully
supported
 Relative record number can be assigned
either by VSAM or the program
 RELATIVE record number can not be
changed
 All retrievals are based on the data name
specified by the RELATIVE KEY phrase
 Virtual Storage Access Method
 VSAM

You might also like