Thursday, 5 July 2012

Creation of KSDS file with JCL....


Key Sequential Dataset


     1) A Key Sequenced Data Set (KSDS) is a type of  VSAM data  system. Each record in a KSDS data file is embedded with a unique key. A KSDS consists of two parts, the data component and a separate index file known as the index component which allows the system to physically locate the record in the data file by its key value. Together, the data and index components are called a cluster.



     2) Records can be accessed randomly or in sequence and can be variable-length.

        We can’t directly use the KSDS file first we have to create the KSDS file.  

           First we will see the program that creates the KSDS file.


    // KSDSNEW1  JOB 'AK85427','AVINASH',NOTIFY=&SYSUID  
    //STEP1 EXEC PGM=IDCAMS                             
    // SYSPRINT DD SYSOUT=*                    
    //SYSOUT DD SYSOUT=*                                
    // SYSIN DD *                                        
    //DEFINE CLUSTER(NAME(SK648K.AVINASH.KSDS1)-        
    //TRACKS(3,1)-        
    //KEYS(3,0)-                             
    //CONTROLINTERVALSIZE(4096)-                       
    // FREESPACE(10,10)-                              
    // RECORDSIZE(35,70)) 
   /*

   
   

     See below Mainframe program i have written in my PDS member to create the KSDS new file which i am going to use for my data storing.








Now i will tell you the function of each in brief.


1)//KSDSNEW1  JOB 'AK85427','AVINASH',NOTIFY=&SYSUID  
This is my Job card.

Job name=KSDSNEW1
‘AK85427'=Accounting information.
AVINASH=programmer Name
NOTIFY=&sysuid will notify all messages related to this job to me.

2)STEP1 EXEC PGM=IDCAMS      
              
Stepname=step1------you can give any stepname but it should be 8 char.Not started with any digit.

EXEC=it is control card name

PGM=IDCAMS(Integrated Data Control Access Method)

As we are working for Data operation.

It is utility required for the  creation of any VSAM file. 

 3) SYSPRINT DD SYSOUT=*  
                            
It allocate a printing device for this operation and gives the result in spool

 4)SYSOUT DD SYSOUT=*

It says that output message of the system is shown in the spool as sysout=*
If we have written sysout dd dsn=file name then this will stores the information in respective file.

5)SYSIN DD *
This is the control card which control the operation of creation of KSDS file.


1)  DEFINE CLUSTER(NAME(SK648K.AVINASH.KSDS1)- 
       
CLUSTER----It is logical name for defining a VSAM file.It can be a dataset contains both Index and data component.
But this criteria only satisfied by KSDS file only.
NAME(dataset name)


2) Defining the space

TRK/CYL (primary quantity,secondary quantity)
I have given TRK(3,1)
It means that on my volume please give me a primary space of 3 Track and if it is fulled by my data please add 1 more TRK space as secondary space.
As many of don’t know the difference in TRK and CYL space they are just giving it blindly so i would like to explain the terms TRK and CYL.
TRK-----1 TRK=56,664 bytes
CYL----1 CYL=15 TRK=849,960 Bytes per Cylinder
See more information on   http://www.lascon.co.uk/hwd_3390_disks.php


3) Defining the primary key

This is nothing but a unique column value from your file .

For ex. If your file having employee record which contain different columns like employee id,employee Name,City here employee name , city can be same but employee id is always different so we are doffing Employee id as primary key.

Suppose in my file the employee id is started at column 1 whose length is 3 digit. Now i want to define keys parameter to tell the system that it is my unique field and i want to search the records by this key.

So in INDEX of KSDS file it will store the employee id with its corresponding address in memory.

So be careful while defining the Key column.
Offset means its position from column 1.
Here my employee id field starts at column 1 so its offset is 3.
So i defined keys(3,0).

If my field length is 5 and starts at column 10 then keys will be
Keys(5,10).
  
 
  4) Defining Control interval

 A Control Interval can contain many records. If the records are not all of constant length, the number of records in each CI will also vary. Also, as we will see when we discuss record insertion, all CIs are created with a moderate amount of free space (to leave room for newly inserted records).
All of the records in a CI (along with their keys) are packed at the beginning of the CI. At the end of each CI is a descriptor (including a record length) for each record in the CI. The area between the records and their descriptors is free space ... to accommodate new records.










It is just like a fixed length  block.

Size of control interval is ranging from 4096 bytes to 32k bytes.

In control interval actual records get inserted.

Frankly speaking a programmer never minds how the data stores internally.
Suppose i have defined my space =1 trk=56,664 bytes and my control interval size is 4096 bytes. Then 56,664/4096 = approximately 14 Control interval will be created.
All the control interval are grouped in control area.



Control Area 1

Control interval A
Control interval B
Control interval C
Control interval D
Control interval E

Control Area 2
Control interval F
Control interval G
Control interval H
Control interval I
Control interval J




I would like to more highlight on programming of VSAM so for deep information  about CI and CA please follow the below links


http://www.exforsys.com/tutorials/mainframe/vsam-control-interval-and-control-area/1.html

http://www.mainframes360.com/2009/07/vsam-tutorial-01-introduction-to.html

     5)   Freespace


      FREESPACE(CI CA) – Specifies the percentage of free space to reserve for the control intervals (ci) and control areas (ca) of the data component.


    6) Record size

    RECORDSIZE/RECSZ(AVG ,MAX) – Specifies the average and maximum record size.
    Depends upon the requirement.
    It's nothing but the minimum and maximum record size.

   The out put of program will creates 3 files as follows.





Now you have doubt where to store actual data its in .DATA file or in .KSDS1 or in .INDEX

Let me clear it….

The actual data is stored in cluster file i.e. MYID.avinash.ksds1 . you can’t open .data and .Index file that is for syatem use.
Many sites define the program with data name and index name also included in the program but no need to defines this it will automatically created.
So control interval field also multiple of 4096 bytes.

Now I will show you how to store a data manually.

You can’t edit a VSAM file like a ps file if you try to open the file by typing E against it.shows you an error.

So I am using File aid tool to open a VSAM file and stores date in it.
In KSDS always data stored in ascending order.





Suppose If I am going to insert  any word which is not ascending then it will shows you error while saving the content.

Now I am inserting amit after zebra then you can see the error message.




So be careful while inserting a data.

Now if I am going to save a duplicate record it will shows a message like





So this data can’t be saved. DUP means duplicate.

If I don’t know my record length?

If you don’t know your record length then no need to write it it will take it as variable length records .

Now if I would like to delete my KSDS file as we are creating the file we have  authority to delete also.

You may have doubt can I have to delete cluster file ,data file,index file separately. Just a minute I will clear your all doubts.

Now I want to delete my KSDS file name ‘sk648k.avinash.ksds3’ so below jcl I am going to use in my JCL program.


//TXXXXXJ     JOB , ,NOTIFY=&SYSUID
//STEP1       EXEC PGM=IDCAMS             
//SYSPRINT DD SYSOUT=*              
//SYSIN DD *               
          DELETE TXXXXX.VSAM.KSDSFILE
/*


So below program I have written in my JCL.






It runs successful and gives maxcc=0.

 So all files with data,Index component got deleted.




No comments:

Post a Comment