VSAM (Virtual Storage Access Method )VSAM is an integral part of MVS. At the end of this course, you, the user, will know VSAM in detail. know the different types of VSAM data sets be able to create, delete and alter VSAM data sets, with indexes and alternate indexes know the organization of VSAM data sets
Access Methods An access method defines the technique by which data is stored and retrieved. The different types of dataset organizations in MVS are: Physical Sequential Partitioned Indexed Sequential Direct VSAM
What is VSAM? VSAM is Virtual Storage Access Method It is a method used to move data between Disk and Main Storage VSAM operates in Virtual Environment
VSAM VSAM acts as interface between Operating System and Application Program V Request S Reply OperatingApplication A System M
VSAM Interface between Main Storage and Disk V SMain Storage DATA A DATA Disk M
File access methods Data (Records) is retrieved Sequential (Reading from beginning to end) Random (Records are read by the value in the key) Direct (Records are read based on their physical location/address on disk) VSAM provides all these methods One access method supporting all types of data retrieval
Traditional access methods QSAM (Queried Sequential Access Method) BSAM (Basic Sequential Access Method) for ‘flat’ files ISAM (Index Sequential Access Method) for Index files BDAM (Basic Direct Access Method) for direct access files
VSAM Dataset TypesEntry 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.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.Linear Dataset (LDS) LDS contains data that has no record boundaries. The manipulation of the data is completely controlled by the user.Relative Record Dataset (RRDS) RRDS contains records in the order of relative record number. These records can be accessed only by this number.
VSAM data set organization VSAM Data Set can contain three major components CLUSTER (Catalog entry) INDEX DATA (Actual data) Data Set is referred by cluster name in JCL INDEX CLUSTER DATA
VSAM internals CONTROL INTERVAL (CI) VSAM stores Data and Index in Control Intervals (CI) CI is similar to ‘Block’ CI Record Record .......
CONTROL INTERVAL CI is the unit of retrieval between DASD and I/O Buffer (Virtual Storage) DASD I/O Buffer CI R1 R2 R3 R1 R2 R3
Control Interval CI contains Records (or DATA) Free space (Optional) Control Information Definition Field (CIDF) Record Definition field (RDF)
Building blocks of a VSAM Dataset 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. Control Interval (CI) A control interval consists of the following: Logical records (LR) Free space (FS) Control information fields LR LR LR LR..FS....FS...RDF CIDF Free Space is the space reserved within the CI for inserting new records in a KSDS or for lengthening the existing records.
CONTROL INTERVAL CIDF & RDF are VSAM control functions Used by VSAM to access data R R CR1 R2 Free D I R3 D Space F D F F3 bytes, Length of RecordHow many successiverecords have same length 4 bytes long, One per CI Indicates Free space, where and how much
CONTROL AREAControl Area CIs are grouped into CA 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) LR LR LR LR.. FS....FS... RDF CIDF LR LR LR LR.. FS....FS... RDF CIDF LR LR LR LR.. FS....FS... RDF CIDF
Cluster VSAM datasets are defined as Highest Index Set Clusters. 2210 5000 A Cluster is a combination of the data component and the index Index Set component. 1055 1600 FS 5000 FS FS The Index component is applicable only in the case of a KSDS. Sequence Set The data component holds data 1010 1055 FS 1350 1600 FS records. The index component holds the index records to access the required DATA COMPONENT (CA1) information from the data component 1300 1305 1310 1350 FS 1400 1410 1415 1600 FSData Component (CA2) FS FS FS FS FS 1001 1002 1005 1010 FS 1020 1022 1030 1055 FS FS FS FS FS FS
Control Interval Split CA-1 (CI-1 to CI-3) - Before split When a data set is first loaded, the key sequence of records and 1001 1002 1005 1010 FS their physical order are the same. However, when records are 1020 1022 1030 1055 FS inserted, control interval split can occur, causing the data control intervals to have a physical order FS FS FS FS that is different from the key sequence. For example, try to insert 1004 CA-1 (CI-1 to CI-3) - After split in CI-1 shown below : A Control Interval Split occurs 1001 1002 1004 FS and CI-1 is split exactly into two half CIs. CI-3, which is a free 1020 1022 1030 1055 FS control interval is used, and some logical records of CI-1 are moved into CI-3. CI-3 is placed after CI- 1005 1010 FS FS 2 and it is not inserted in between CI-1 and CI-2.
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
Types of VSAM data sets ESDS Entry Sequenced Data Set KSDS Key Sequenced Data Set RRDS Relative Record Data Set LDS Linear Data Set
ORGANIZATION SEQUENTIAL => ESDS INDEXED => KSDS RELATIVE => RRDS ACCESS MODE OPTIONSESDS : SEQUENTIALKSDS : SEQUENTIAL or RANDOM or DYNAMICRRDS: SEQUENTIAL or RANDOM or DYNAMIC
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.
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: Name of the cluster. Volume(s) on which the data set will be allocated. Type of data set (KSDS, ESDS, RRDS or LDS). Space needed for the data set. For a KSDS, the length of the key and its offset from the beginning of the record. Record size, and whether it is fixed or variable in length. Control interval size. CI and CA Free Space. The following keywords have to be used to define the different types of VSAM data sets: NONINDEXED for ESDS. INDEXED for KSDS. NUMBERED for RRDS. LINEAR for LDS.
Sample JCL to create an ESDS cluster//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID//DEFKSDS EXEC PGM=IDCAMS NONINDEXED - ESDS//SYSPRINT DD SYSOUT=*//SYSIN DD * DEFINE CLUSTER(NAME(LEM0UXX.TEST.ESDS) - VOLUMES(LEM001) - RECORDSIZE(N1,N2) NONINDEXED - TRACKS(2,1) - N1=> AVG RECL RECORDSIZE(50,50) - N2=> MAX RECL CONTROLINTERVALSIZE(4096) - FREESPACE(10,20)) - DATA(NAME(LEM0UXX.TEST.ESDS.DATA))/* Freespace(PCT1,PCT2) PCT1=> PCT FREE SPACE IN each CI PCT2=> PCT Of unused CI in CA
ESDS Similar to Sequential File Sequenced by the order in which data is entered/loaded New Records are added at the end only (chronological order) Supports both Fixed and Variable formats Contains only CLUSTER & DATA components
ESDS (Contd...) Only sequential access in Batch Cobol Programs Random access is supported in on-line applications (CICS) using Relative Byte Address (RBA) Alternate Index is supported in on-line applications (CICS) NO primary index
RBA Record location relative to the beginning of the file (Relative Byte Address) CI R1 R2 R3 80 40 60 RBA of R1 is 80
FILE-CONTROL ParagraphFormat:SELECT [OPTIONAL] File-name-1 ASSIGN TO AS-Assignment-name-1 SEQUENTIAL[ ORGANIZATION IS INDEXED RELATIVE SEQUENTIAL[ACCESS MODE IS RANDOM DYNAMIC[FILE STATUS IS Data-name-1]
Sample JCL to create a KSDS cluster KEYS(N1,N2)//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID N1=> length of the Key(Bytes)//DEFKSDS EXEC PGM=IDCAMS N2=> is starting byte position//SYSPRINT DD SYSOUT=* of Key in Record//SYSIN DD * DEFINE CLUSTER(NAME(LEM0UXX.TEST.KSDS) - RECORDSIZE(N1,N2) VOLUMES(LEM001) - N1=> AVG RECL TRACKS(2,1) - N2=> MAX RECL INDEXED - KEYS(9,0) - INDEXED - KSDS RECORDSIZE(50,50) - CONTROLINTERVALSIZE(4096) - Freespace(PCT1,PCT2) FREESPACE(10,20)) - PCT1=> PCT FREE SPACE IN each CI DATA(NAME(LEM0UXX.TEST.KSDS.DATA)) - PCT2=> PCT Of unused CI in CA INDEX((NAME(LEM0UXX.TEST.KSDS.INDEX))
SELECT & ASSIGN SyntaxENVIRONMENT DIVISION.INP UT- OUT P UTSECT ION.FILE - CONT ROL. SELECT [OP T IONAL FileName ] ASSIGN T O FileSpec ORGANIZAT I IS INDEXED ON SEQUENT IAL ACCESS MODE IS RANDOM DYNAMIC RECORD KEY IS UniqueRecKey ALT ERNAT ERECORD KEY IS AltKey WIT HDUP LICAT ES FILE ST AT US IS FileStatus
READ statementREAD FileName RECORD INTO DestItem KEY IS KeyName INVALID KEY StatementBlockEND READREAD FileName NEXT RECORD INTO DestItem AT END StatementBlockEND READ
WRITE & REWRITE statementWRITE RecName FROM SourceItem INVALID KEY StatementBlockEND WRITEREWRITE RecName FROM SourceItem INVALID KEY StatementBlockEND REWRITE
START & DELETE statement IS EQUAL TO IS = IS GREATER THANSTART FileName KEY KeyName IS > IS NOT LESS THAN IS NOT < INVALID KEY StatementBlockEND STARTDELETE FileName RECORD INVALID KEY StatementBlockEND DELETE
ALTERNATE INDEXES Used whenever the data is required to be retrieved on the basis of m than one fieldEMPNO ENAME SALARY101 RAJESH 5000102 RAMESH 6000103 RANDY 7000104 SURESH 8000 e.g., Can be defined for both KSDS & ESDSEMPNO IS ENAME ISBASE KEY ALTERNATE KEY
ALTERNATE INDEXESReduce data redundancyCan have duplicatesEasy to define using IDCAMSAllow datasets to be accessed sequentially orrandomlyCan be updated automatically
Steps for Creating Alternate Index Define AIX using IDCAMS DEFINE AIX Specify Alternate Index Path using IDCAMS DEFINE PATH Build AIX & populate it using IDCAMS BLDINDEX
Sample JCL to create an AIX cluster UPGRADE-> VSAM AUTOMATIC Updates the AIX for all ADD,UPDT,DEL of Base cluster//LEM0UXXA JOB MSGCLASS=Q,CLASS=Q,NOTIFY=&SYSUID//DEFKSDS EXEC PGM=IDCAMS UNIQUE /NONUNIQUE//SYSPRINT DD SYSOUT=*//SYSIN DD * DEFINE AIX (NAME(LEM0UXX.TEST.AIX.CLUSTER) – KEY ( N1,N2) RELATE (LEM0UXX.INFILE.KSDS) - N1-> LENGTH OF AIX key VOLUMES(LEM001) - KEY (10, 35) - N2-> KEYS start Loc in BASE CLUSTERTRACKS(2,1) -NONUNIQUEKEY - RECORDSIZE(N1,N2)RECORDSIZE(49,49) - N1=> AVG RECLUPGRADECONTROLINTERVALSIZE(4096) - N2=> MAX RECLFREESPACE(10,20)) -DATA(NAME(LEM0UXX.TEST.AIX.DATA))INDEX(NAME(LEM0UXX.TEST.AIX.INDEX)) Freespace(PCT1,PCT2)/* PCT1=> PCT FREE SPACE IN each CI PCT2=> PCT Of unused CI in CA
UPGRADE/NOUPGRADE• Syntax : UPGRADE/NOUPGRADE• UPGRADE specifies that records in AIX are to be updated• automatically whenever the base cluster is updated
BUILD INDEX//JOB CARD//STEP1 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT=* BUILD INDEX is used//SYSIN DD * To load records in BLDINDEX - INDATASET(LEM0UXX.KSDS.CLUSTER) - AIX after it has been def OUTDATASET(LEM0UXX.KSDS.AIX.CLUSTER) -/*