Ver2 Vsam Mat

download Ver2 Vsam Mat

of 64

Transcript of Ver2 Vsam Mat

  • 7/28/2019 Ver2 Vsam Mat

    1/64

    VSAM

    Version - 2.020th June 2000

    1

  • 7/28/2019 Ver2 Vsam Mat

    2/64

    VSAM

    Day-wise Schedule...................................................................................................4

    1. INTRODUCTION TO VSAM............................................................................................5

    Features of VSAM...................................................................................................5

    Advantages of VSAM..............................................................................................5

    Types of VSAM Datasets.........................................................................................5

    VSAM history..........................................................................................................6

    2. VSAM Catalogs....................................................................................................................7

    Vsam catalog............................................................................................................8

    3. Inside VSAM Datasets.......................................................................................................10

    Control Interval......................................................................................................10

    Spanned Records....................................................................................................11

    ................................................................................................................................11

    ESDS......................................................................................................................12

    ................................................................................................................................12

    KSDS......................................................................................................................12

    KSDS Structure......................................................................................................14

    ..........................................................................................................................18

    4. IDCAMS COMMANDS...................................................................................................20

    Format of IDCAMS command...............................................................................21

    IDCAMS return codes............................................................................................22

    ................................................................................................................................22

    ................................................................................................................................23

    Defining an ESDS Cluster......................................................................................23

    5. LISTCAT...........................................................................................................................30

    2

  • 7/28/2019 Ver2 Vsam Mat

    3/64

    VSAM

    6. Creating Alternate Indexes................................................................................................33

    Building Alternate Indexes.....................................................................................36

    7. Reorganizing VSAM datasets..........................................................................................38

    With REPRO you can do the following.................................................................38

    Redefine the cluster using IDCAMS DEFINE CLUSTER command...................40

    14. VERIFY , PRINT, DELETE, ALTER Command........................................................44

    VERIFY.................................................................................................................44

    DELETE.................................................................................................................44

    PRINT....................................................................................................................45

    ALTER...................................................................................................................46

    15. Generation DataSets.......................................................................................................50

    Physical deletion of entry.......................................................................................53

    16. COBOL VSAM Considerations......................................................................................55

    17. Appendix-A .................................................................................................................59

    VSAM ASSIGNMENT .........................................................................................59

    18. Appendix -B......................................................................................................................61

    References..............................................................................................................61

    19. Appendix-C ......................................................................................................................62

    Table of Figures ...................................................................................................62

    14. Appendix-D.......................................................................................................................62

    Table of JCL listing................................................................................................63

    .............................................................................................................64

    3

  • 7/28/2019 Ver2 Vsam Mat

    4/64

    VSAM

    Day-wise Schedule

    Day-1

    What is catalog?Types of VSAM datasetsIDCAMS commandCOBOL Considerations for ESDSListcat overview

    Day-2

    Introduction to Alternate indexDefine AixDefine path

    BLDIndexCOBOL Considerations for AIX

    Day-3

    IDCAM commandsREPRO, EXPORT/IMPORTVERIFY, ALTER, DELETEAdditional options onIDCAMS commandKEYRANGES, IMBED,REPLICATE

    Day-4

    READPW, MASTERPW, UPDATEPW optionsCreating and using Generation Dataset GroupsDeleting and altering GDGs

    4

  • 7/28/2019 Ver2 Vsam Mat

    5/64

    VSAM

    1. INTRODUCTION TO VSAM

    VSAM stands for Virtual Storage Access Method, is IBM high performance access methodwhich allows you to access files of different organization such as sequential, indexed, relativerecord and linear datasets.

    Features of VSAM

    VSAM is one coherent file storage system used to store and retrieve data. It is not a databasemanagement 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 throughprogramming languages like COBOL or PL/I. It is not a communication system like VTAMor CICS. It has no equivalent for a PDS type of file organization.

    Advantages of VSAM

    Provides protection of Data against unauthorized access through password facility.

    Cross-system (MVS & VSE) Cmpatibility. VSAM datasets can be imported and imported inMVS and VSE systems.

    Device Independence (Access Via Catalog). The application programmer need not beconcerned with Block size ,volume and other control information, as access to VSAMdataset it always through the Catalog and all control information are stored in the catalogentry of the dataset.

    IDCAMS commands can be included in JCL to handle VSAM datasets

    Types of VSAM Datasets

    Clusters

    VSAM files are often called clusters. A cluster is the set of catalog entries that represent afile. A cluster consists of one or two components. All VSAM datasets consist of a datacomponent in which data records are placed . For KSDS , there is an additional indexcomponent, which contains the indexes used to access records in the data component. ESDSRRDS and LDS have data component only and no index component

    VSAM clusters are categorized into 4 types based on the way we store and access the records:

    5

  • 7/28/2019 Ver2 Vsam Mat

    6/64

    VSAM

    ESDS Entry Sequenced dataset.

    These are sequential datasets that can be read in the sequence in which they were created.Records can be added only to the end of the dataset.

    KSDS Key Sequenced dataset.

    These datasets are stored in sequence of some key field in the record. The data componentand index component are separated. The keys are stored in a separate index and records areaccessed through the index. Individual records can be accessed randomly on the basis of therecord key. Locating the record is a two stage process.

    First search for the key in the index

    Use the information in the index to locate the record.

    RRDS Relative record dataset.

    These datasets associate a number to each record. There is no key field but records areaccessed by deriving the relative position of the record in the dataset.

    LDS Linear dataset. These datasets consist of a stream of bytes which are accessedand written as 4k blocks accessed by Relative Byte Address

    VSAM history

    VSAM was introducted in 1973. This version had only Entry Sequence Datasets and KeySequenced Datasets. In 1975 Relative Record Datasets and alternate indexes for KSDS wasadded. 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)

    DFP/VSAM version 3 was introduced to run under MVS/ESA architecture.In 1991 version 3.3 supported variable-length records for RRDS.

    6

  • 7/28/2019 Ver2 Vsam Mat

    7/64

    VSAM

    2. VSAM Catalogs

    VSAM is totally catalog-driven. Catalogs are special purpose files residing on DASD (Direct

    Access Storage Device) serving as a central repository for information about all datasetsunder its control.

    There are two types of catalogs used

    Master catalog

    User catalog

    Theres only one Master catalog per system. The entries in the master catalog may point toVSAM 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 becataloged into master catalog.

    Access to a dataset can only be made through a master or user catalog. Therefore all VSAMdatasets have to be cataloged. Non-VSAM datasets can also be cataloged. Catalogs are

    protected by RACF.

    Figure 2.1 VSAM Catalog

    7

    MASTER CATALOG

    USERCATALOG

    USERCATALOGUSERCATALOG

    USERCATALOG

    USERCATALOG

  • 7/28/2019 Ver2 Vsam Mat

    8/64

    VSAM

    Vsam catalog

    Catalogs maintain the following information

    Name and physical location of datasets

    password information required to access protected datasets

    Statistics about datasets Example No. of records added, read, deleted or no. of Control

    Interval/Control Area splits

    Information about dataset itself Example ESDS, KSDS, RRDS, CSIZE,

    KEYLENGTH

    Location of catalog recovery area

    Vsam records

    VSAM records can be fixed or variable length. Records can also be spanned

    Vsam space allocation

    VSAM space allocation depends on whether the dataset is cataloged in an ICF or the olderVSAM 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 CLUSTERcommand

    Each VSAM dataset cataloged in an ICF catalog has its own VTOC entry. These VSAMdatasets can have 1 primary and 122 secondary allocation unlike OS dataset which can haveonly 1 primary and 15 secondary extends on a volume.

    Vsam space management

    VSAM maintains detailed information in its catalogs about DASD space allocated to VSAMfiles. This allocation information stored in the catalog is more comprehensive and flexible

    than the equivalent information stored for a non-VSAM file in VTOC.

    Sub Allocation

    Once the space has been allocated, VSAM has complete control over subsequent allocationswithin that space. Within that space, VSAM can create suballocated files. Whenever asuballocated files need to be created, extended or deleted, VSAM uses it own spacemanagement facilities.

    8

  • 7/28/2019 Ver2 Vsam Mat

    9/64

    VSAM

    Unique Allocation

    Alternatively an entire VSAM space can be allocated to single VSAM file. In that caseallocation for the file called UNIQUE file, is managed by DADSM rather than by VSAM.Allocation information for the unique files is maintained in two places : the VSAM catalogentry for the file and the VTOC entry for the space that contains unique file.

    The figure below shows two DASD volumes. The first volume has a VSAM dataspacecontains two sub-allocated files. Notice that theres unused space within the dataspace too.However, that space is not available to non-VSAM files because its already under VSAMscontrol. The second DASD volume contains two unique VSAM datasets. All of the unusedspace on the volume is available to both VSAM and Non-VSAM datasets. UnderVSE/VSAM & OS/VS VSAM most VSAM datasets are sub-allocated. Under ICF, there is noVSAM space. All VSAM files are Unique

    Figure 2.2 Space Allocation

    9

    Non-VSAM

    File I

    Available Space

    File II

    Available Space

    Non-VSAM

    Non-VSAM

    File III

    Non-VSAM

    File IV

    Non-VSAM

    VSAM

    dat

    asets

    underVSAM

    s

    control

    uniqueVSA

    M

    file

    VOLUME 1 VOLUME II

  • 7/28/2019 Ver2 Vsam Mat

    10/64

    VSAM

    3. Inside VSAM Datasets

    Control Interval

    A control interval is the unit of data VSAM transfers between virtual and disk storage. It issimilar to the concept of blocking in non-VSAM files. Each control interval can containmore than one logical record.

    The size of CI must be between 512 bytes to 32K. Upto 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.

    For index component, the size of CI is 512, 1K, 2K or 4K bytes.

    A Control Inverval consists of records, free space and control field information as shownbelow

    Figure 3.1 Contents of Control Interval

    In th Control Interval shown above Rec1, Rec2, Rec3 are records. Free Space is where newrecords can be inserted.

    Figure 3.2 Contents of Control Field

    10

    Rec1 Rec2 Rec3 Free Space Unused Space Control Field

    CF

    RDF CIDF

  • 7/28/2019 Ver2 Vsam Mat

    11/64

    VSAM

    Control Interval Descriptor Field(CIDF) contains information about available space withinCI. Record Descriptor Field (RDF) contains the length of each record and how many adjacentrecords are of the same length. Theres one RDF for each record in variable length records.

    There will be only two RDFs per CI in case of fixed length files. One RDF specifies thelength of the record and the second RDF specifies how many records are there in the CI. EachRDF is of 3 bytes .

    VSAM groups control intervals into contiguous, fixed length areas of storage called ControlAreas. Maximum size of a CA is 1 cylinder. You can also specify freespace in CA. The totalnumber of CI/CA in a Cluster is determined by VSAM.

    CONTROL AREA

    Figure 3.3 Control Area

    Spanned Records

    Spanned records are records larger than the specified CI size. That is they span more than oneCI. 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 RDFgives the length of the segment and the left gives the update number of the segment. Spannedrecords can exist only in ESDS and KSDS.

    A CI that contains a record segment of a spanned record contains no other data. Records canspan Control Intervals but not Control Areas. For KSDS the entire key field of the spannedrecord must be in the first Control Interval.

    11

    CONTROL INTERVAL

    CONTROL INTERVAL

    CONTROL INTERVAL

    CONTROL INTERVAL

    CONTROL INTERVAL

  • 7/28/2019 Ver2 Vsam Mat

    12/64

    VSAM

    Figure 3.4 Spanned Record

    ESDS

    ESDS is a sequential dataset. Records are retrieved in the order in which they are written tothe dataset. Additions are made always at the end of the file. Records can be retrievedrandomly 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 collatingsequence by the key field.

    Rules for key

    Key must be unique in a record

    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

    A KSDS consists of two components index component and data componentDATA Component :- Contains control areas which in turn contains Control Intervals asshown in

    12

    Logical Record 1

    Record1 RCSegment2

    Record1 RC

    Segment1

    Record1 RCSegment3

  • 7/28/2019 Ver2 Vsam Mat

    13/64

    VSAM

    Figure 3.5

    13

  • 7/28/2019 Ver2 Vsam Mat

    14/64

    VSAM

    Figure 3.5 Contents of Control Area

    KSDS Structure

    Figure 3.6 Contents of KSDS Index

    The first level of index is called a Sequence set. The Sequence setconsists of Primary keysand 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 anyorder. VSAM uses the Sequence Set to access records in the KSDS sequentially.

    The index component is a separate entity with a different CIsize , a different name and canbe stored on a different volume.

    Control interval splits can occur in Indexes also

    Sequence Set

    14

    Data Component Control Intervals

    Control Areas

    Index Set

    Sequence Set

  • 7/28/2019 Ver2 Vsam Mat

    15/64

    VSAM

    CI CI CI CI

    Figure 3.7 Contents of Sequence Set

    Index Set

    Indexcomponent

    Sequence Set Sequence Set

    CA1 CA2

    Figure 3.7 Contents of Index Set

    15

    CI CI CI CI CI CI CI CI

    Key Ptr Key Ptr Key Ptr Key Ptr

  • 7/28/2019 Ver2 Vsam Mat

    16/64

    VSAM

    Figure 3.8 Inserting a new record into a KSDS

    16

    NewRecord

    After Inserting

    Record1 Record2 Record3 FSPC US CF

    Record1 Record2 New Record Record 3 FSPC US CF

  • 7/28/2019 Ver2 Vsam Mat

    17/64

    VSAM

    Before Control Interval Split

    FullControl Interval

    Figure 3.9 Inserting a new record into a full CI

    Figure 3.10 After Control Interval Split

    17

    EmptyControlInterval

    Record3 Record4 Record5 FSPC US CF

    Record1 Record2 New Record FSPC US CF

    New

    Record

    Rec1 Rec2 Rec3 Rec4 Rec5 US CF

    FSPC US CF

  • 7/28/2019 Ver2 Vsam Mat

    18/64

    VSAM

    Sequence Set

    0

    100

    200

    Figure 3.11a Effect of Control Interval Split on Sequence Set

    18

    RecordJ RecordK FSPC US CF

    RecordA RecordB RecordF RecordG FSPC US CF

    I 0 K 100

    NewRecord

    FSPC US CF

  • 7/28/2019 Ver2 Vsam Mat

    19/64

    VSAM

    0

    100

    200

    Figure 3.11b Effect of Control Interval split on Sequence Set

    19

    RecordJ RecordK FSPC US CF

    RecordA RecordB RecordC FSPC US CF

    E 0 I 200 K 100

    RecordF RecordG FSPC US CF

  • 7/28/2019 Ver2 Vsam Mat

    20/64

    VSAM

    4. IDCAMS COMMANDS

    You can write IDCAMS utility program

    1. To create VSAM dataset

    2. To list, examine, print, tune, backup, and export/import VSAM datasets.

    The IDCAMS utility can be invoked in batch mode with JCL or interactively with TSO commands. With JCL you can

    print/display datasets and system messages and return codes. Multiple commands can becoded per job. You can use IF-THEN-ELSE statement to execute command/s selectively

    based on condition codes returned by previous commands.Listed below are the IDCAMS commands to be discussed in this course

    DEFINE

    MODAL COMMANDS

    IF

    SET

    PARM

    BUILDINDEX

    REPRO

    PRINT

    DELETE

    VERIFY

    IMPORT/EXPORT

    ALTER

    LISTCAT

    The example 4.1 shown below is a skeleton JCL for executing IDCAMS commands. ThePGM parameter specifies that the program to be executed is IDCAMS utility program . Thestatements that follow SYSIN DD * are IDCAMS commands. The end of data is specified

    by /*.

    20

  • 7/28/2019 Ver2 Vsam Mat

    21/64

    VSAM

    Optionally JOBCAT and STEPCAT statements may be coded to indicate catalog names for ajob/step, in which concerned dataset may be cataloged

    // jobname JOB (parameters)// stepname EXEC PGM=IDCAMS// SYSPRINT DD SYSOUT = *[// ddname DD DSN=datasetname,

    DISP= SHR/ OLD]//SYSIN DD *

    IDCAMS command/s coded freely between 2 to 72 cols./*//Optionally:// JOBCAT DD DSN = catalogname, DISP= SHR// STEPCAT DD DSN = catalogname, DISP = SHR

    Example 4.1 JCL for executing IDCAMS commands

    Format of IDCAMS command

    verb object (parameters)

    Every IDCAMS command starts with a verb followed by object which takes someparameters. In the code listing 4.2 DEFINE is the verb CLUSTER is the object which takes adataset DA0001T.LIB.KSDS.CLUSTER as parameter

    DEFINE CLUSTER -NAME(DA0001T.LIB.KSDS.CLUSTER) -

    CYLINDERS(5, 1) -VOLUMES (BS3013) -INDEXED -

    )

    Example 4.2 Creating a cluster

    Comments:

    Comments in IDCAMS can be specified in the following manner

    /* comment */

    or/* -----

    21

  • 7/28/2019 Ver2 Vsam Mat

    22/64

    VSAM

    */

    IDCAMS return codes

    The IDCAMS Commands return certain codes which have the following interpretation

    Condition code:

    0 : command executed with no errors4 : warning - execution may go successful8 : serious error - execution may fail12 : serious error - execution impossible

    16 : fatal error - job step terminates

    The condition codes are stored in LASTCC/MAXCC. LASTCC stores the conditioncode for the previous command and MAXCC stores the maximum code returned byall previous commands. Both LASTCC and MAXCC contain zero by default at thestart of IDCAMS execution. You can check the condition code of the previouscommand and direct the flow of execution or terminate the JCL.

    Syntax of IF statement

    IF LASTCC/MAXCC

    comparand VALUE-THEN -command

    ELSECommand

    Comparand(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 : LASTCCandMAXCCcan also be set toany 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

    22

  • 7/28/2019 Ver2 Vsam Mat

    23/64

    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 */CommandCommand

    ENDELSE

    Command

    Example 4.3a JCL using MAXCC and LASTCC

    DEFINE CLUSTER.

    IF LASTCC > 0 THENSET MAXCC = 16ELSE

    REPRO

    Example 4.3b JCL using MAXCC and LASTCC

    Defining an ESDS Cluster

    DEFINE CLUSTER

    Clusters are created and named with the DEFINE CLUSTER command.

    The NAME parameter

    This is a required positional parameter.

    Format : NAME(Cluster-Name)

    23

  • 7/28/2019 Ver2 Vsam Mat

    24/64

    VSAM

    Cluster name :- The name to be assigned to the cluster

    Example: NAME(DA0004T.LIB.KSDS.CLUSTER)The cluster Name becomes the dataset name in any JCL that invokes this cluster either as an

    input or output

    //INPUT DD DSN=DA0004T.LIB.KSDS.CLUSTER,DISP=SHR

    The high-level qualifier is important because in most installations this technique ensures thatVSAM datasets are cataloged in the appropriate user catalog.

    Rules for Naming Cluster

    Can have 1 to 44 alphanumeric characters

    Can include the national characters #, @, $

    Segmented into level of eight or fewer characters, separated by periods

    The first character must be either alphabetic or national character

    The SPACE Allocation parameter

    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 whenthe dataset is created

    Secondary : Number of units of secondary space to allocate. This amount is allocated amaximum of 122 times as needed during the life of the dataset. VSAM calculates the controlarea size for you. A control area size of one cylinder usually yields best performance. Toensure control area size of one cylinder you must allocate space in CYLINDERS.

    Allocating space ine RECORDS must be avoided as this might result in an inefficient ControlArea size.

    The VOLUMES parameter

    This VOLUMES parameter assigns one or more storage volumes to your dataset.Multiple volumes must be of the same device type.

    24

  • 7/28/2019 Ver2 Vsam Mat

    25/64

    VSAM

    Format :

    VOLUMES(volser) or VOLUMES(volser ........ volser)

    volser : The 6 digit volume serial number of a volume.

    Example :

    VOLUMES(BS3011)VOLUMES(BS3011 BS3040 BS3042)

    You can store the data and index (in case of KSDS clusters) on separate volumes asthis may provide a performance advantage for large dataset

    The Recordsize parameter

    This parameter tells VSAM what size records to expect. The avg and max are average

    and maximum values for variable length record. If records are of fixed length, avgand maxshould be the same.

    Format :

    RECORDSIZE(avg max)

    avg : Average length of recordsmax : Maximum length of recordse.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 is an optional parameter, if omitted default is RECORDSIZE(4086 4086)

    The SPANNED parameter

    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 isunusable by other records, even if they fit logically in the unused bytes. [NONSPANNED isthe default] & it means that records cannot span control intervals

    The DATASET-TYPE parameter

    This parameter specifies whether the dataset is INDEXED(KSDS),NONINDEXED(ESDS), or NUMBERED(RRDS).

    Format : INDEXED| NONINDEXED | NUMBERED

    INDEXED :- Specifies a KSDS and is the default

    25

  • 7/28/2019 Ver2 Vsam Mat

    26/64

    VSAM

    NONINDEXED :- Specifies an ESDS. No index is created and records are accessedsequentially or by relative byte address

    NUMBERED :- Specifies an RRDSLINEAR :- Specifies a LINEAR dataset

    The default dataset Type is INDEXED.

    //DA0001TA JOB LA2719, PCS,MSGLEVEL=(1,1),// MGCLASS=A,NOTIFY=DA0001T// * Delete/Define Cluster for ESDS VSAM Dataset//STEP1 EXEC PGM=IDCAMS// SYSPRINT DD SYSOUT = *// SYSIN DD *

    DELETE DA0001T.LIB.ESDS.CLUSTER

    DEFINE CLUSTER -(NAME(DA0001T.LIB.ESDS.CLUSTER) -NONINDEXED -RECORDSIZE(125 125) -RECORDS(100 10) -NONSPANNED -VOLUMES (BS3013) -REUSE - ) -DATA(NAME(DA0001T.LIB.ESDS.DATA))

    Example 4.4 JCL for Defining an ESDS Cluster

    Defining KSDS Cluster

    While defining a KSDS Cluster it is essential to code the DATA, INDEX and KEYSparameter

    The DATA parameter

    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)

    dataname :- The name you choose to name the data component

    The INDEX parameter

    The INDEX parameter creates a separate index component

    Format :

    INDEX(NAME(indexname) Parameters)

    26

  • 7/28/2019 Ver2 Vsam Mat

    27/64

    VSAM

    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 forthem. If you omit the NAME parameter for DATA and INDEX , VSAM appends .DATAor .INDEX as the low-level qualifier.

    The KEYS parameter

    This parameter defines the length and offset of the primary key in a KSDS record.The offset is the primary keys displacement (in bytes) from the beginning of the record.

    Format :

    KEYS(length offset)

    length : length in bytes of the primary keyoffset : Offset in bytes of the primary key with records (0 to n)

    Example :

    KEYS(8 0)

    VSAM records begin in position zero

    Note :

    Default is KEYS(64 1) [Key is in bytes 2 thru 65]

    //DA0001TA JOB LA2719, PCS,MSGLEVEL=(1,1),// MGCLASS=A,NOTIFY=DA0001T// *Delete/Define Cluster for KSDS VSAM Dataset//*//STEP1 EXEC PGM=IDCAMS// SYSPRINT DD SYSOUT=*// SYSIN DD *

    DELETEDA0001T.LIB.KSDS.CLUSTERDEFINE CLUSTER(

    NAME(DA0001T.LIB.KSDS.CLUSTER) -INDEXED -KEYS(4 0) -FSPC(10 20) -RECORDSIZE(125 125) -RECORDS(100 10) -NONSPANNED -VOLUMES (BS3013) -NOREUSE - )-

    DATA(NAME(DA0001T.LIB.KSDS.DATA)) INDEX(NAME(DA0001T.LIB.KSDS.INDEX))/*//

    Example 4.5 JCL for Defining a KSDS Cluster

    27

  • 7/28/2019 Ver2 Vsam Mat

    28/64

    VSAM

    The FREESPACE parameter

    This FREESPACE parameter, which applies to the KSDS, allocates some percentage ofcontrol 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 tothe data component

    Format :FREESPACE(%CI %CA)

    %CI :- Percentage of control interval to leave free for expansion%CA :- Percentage of control area to leave free for expansion

    Example : FREESPACE(20 10)

    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 isFREESPACE(0 0)

    The REUSE parameter

    The REUSE parameter specifies that the cluster can be opened a second time as areusable 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 anddeleted each time the application runs. To simplify these applications, VSAM lets you createreusable files. The reusable file is a standard VSAM KSDS, ESDS or RRDS. The onlydifference is that, if you open an existing reusable file for output processing, VSAM treats thefile as if were empty. Any records already present in the file are ignored.

    The CONTROL INTERVAL SIZE parameter

    This parameter specifies the Control Interval size. It is usually abbreviated CISZ.

    Format :

    CISZ(bytes)

    Example :

    CISZ(4096)

    Note :If omitted VSAM calculates CISZ based on record size.

    28

  • 7/28/2019 Ver2 Vsam Mat

    29/64

    VSAM

    Remark : Control Interval is VSAMs equivalent of a block and it is the unit of data that isactually transmitted when records are read or written.

    Guidelines for determining the CISZ

    ESDS is processed sequentially, so the CISZ should be relatively large, depending on the sizeof 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 CISZfor random processing and then allocate extra buffers for sequential processing with the AMPJCL parameter.

    RRDS is usually processed randomly, so the CISZ should be relatively small, depending onthe size of the record.

    SHAREOPTIONSThis parameter tells VSAM whether you want to let two or more jobs to process your file atthe same time. It specifies how a VSAM dataset can be shared

    Format :

    SHARE OPTIONS(cr value cs value)

    cr value : Specifies the value for cross region sharing. Cross region sharing is defined asdifferent jobs running on the same system using Global Resource Serialization(GRS), aresource control facility available only under MVS/XA and ESAcs value : Specifies the value for cross system sharing means different jobs running ondifferent 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)

    29

  • 7/28/2019 Ver2 Vsam Mat

    30/64

    VSAM

    5. LISTCAT

    LISTCATs basic function is to list information about VSAM and NONVSAM objects. WithLISTCAT you can also view password and security information, usage statistics, spaceallocation information, creation and expiration dates etc.

    Format 1:

    LISTCAT ENTRIES(entryname) options

    Options are : HISTORY

    VOLUME

    ALLOCATION ALL

    ENTRIES (ENT) requires you to specify each level of qualification, either explicitly orimplicitly, using an asterisk as a wild card character.

    Examples:

    LISTCATENT(DA0001T.VSAM.KSDS.CLUSTER) -

    CLUSTER -ALL -

    Example 5.1 LISTCAT

    The above command will only display the base cluster

    LISTCATENT(DA0001T.VSAM.KSDS.CLUSTER) -

    DATA -ALL -

    The above command will only display the data component

    30

  • 7/28/2019 Ver2 Vsam Mat

    31/64

    VSAM

    LISTCATENT(DA0001T.VSAM.KSDS.CLUSTER) -

    ALL

    The above command will display all catalog information.

    //STEP1 EXEC PGM=IDCAMS//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-levelqualifier and list every entry with that high level qualifier .

    Example

    LISTCAT LVL(DA0001T.*.KSDS) ALL

    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 listDA0001T.ABC.KSDS and DA0001T.TEST.KSDS.AIX, DA0001T.TEST.KSDS.DATA .

    To execute LISTCAT from TSO prompt

    LISTCAT ENTRIES (LIB.KSDS.CLUSTER) ALL

    If you analyze the output of the LISTCAT command there is ALLOCATION informationwhich shows two fields HURBA and HARBA.

    High-Used-RBA (HURBA)points to the end of the data. High-Allocated-RBA (HARBA)isthe highest byte that can be used.

    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.

    31

  • 7/28/2019 Ver2 Vsam Mat

    32/64

    VSAM

    HIGH-USED-RBA indicates the Relative Byte Address(plus 1) of the last used data controlarea. This value reflects the portion of the space allocation that is actually filled with datarecords.

    There are actually to HURBAs one in the VSAM control block of the cluster and one in thecatalog entry for the cluster.You can write application programs (in COBOL, PL/I Assembler Language, in CICS) anduse the statements provided by these languages to write and read VSAM datasets

    Figure 5.1 HURBA and HARBA

    32

    HARBA

    HURBA

    VSAM cluster

    Data space

    allocated butempty

    Data spaceloaded withrecords

  • 7/28/2019 Ver2 Vsam Mat

    33/64

    VSAM

    6. Creating Alternate Indexes

    An Alternate Index AIX provides a view of data different from the one offered by theprimary key. For example for a KSDS dataset Employee, you may have a Record Key indexon Employee-no and an Alternate Index on Employee-Name . You can now browse and evenupdate the same KSDS in logical sequence by Employee-Name.

    Alternate Indexes may be defined on one or more than one Alternate Key(s) i.e. Field(s) otherthan primary key. Alternate Key(s) need not be unique. Each alternate index itself is a KSDSwith data and index component.

    Alternate Index greatly reduces redundancy. There is no need to keep a separate dataset fordifferent views like Employees Social Security No. The records may be accessed

    sequentially or randomly based on the alternate record keys.

    They can be updated automatically when the base cluster is updated.

    Alternate Indexes do not support a reusable base cluster. So NOREUSE which is the default,should be specified.

    Too many Alternate Indexes built on a KSDS may lead to performance Degradation asaccess by alternate key requires twice as many I/Os . VSAM first locates the primary keyfrom the alternate index and then locates the Control Interval information from the recordkey index.

    For ESDS, VSAM builds AIX by mapping one field to the records RBA.

    Steps for defining and building alternate indexes:

    DEFINE AIX Command

    Define the Alternate Index Cluster using the IDCAMS DEFINE AIX command.

    33

  • 7/28/2019 Ver2 Vsam Mat

    34/64

    VSAM

    //STEP1 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT =*//SYSIN DD *

    DEFINE AIX -(NAME(DA0001T.LIB.KSDS.AUTHNAME.AIX)

    -VOLUMES (BS3013) -RELATE(DA0001T.LIB.KSDS.CLUSTER)

    -UPGRADE -TRACKS(10 1)

    -KEYS(25 9) -RECORDSIZE(70 110)FREESPACE(20 10)

    -SHAREOPTIONS(1) -NONUNIQUEKEY) -)

    DATA(NAME(DA000A1T.LIB.KSDS.AUTHNAME.DATA)) -INDEX(NAME(DA0001T.LIB.KSDS.AUTHNAME.INDEX)/*//

    Example 6.1 JCL to define AIX

    Pathname is the dataset name in JCL (DSN=PATHNAME)

    RELATE Parameter

    Format:RELATE(base cluster name)

    This parameter establishes the relationship between the base cluster and the alternate indexvia the use of the base cluster name. It is unique to the DEFINE AIX command, and it isrequired.

    The RECORDSIZE Parameter

    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. Thelength of a unique alternate index built over a KSDS is derived as follows:

    34

  • 7/28/2019 Ver2 Vsam Mat

    35/64

    VSAM

    Figure 6.1 Contents of KSDS unique alternate index

    For example if an unique alternate index on Soc-Sec-No is built on our KSDS clusterEmployee 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

    Therefore recordsize parameter will be coded as RECORDSIZE(20 20)

    KSDS non-unique alternate index: An alternate index created with a NONUNIQUEKEYparameter has variable length records. The RECORDSIZE is calculated as follows:-

    Avgerage Record length = 5 bytes for House Keeping + size of the alternate key + size ofthe 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 ofthe primary key x maximum no of records the alternate index key can point to

    DEFINE PATH Command:

    Define an Alternate Index Path using the IDCAMS DEFINE PATH command. The pathforms a connection between the alternate index and the base cluster. Path name becomes acatalog entry but path does not contain any records. The path name is specified in the JCL forapplications that access records via the alternate index.

    35

    HOUSEKEEPING Soc-Sec-No Emp-No

    5 9 8

  • 7/28/2019 Ver2 Vsam Mat

    36/64

    VSAM

    //STEP1 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT =*//SYSIN DD *

    DEFINE PATH -NAME(DA0001T.LIB.KSDS.AUTHNAME.PATH) -PATHENTRY(DA0001T.LIB.KSDS.AUTHNAME.AIX) -UPDATE -

    )/*//

    Example 6.2 JCL to define PATH for the AIX

    UPDATE vs NOUPDATE

    Records may be accessed by applications by the alternate index path alone, without openingthe base cluster. In such cases any changes made to data will be reflected in the alternateindex records if the UPDATE option is specified. If NOUPDATE is specified then thealternate index records will not be automatically updated.

    UPGRADE vs. NOUPGRADE

    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 reflectedimmediately in the alternate index records if the base cluster is opened in the application.Fortunately UPGRADE and UPDATE are defaults for their respective commands.

    Building Alternate Indexes

    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 correspondingprimary key field. VSAM creates a temporary file with these records.

    This temporary file is sorted in ascending alternate key sequence.

    If NONUNIQUEKEY option is specified then a merge operation takes place, which

    will merge all records with the same alternate key into a single record.

    36

  • 7/28/2019 Ver2 Vsam Mat

    37/64

    VSAM

    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.

    //STEP1 EXEC PG=IDCAMS//SYSPRINT DD SYSOUT =*//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/*//

    Example 6.3 JCL to build Alternate Index

    Disposition of base cluster is DISP=OLD as the BLDINDEX needs absolute control of thebase 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 theBLDINDEX 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)

    .)

    BLDINDEXINDATASET(DA0001T.LIB.KSDS.CLUSTER)OUTDATASET(DA0001T.LIB.KSDS.AUTHNAME.AIX)

    .)

    Example 6.4 Steps for creating and building AIX

    37

  • 7/28/2019 Ver2 Vsam Mat

    38/64

    VSAM

    7. Reorganizing VSAM datasets

    This chapter explains the commands used to back up and restore existing datasets, protect theintegrity of data.

    REPRO

    This command is used to:

    Loads empty VSAM cluster with records.

    Creates backup of a dataset

    Merge data from two VSAM datasets

    REPRO command can operate on non-VSAM datasets. It is an all-purpose load and backuputility command and can be used in place of IEBGENER.

    With REPRO you can do the following

    Convert an ISAM dataset to VSAM format

    Copy a non-VSAM dataset to a physical sequential or partitioned dataset

    Copy record from one type of VSAM datasets to another. For example KSDS to

    ESDS

    REPRO has following disadvantages:

    Little control over the input data

    Catalog information is not copied with the data

    Prior DELETE and redefinition is required before loading the cluster unless you have

    specified REUSE in the DEFINE CLUSTER command

    Incase of KSDS, data and index component are build automatically.

    REPRO Command Syntax

    Format :

    REPROINFILE(ddname) | INDATASET(dsname) -OUTFILE(ddname) | OUTDATASET(dsname) -

    Optional parameters are :FROMKEY FROMADDRESSFROMNUMBER SKIP

    TOKEY TOADDRESSTONUMBER COUNT

    38

  • 7/28/2019 Ver2 Vsam Mat

    39/64

    VSAM

    INFILE and OUTFILE are required parameters that point to DD1(input file) and DD2 (outputfile) respectively .

    Limiting Input and Output Records:-

    While it is not possible to edit the input to REPRO, you can limit the input by providing theoptional parameters.

    FROMKEY and TOKEY parameters: FROMKEY specifies the key of the input records atwhich 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 beforebeginning to copy. COUNT specifies the number of output records to copy. You can specifyboth. 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)

    Example 7.1 JCL for Loading Dataset:

    Other parameter for filtering records:

    FROMADDRESS (RBA)TOADDRESS(RBA)FROMNUMBER (RRN)TONUMBER(RRN)COUNT (NO.)

    SKIP(NO)

    Backing up VSAM Datasets

    It is good to backup VSAM datasets on a regular basis.REPRO command is used to rebuild and restore VSAM cluster from the backup copy.Backing up a VSAM dataset involves only one step

    39

  • 7/28/2019 Ver2 Vsam Mat

    40/64

    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)

    /*//

    Example 7.2 Using Repro for backup

    In the example above INDATASET is the input file and DD2 is the output tape datasetwhich is a part of the GDG while is more or less like a physical sequential file. (Ref tochapter 10 for more on GDGs )

    Restoring and rebuilding the backup

    DELETE-DEFINE-REPRO sequence required to restore the cluster incase of KSDS.Delete the original cluster using IDCAMS DELETE commandRedefine the cluster using IDCAMS DEFINE CLUSTER commandLoad the empty cluster with data using the IDCAMS REPRO command

    When you DELETE-DEFINE-REPRO a VSAM dataset it has the following effects on theKSDS.

    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 bysequence of entry or record number.

    40

  • 7/28/2019 Ver2 Vsam Mat

    41/64

    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)/*

    Example 7.3 DELETE-DEFINE-REPRO

    Merging datasets with REPRO

    The REPRO command can also be used to merge two datasets into one. The target datasetcan be a nonempty KSDS, ESDS or RRDS. If the target dataset is an ESDS, the mergedrecords 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 adataset, alternate index or a catalog to a different system.

    EMPORT/IMPORT has several advantages as compared to REPRO

    Catalog information is exported along with data

    Cluster deletion and redefinition not required during import as input dataset already containscatalog information

    Easily ported on other systems as catalog information available with data

    Like REPRO KSDS datasets are reorganized however three steps of REPRO are replaced byone

    41

  • 7/28/2019 Ver2 Vsam Mat

    42/64

    VSAM

    Disadvantages:

    Exported data cannot be processed until Imported

    Can be used only for VSAM dataset

    EXPORT

    FORMAT :

    EXPORT entryname | passwordOUTFILE(ddname) |OUTDATASET(dsname)

    Optional parameters

    Example :

    EXPORT DA0001T.LIB.KSDS.CLUSTER -OUTFILE(DD2)

    The output dataset from an EXPORT must alwaysbe a sequential dataset (usually on a tape)

    IMPORT

    Format :

    IMPORT -INFILE(ddname) | INDATASET(dsname) -OUTFILE(ddname) | OUTDATASET(dsname) -

    Optional parameters:

    IMPORT INFILE (DD2) -OUTDATASET(DA0001T.LIB.KSDS.CLUSTER)

    Imports only EXPORTED dataset

    42

  • 7/28/2019 Ver2 Vsam Mat

    43/64

    VSAM

    //DA0001TA JOB LA1279,PCS,MSGLEVEL=(1,1),// MSGCLASS=A, NOTIFY=DA0001T//* Input instream Data into ESDS VSAM Dataset// STEP1 EXEC PGM=IDCAMS// SYSPRINT DD SYSOUT = *// DD1 DD *123456789123456789AAAAAAAABBBBBBCCCC/*//DD2 DD DSN=DA0001T.ESDS.CLUSTER//SYSIN DD *

    REPRO -INFILE(DD1) -OUTFILE(DD2)

    /*//

    Example 7.4 Input instream Data into ESDS

    //DA0001TA JOB LA2719,PCS,MSGLEVEL= (1,1),// MSGCLASS=A, NOTIFY=DA0001T//* Load Data from a file into ESDS VSAM Dataset//STEP1 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT = *//DD1 DD DSN=DA0001T.ESDS.CLUSTER1//DD2 DD DSN=DA0001T.ESDS.CLUSTER2//SYSIN DD *

    REPRO -INFILE(DD1 -OUTFILE(DD2)

    /*//

    Example 7.5 Load Data from a file into ESDS

    43

  • 7/28/2019 Ver2 Vsam Mat

    44/64

    VSAM

    14. VERIFY , PRINT, DELETE, ALTER

    CommandVERIFY

    Verify - preserves data integrity (HURBA)

    Format :

    VERIFY FILE(ddname/passwd)or

    VERIFY DATASET(entryname/passwd)

    VERIFY entryname/passwd (TSO)

    VERIFY DATASET(DA0001T.LIB.KSDS.CLUSTER)

    Example 8.1 VERIFY

    Remark :

    VERIFY can be issued from a TSO or within a JCL statement.It is valid only for VSAM dataset except LDS.

    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

    44

  • 7/28/2019 Ver2 Vsam Mat

    45/64

    VSAM

    Optional parameters are :

    AIX

    CLUSTER

    NONVSAM

    PATH ERASE | NOERASE

    FORCE | NOFORCE

    PURGE | NOPURGE

    SCRATCH | NOSCRATCH

    //DA0001TA JOB LA2179,PCS,MSGLEVEL=(1, 1) ,// NOTIFY=DA0001T//* Deletes VSAM Dataset//STEP1 EXEC PGM=IDCAMS//SYSPRINT DD SYSOUT = *//SYSIN DD *

    DELETE DA0001T.TRAIN.ITMFOIV/*//

    Example 8.3 Delete VSAM Dataset

    PRINT

    The default output destination for PRINT is SYSPRINT.prints in CHAR/HEX/DUMP formatlimiting

    Format 1 :

    PRINT INDATASET (entryname/passwd) -

    Format 2 :

    PRINT INFILE (ddname/passwd) -

    parameters like REPRO are available

    Options

    CHAR | DUMP | HEX

    COUNT (number)

    45

  • 7/28/2019 Ver2 Vsam Mat

    46/64

    VSAM

    FROMADDRESS, [TOADDRESS]

    FROMKEY, [TOKEY]

    FROMNUMBER, [TONUMBER]

    OUTFILE (ddname)

    SKIP (number)

    //DA0001TA JOB LA2179,PCS,MSGLEVEL=(1, 1) ,// NOTIFY=DA0001T//* Print VSAM Dataset//PRG1 EXEC PGM=IDCAMS//FILE1 DD DSN=DA0001T.LIB.KSDS.CLUSTER,

    // DISP=SHR//SYSPRINT DD SYSOUT = *// SYSIN DD *

    PRINT INFILE(FILE1) CHARACTER/*//

    Example 8.4 Print VSAM Dataset

    ALTER

    Used to change certain attributes of a previously defined VSAM objectFollowing 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)

    46

  • 7/28/2019 Ver2 Vsam Mat

    47/64

    VSAM

    NEWNAME(newname)

    READPW (password)

    SCRATCH | NOSCRATCH

    SHAREOPTIONS

    (cross region cross system) TO(date) |FOR(days)

    UPDATE | NOUPDATE

    UPDATEPW(password)

    UPGRADE | NOUPGRADE

    The ORDERED Parameter

    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

    Example :

    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

    The IMBED Parameter directs VSAM to place the sequence set on the first track of the DataControl Area and duplicate it as many times as it will fit.Advantage : reduces rotational delay

    Format :IMBED | NOIMBED

    The REPLICATE Parameter

    47

  • 7/28/2019 Ver2 Vsam Mat

    48/64

    VSAM

    The REPLICATE Parameter directs VSAM to duplicate each index record as many times asit 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 -

    )

    The Password Protection Parameter

    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 packagelike RACF.

    Format :

    MASTERPW(password)

    Allows the highest level of access to all cluster components, including DELETE and ALTERauthority

    Format :

    UPDATEPW(password)

    Allows write authority to the cluster

    Format :

    READPW(password)

    Allows read only access to the cluster

    Note : Valid only for KSDS, ESDS, RRDS.Passwords are initially specified in the DEFINE

    CLUSTER

    Example :

    MASTERPW(TRGDEPT)

    At the execution time, a password can be coded explicitly in the PASSWORD clause of aCOBOL SELECT clause

    The AUTHORIZATION Parameter

    AUTHORIZATION provides additional security for a VSAM cluster by naming andassembler user verification routine (USVR).

    48

  • 7/28/2019 Ver2 Vsam Mat

    49/64

    VSAM

    Format :

    AUTHORIZATION (entry-point password)

    entry-point : the name of the entry point of a USVR

    written in assembly languagepassword : the password the routine is to verify

    Note : Valid only for KSDS, ESDS, RRDS.

    Example :

    AUTH(MYRTN TRGDEPT)

    ALTER -

    DA0001T.LIB.KSDS.CLUSTER -NEWNAME(A2000.MY.CLUSTER)

    Example 8.5 Altering name of a Dataset

    ALTER -DA0001T.LIB.KSDS.INDEX -FREESPACE(30 30)

    Example 8.6 Altering FREESPACE of a Dataset

    The following attributes are alterable only for empty clusters KEYS(length offset)

    RECORDSIZE(avg max)

    UNIQUEKEY | NONUNIQUEKEY

    The following attributes are unalterable. You have to DELETE the cluster and redefine itwith new attributes.

    CISZCluster type,IMBED/REPLICATEREUSE | NOREUSE

    49

  • 7/28/2019 Ver2 Vsam Mat

    50/64

    VSAM

    15. Generation DataSets

    Although there are many different uses for sequential datasets, many sequential files have onecharacteristics in common : they are used in cyclical applicationfor example, sequential dataset that contains transaction posted daily against a master file iscyclical; each days transactions, along with the processing required to post them, from onecycle. Similarly a sequential dataset used to hold the backup copy of a master file is cyclicaltoo; each time a new backup copy is made, new cycle is begun.

    In most of the cyclical applications, its good idea to maintain versions of the files used forseveral cycles. That way if something goes wrong, you can recreate the processing thatoccurred 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 ormore chronologically related versions of the same file. Each version of the file or member ofthe GDG, is called a generation dataset. A generation dataset may reside on tape or DASD. Itis generally sequential (QSAM) or direct(BDAM) file. ISAM and VSAM files cant be usedin GDGs.

    As each processing cycle occurs a new generation of dataset is added to the generation datagroup. The new version becomes the current generation; it replaces the old currentgeneration, which becomes a previous generation.

    file.c1(+1) Next Generationfile.c1(0) Current Generationfile.c1(-1) Previous Generationsfile.c1(-2)file.c1(-3)

    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 thecurrent generation is always referred to as relative generation 0.MVS uses the generation data groups catalog entry to keep track of relative generationnumbers. As a result, GDGs must be cataloged and each generation dataset thats a part of thegroup must be cataloged too.

    When you create a generation data groups catalog entry, you specify how many generationsshould be maintained Example: You might specify that five generations including the currentgeneration should be maintained. Then during each processing cycle, the new version of thefile becomes the current version.

    50

  • 7/28/2019 Ver2 Vsam Mat

    51/64

    VSAM

    Although MVS lets you use relative generation numbers to simplify cyclical processing,MVS uses Absolute Generation Numbers in the form GnnnnV00 to identify eachgeneration dataset uniquely. GnnnnV00 represents the chronological sequence number of thesequence 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. Thesequence and version numbers are stored as a part of the files 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)\

    Example 9.1 Using a GDG

    Relative Name and Absolute Name

    DA0002T.MASTER.DAY90) ---> Relative NameDA0002T.MASTER.DAY.G00001V00 -->Absolute Name

    // Step1 EXEC PGM=IDCAMS// SYSPRINT DD SYSOUT = *// SYSIN DD *

    DEFINE GDG(NAME(DA0002T.MASTER.DAY)

    LIMIT(5)SCRACHEMPTY)

    /*

    Example 9.2 Defining a GDG Index

    51

  • 7/28/2019 Ver2 Vsam Mat

    52/64

    VSAM

    Following code contains 1 job with 2 steps....

    //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=*

    Example 9.3a Adding datasets to a GDG

    Following code contains 2 jobs.........

    //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=*

    Example 9.3b Adding datasets to a GDG

    GDGs are agroup of datasets which are related to each other chronologically and functionally.Generations can continue until a specified limit is reached. The LIMIT parameterspecifies total number of generations that can exist at any one time.

    Once limit is reached the oldest generation is deleted.

    GDG Indexhave 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 bespecified.All datasets within a GDG will have the same name. Generation number of a dataset, within aGDG is automatically assigned by OS when created. Datasets within a GDG can bereferenced by their relative generation number. Generation 0 always references currentgeneration

    52

  • 7/28/2019 Ver2 Vsam Mat

    53/64

    VSAM

    Creation of GDGs

    Create and catalog the indexUse IDCAMS statement DEFINE GDG for creating IndexParameters for creating index

    Specification

    Name of GDGNumber of generationsLimit . maximum no of datasets in a GDG.Action to be taken when limit is reached

    Uncataloging oldest generation once limit reached

    Uncataloging all generations when limit reached

    Physical deletion of entry

    Uncataloging entry without physical deletion

    Defining a model for the GDG.

    NAME refers to the name of the GDG Index

    LIMIT .. refers to the maximum no of datasets in a GDG.

    NOEMPTYEMPTY SCRATCH .NOSCRATCH

    Modifying Features of GDG

    You can modify a GDG only with the ALTER command

    //STEP1 EXEC PGM=IDCAMS//SYSINDD

    ALTER DA0001T.ACCOUNTS.MONTHLY -NOSCRATCH -EMPTY

    /*//

    Example 9.4 Modifying a GDG

    53

  • 7/28/2019 Ver2 Vsam Mat

    54/64

    VSAM

    Deleting GDG Index

    Can be deleted by the DELETE parameter of IDCAMSWill result in an error on reference to any generation datasets of the GDG

    /STEP1 EXEC PGM=IDCAMS//SYSINDD

    DELETE DA0001T.ACCOUNTS.MONTHLY GDG/*//

    Example 9.5 Deleting GDG Index

    Adding a Dataset to a GDG

    Name of the model containing the GDG DCB parameters is coded in the DCB parameter ofthe DD statement

    //STEP1 EXEC PGM=GDG1//FILE1 DD// DSN=DA0001T.ACCOUNTS.MONTHLY(+1),// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,// SPACE=(TRK,(30,10),RLSE),// DCB=(MODEL.DCB,// RECFM=FB,LRECL=80,

    // BLKSIZE=800)Example 9.6 Adding a Dataset to a GDG

    Deleting GDG Index and Datasets

    FORCE parameter in the DELETE statement of IDCAMS can be used

    Example :

    /STEP1 EXEC PGM=IDCAMS//SYSINDD

    DELETE DA0001T.ACCOUNTS.MONTHLY` -GDG -FORCE

    /*//

    Example 9.7 Deleting GDG Index and Datasets

    54

  • 7/28/2019 Ver2 Vsam Mat

    55/64

    VSAM

    16. COBOL VSAM Considerations

    SELECT CLAUSE

    SELECT file ASSIGN TO DDNAME / AS-DDNAME

    ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVEACCESS MODE IS SEQUENTIAL/INDEXED/DYNAMICRECORD KEY IS primary Key DatanameALTERNATE KEY IS Alternate Key Dataname [With Duplicates]FILE STATUS IS status-key.

    Example 10.1 SELECT clause for VSAM datasets

    status key=Cobol, VSAMx(2) 9(2) - Return code

    9(1) - Junction code9(3) - Feedback code

    FD Entry

    Should have the record structure

    If KSDS then key field must match with length and position of KEYS parameter in DEFINE

    CLUSTER information

    File Processing

    Regular COBOL file handling commands

    Alternate index processing :

    In JCL there must be a DD statement for base cluster and one or more DD statement foralternate 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

    55

  • 7/28/2019 Ver2 Vsam Mat

    56/64

    VSAM

    Remark:

    No matter how many alternate indexes you specify in the program, theres only one ASSIGN

    clause pointing to the ddname of the base cluster.

    SELECT file ASSIGN TO LIBMAST

    RECORD KEY IS ............ALTERNATE KEY IS .........

    [WITH DUPLICATES]

    Example 10.3 Cobol SELECT clause for AIX

    FD : Should have record description having primary key dataname and alternate key

    dataname

    KEY of reference : READ filenameKEY IS primary/alternate key

    dataname

    Key of Reference.

    The key that is currently being used to access records is called the key of reference. When theprogram 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 startaccessing records by an alternate index key, you merely change the key of reference by usingthe KEY phrase as part of one of the following statements.

    A random READ statement, for example

    READ EMP-MAST KEY IS EMP-NAME

    Example 10.4 READ

    A sequential READ statement, for example

    READ EMP-MAST NEXTKEY IS EMP-NAMEA

    Example 10.5 READ for Accessing AIX

    START statement, for example

    START EMP-MASTKEY IS EQUAL TO EMP-NAME.

    Example 10.6 START verb

    56

  • 7/28/2019 Ver2 Vsam Mat

    57/64

    VSAM

    key-1 key-2 Cause

    Successful Completion:0 0 No further information,

    2 Duplicate key detected.

    4 Wrong fixed-length record.5 Data set created when pened.With

    sequential VSAM datasets,0 is returned.7 CLOSE with NO REWIND or

    REEL, for non-tape.End-of-file.1 0 No further information.

    4 Relative record READ outsidedataset boundary.

    Invalid key.

    2 1 Sequence error.2 Duplicate key.3 No record found.4 Key outside boundary of dataset.

    Permanent I/O error :3 0 No further information.

    4 Record outside dataset boundary.5 OPEN and required dataset not found.7 OPEN with invalid mode.8 OPEN of dataset closed with LOCK.9 OPEN unsuccessful because of

    conflicting dataset attributes.

    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-Oor EXTEND.

    9 DELETE or REWRITE for dataset not opened I-O.

    Specific compiler-defined conditions :9 0 No further information.

    1 VSAM password failure.2 Logic error.3 VSAM resource not available.4 VSAM sequential record not available.

    5 VSAM invalid or incomplete dataset information.

    57

  • 7/28/2019 Ver2 Vsam Mat

    58/64

    VSAM

    9 6 VSAM-no DD statement.7 VSAM OPEN successful.Dataset integrity verified.

    VSAM I/O error processing

    I/O error handling is one vital area where VSAM dataset processing differs from non-VSAMdataset processing. When processing non-VSAM datasets, most programmers code theirapplication programs to ignore errors, because the access method would abend the program ifa serious I/O error occurs. Not so when processing VSAM datasets.

    The COBOL FILE STATUS Key

    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 afterevery 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 continueprocessing.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 continueprocessing :

    21 Input record out of sequence.22 duplicate primary key or unique alternate key

    encountered (un-expected).23 record (or Key) not found.

    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

    For the following status key values, terminate the program :

    24 out-of-space condition (KSDS or RRDS).30 Nonspecific I/O problem.34 out-of-space condition(ESDS).49 REWRITE attempted; dataset not opened for I-O.90 Dataset unusable or logic error.92 logic error.93 Resource not available.94 current record pointer undefined.95 Nonzero HURBA for OPEN OUTPUT.96 No corresponding JCL DD statement.97 If your shop has enabled the implicit VERIFY command, this means that the

    dataset was opened after and implicit VERIFY, and you can continueprocessing.

    58

  • 7/28/2019 Ver2 Vsam Mat

    59/64

    VSAM

    17. Appendix-A

    VSAM ASSIGNMENT

    a. Define an ESDS cluster. Populate the ESDS cluster by using a COBOL program.Using LISTCAT command list the attributes of the created cluster.

    b. Define a KSDS cluster with the following options:

    Allocation for 3000 records primary, secondary allocations for 100 records.Fixed record length of 80 bytes each.Key beginning in the 5th position with length of 5 bytes.Volume parameters.

    c. Populate the KSDS cluster by using a COBOL program. Using LISTCAT commandlist the attributes of the created cluster.

    d. Write a program to populate an indexed master file from transaction records. Thereare three datasets.

    PRODUCT-MASTER Record Layout

    1 5 6 10

    PURCHASE-TRANS Record Layout

    1 5 6 25 26 28 29 33

    CUSTOMER-MASTER Record Layout

    1 5 6 13 14 18

    59

    Prodno unit price

    Custno Name Qty Prodno

    Custno Amount Prodno

  • 7/28/2019 Ver2 Vsam Mat

    60/64

    VSAM

    1. A table of product numbers and corresponding unit prices is to be created in storagefrom PRODUCT-MASTER. There are 50 product numbers.

    2. Customer number is the key field for the CUSTOMER-MASTER file

    3. Amount owed = Quantity Purchased x Unit Price (from table)

    4. Perform a table look up using the product number from the PURCHASE-TRANSrecord to find the corresponding unit price in the PRODUCT-MASTER table.

    e. An indexed file contains the following table records:

    1.2 State number 3.4 County number

    5.7 Tax rate8.11 Not used

    The key field is a combined group item consisting of state number and country number.Create a KSDS cluster and populate the cluster from the following transaction records.

    1.5 Customer number 6.25 Customer name26.28 Qty29.33 Price per unit34.35 State number

    36.37 County number37 Not used

    The output master file is also an indexed file with following record layout

    1.37 Same as positions 1-37 in the transaction record38.45 Amount Owed

    46 Not used

    Amount Owed = Qty x Price per unit + Tax rate x (Qty x Price per unit )

    60

  • 7/28/2019 Ver2 Vsam Mat

    61/64

    VSAM

    18. Appendix -B

    References

    MVS/VSAM for Application Programmer by Brown and Smith

    VSAM by Doug Lowe

    VSAM for COBOL Programmer by Doug Lowe

    61

  • 7/28/2019 Ver2 Vsam Mat

    62/64

    VSAM

    19. Appendix-C

    Table of Figures

    14. Appendix-D

    62

    Figure 2.1 VSAM Catalog.......................................................................................................7

    Figure 2.2 Space Allocation.....................................................................................................9

    Figure 3.1 Contents of Control Interval ..............................................................................10

    Figure 3.2 Contents of Control Field....................................................................................10

    Figure 3.3 Control Area.........................................................................................................11

    Figure 3.4 Spanned Record...................................................................................................12

    Figure 3.5 Contents of Control Area...................................................................................14

    Figure 3.6 Contents of KSDS Index ....................................................................................14

    Figure 3.7 Contents of Sequence Set.....................................................................................15

    Figure 3.7 Contents of Index Set ..........................................................................................15

    Figure 3.8 Inserting a new record into a KSDS...................................................................16

    Figure 3.9 Inserting a new record into a full CI..................................................................17

    Figure 3.10 After Control Interval Split..............................................................................17

    Figure 3.11a Effect of Control Interval Split on Sequence Set......................................18

    Figure 3.11b Effect of Control Interval split on Sequence Set..........................................19

    Figure 5.1 HURBA and HARBA..........................................................................................32

    Figure 6.1 Contents of KSDS unique alternate index.........................................................35

  • 7/28/2019 Ver2 Vsam Mat

    63/64

    VSAM

    Table of JCL listing

    63

  • 7/28/2019 Ver2 Vsam Mat

    64/64

    VSAM

    Example 4.1 JCL for executing IDCAMS commands......................................................21

    Example 4.2 Creating a cluster........................................................................................... .21

    Example 4.3a JCL using MAXCC and LASTCC..............................................................23

    Example 4.3b JCL using MAXCC and LASTCC..............................................................23

    ...............................................................................................................................................23

    Example 4.4 JCL for Defining an ESDS Cluster................................................................26

    Example 4.5 JCL for Defining a KSDS Cluster.................................................................27

    Example 5.1 LISTCAT.........................................................................................................30

    Example 6.1 JCL to define AIX...........................................................................................34

    Example 6.2 JCL to define PATH for the AIX...................................................................36

    Example 6.3 JCL to build Alternate Index.........................................................................37

    Example 6.4 Steps for creating and building AIX..............................................................37

    Example 7.1 JCL for Loading Dataset:...............................................................................39

    .................................................................................................................................................39

    Example 7.2 Using Repro for backup.................................................................................40

    Example 7.3 DELETE-DEFINE-REPRO.........................................................................41

    Example 7.4 Input instream Data into ESDS ....................................................................43

    Example 7.5 Load Data from a file into ESDS.................................................................43

    Example 8.1 VERIFY...........................................................................................................44

    Example 8.2 Deleting a Cluster...........................................................................................44

    Example 8.3 Delete VSAM Dataset.....................................................................................45

    Example 8.4 Print VSAM Dataset.......................................................................................46

    Example 8.5 Altering name of a Dataset.............................................................................49

    Example 8.6 Altering FREESPACE of a Dataset...............................................................49