Sunday, June 8, 2014

How to define KSDS, ESDS ,RRDS VSAM with IDCAMS.. Explanation of the VSAM parameters

VSAM is one file storage system used to store and retrieve data. It stores data, but not like a relational model or hierarchical model like DB2 or IMS. In fact, there are many structures in DB2, which are implemented using VSAM .We can use VSAM files in both batch and online(CICS) operations.
How do we create a vsam file?
The IBM Access Methods Services (AMS) utility,popular as IDCAMS is the utility to create and maintain VSAM files. In this context,we should know that VSAM is totally catalog driven.When ever we create a VSAM dataset,ie a VSAM file, an entry is recorded in the system catalog which stores the cluster informtion.
Vsam Cluster? what is it ? ::
In this VSAM world,simple VSAM files are often called clusters. A cluster is the set of catalog entries that represent a file.
So, how many types of VSAM can we create, rather how many types of VSAM are there?
The answer is 4 types:
1.ESDS    or Entry Sequenced dataset
2.KSDS    or Key Sequenced dataset
3.RRDS    or Relative record dataset
4.LDS     or Linear dataset
Frankly,till date i never came across the use of LDS or RRDS. The most Widely used VSAM are KSDS and ESDS.
Lets see the JCL to create a KSDS:
How to create a KSDS and the description of the parameters.

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

  DEFINE CLUSTER(             -                
       NAME(TEST.FILE.MYVSAM) -              
       RECSZ(300 2000)      -                
       KEYS(41 20)          -                
       MANAGEMENTCLASS(xxxx) -           
       INDEXED              -                
       SPEED                -                
       SHR  (2 3)           -                
       FSPC (24,7)          -                
       BUFSP (39936)        -                
       DATACLAS (DCVSEXT))  -                
       DATA(NAME(
TEST.FILE.MYVSAM.DATA) -    
         CISZ (18432)         -              
         CYL  (200,100))       -             
       INDEX (NAME(
TEST.FILE.MYVSAM.INDEX) - 
         CISZ (1024)          -              
         CYL  (10,10))

As we see, the CLUSTER have two components here. The DATA and the INDEX part.
The keywords are marked and highlighted in red.
Explanation of the VSAM parameters:

1. RECORDSIZE(300  2000)
Specifies the record length of the file. The first parameter specifies the average length of the record and second parameter tells the maximum record length.
RECORDSIZE(avg  max)
avg : Average length of records
max : Maximum length of records
e.g. :
 RECORDSIZE(300  2000) [Fixed Length records]
 RECORDSIZE(300  300)    [Variable Length records]
Note :  RECORDSIZE or RECSZ  can also be used in the IDCAMS define step.
We can use this parameter in the cluster level as well as in the data level.
If not used, VSAM will use its default recordsize which is  RECORDSIZE(4086 4086)
 
2. KEYS(41 20)
The first parameter defines the key length and the second parameter defines the offset, ie, the beginning of the key position from the starting of the record
Thus the general format is like :
        KEYS(length-of-the-key  offset-from-begining)

3. MANAGEMENTCLAS : Optional Clause

4. INDEXED: This specifies that the VSAM is a KSDS VSAM

5. SPEED or RECOVERY option is coded at the CLUSTER or DATA level.It just governs how the VSAM load data into the file.
   With the RECOVERY option, the VSAM pre-formats each Control area with binary  zeros before it  writes any control interval to it. When SPEED is specified, no such additional activity is performed and therefore the data loading is much faster with SPEED option.

6..FSPC (24,7): FSPC or FREESPACE(24,7) is same thing.
FREESPACE parameter applies to the KSDS.This free space can be used for adding new records or for expanding existing variable records.FREESPACE applies only to the data component. For the FREESPACE parameter, the first value defines the percentage of free space to be reserved within each control interval, and the second defines the number of control intervals within each control area that should be reserved as free space.
Default is FREESPACE(0 0)

7. SHR  (2 3)OR SHAREOPTIONS ( 2 3):
This parameter tells VSAM whether you want to let two or more jobs to process your file at the same time. It specifies how a VSAM dataset can be shared. This is a big topic to deal with .Read here to explore this feature.
8. BUFSP(39936):  The number of buffers that can be used to hold INDEX and DATA records.
9. CYLINDERS(Pri Sec)or CYL(200,100):Primary : Number of units of primary space to allocate.This amount is allocated once when the dataset is created.Secondary : Number of units of secondary space to allocate.

In the DEFINE CLUSTER command we need to mention the type of VSAM we are creating like:

INDEXED   for KSDS
NONINDEXED  for  ESDS
NUMBERED for  RRDS
LINEAR for  LDS

So, Here is the sample JCL for ESDS VSAM

DEFINE CLUSTER(                   -               
           NAME(TEST.RM3452.FILE) -             
           RECSZ(300 2000)        -                     
           NONINDEXED             -               
           SPEED                  -               
           SHR  (2 3)           
      DATA(NAME(TEST.RM3452.FILE.DATA) -   
             CISZ (18432)              -             
             CYL  (200,100))           -

No comments:

Post a Comment