Comprehensive Educational information on Computer Programming!: 2019

Monday, February 25, 2019

VSAM - File Status

While working with VSAM datasets you may encounter abends. Following are the common file status codes with their description which will help you to resolve the issues −
CodeDescription
00Operation completed successfully
02Non-Unique Alternate Index duplicate key found
04Invalid fixed length record
05While performing OPEN File and file is not present
10End of File encountered
14Attempted to READ a relative record outside file boundary
20Invalid Key for VSAM KSDS or RRDS
21Sequence error while performing WRITE or changing key on REWRITE
22Primary duplicate Key found
23Record not found or File not found
24Key outside boundary of file
30Permanent I/O Error
34Record outside file boundary
35While performing OPEN File and file is not present
37OPEN file with wrong mode
38Tried to OPEN a Locked file
39OPEN failed because of conflicting file attributes
41Tried to OPEN a file that is already open
42Tried to CLOSE a file that is not OPEN
43Tried to REWRITE without READing a record first
44Tried to REWRITE a record of a different length
46Tried to READ beyond End-of-file
47Tried to READ from a file that was not opened I-O or INPUT
48Tried to WRITE to a file that was not opened I-O or OUTPUT
49Tried to DELETE or REWRITE to a file that was not opened I-O
91Password or authorization failed
92Logic Error
93Resources are not available
94Sequential record unavailable or concurrent OPEN error
95File Information invalid or incomplete
96No DD statement for the file
97OPEN successful and file integrity verified
98File is Locked - OPEN failed
99Record Locked - Record access failed

Saturday, February 23, 2019

VSAM - Catalog

Catalog maintains the unit and volume where dataset resides. Catalog is used for retrieval of datasets. Non-VSAM datasets create a catalog entry by means of Disposition Parameter in JCL. VSAM datasets maintains its own catalog in form of KSDS cluster. In following image you can see the type of VSAM catalogs −
Catalog

Master Catalog

Master catalog is itself a file which monitors and manages operations of VSAM. Their is only one master catalog in any system which contains entries about system datasets and VSAM datasets. VSAM and Non-VSAM datasets may have entry in master catalog but this is not a good practice. The master catalog is created during system generation process and resides on system volume. Master catalog owns all VSAM resources in operating system. All files used in VSAM are controlled by master catalog. Master catalog is responsible for following operations −
  • Password Authorization for files
  • Enhancing the Security
  • VSAM access for files
  • Space Management of file
  • Location of file
  • Free Space available in file
When any of the above file attributes changes they are automatically updated in master catalog. Master catalog is defined using IDCAMS programs.

User Catalog

User catalog has same structure and concepts as the master catalog. It is present at next hierarchy level after master catalog. User catalog is not mandatory in the system but it is used to enhance security of VSAM system. Master catalog points to VSAM files but if User catalog is present then master catalog points to user catalog. User catalogs can be many in number as per the system requirement. In VSAM structure if master catalog is removed then it will not affect the user catalog. User catalog contain entries about application specific datasets. The information of user catalog is stored in master catalog.

Data Space

Data space is an area of the direct access storage device that is exclusively allocated for VSAM use. Data space must be created before creating VSAM clusters. The area occupied by the data space is recorded in the Volume Table of Contents (VTOC), so that the space will not be available for allocation to any other use, either VSAM or non-VSAM. VTOC has entry of area occupied by space. VSAM creates a data space to hold the user catalog entries. VSAM takes control of this space and monitors and maintains this space as needed by VSAM files.

Unique Clusters

Unique Clusters consists of a separate data space which is utilized completely by the cluster created within it. Unique clusters are created out of unallocated space on direct access storage.

Sub-allocated Clusters

A sub-allocated VSAM file shares the VSAM space with other sub-allocated files. It specifies that file should be sub-allocated within existing VSAM space. Sub-allocation is used for easier management and control of VSAM spaces.

Non-VSAM datasets

Non-VSAM datasets resides on both tape and direct access storage. Non-VSAM datasets may have entries in both master catalog and user catalogs. The main function of cataloging non-VSAM datasets is to retain unit and volume serial information.

VSAM - Alternate Index

Alternate index are the additional index that are created for KSDS/ESDS datasets in addition to their primary index. An alternate index provides access to records by using more than one key. The key of alternate index can be a non-unique key, it can have duplicates.

Creation of Alternate Index

Following steps are used to create an Alternate Index −
  • Define Alternate Index
  • Define Path
  • Building Index

Define Alternate Index

Alternate Index is defined using DEFINE AIX command.
DEFINE AIX                              -
(NAME(alternate-index-name)             -
RELATE(vsam-file-name)                  -
CISZ(number)                            -
FREESPACE(CI-Percentage,CA-Percentage)  -
KEYS(length offset)                     -
NONUNIQUEKEY / UNIQUEKEY                -
UPGRADE / NOUPGRADE                     -
RECORDSIZE(average maximum))            -
DATA                                    -
   (NAME(vsam-file-name.data))          -
INDEX                                   -
   (NAME(vsam-file-name.index))
Above syntax shows the parameters which are used while defining Alternate Index. We have already discussed some parameters in Define Cluster Module and some of the new parameters are used in defining Alternate Index which we will discuss here −
Sr.NoParameters with Description
1
DEFINE AIX
Define AIX command is used to define Alternate Index and specify parameter attributes for its components.
2
NAME
NAME specifies the name of Alternate Index.
3
RELATE
RELATE specifies the name of the VSAM cluster for which the alternate index is created.
4
NONUNIQUEKEY / UNIQUEKEY
UNIQUEKEY specifies that the alternate index is unique and NONUNIQUEKEY specifies that duplicates may exist.
5
UPGRADE / NOUPGRADE
UPGRADE specifies that the alternate index should be modified if the base cluster is modified and NOUPGRADE specifies that the alternate indexes should be left alone if the base cluster is modified.

Example

Following is a basic example to show how to define an Alternate Index in JCL −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   DEFINE AIX (NAME(MY.VSAM.KSDSAIX)      -
   RELATE(MY.VSAM.KSDSFILE)               -
   CISZ(4096)                             -
   FREESPACE(20,20)                       -
   KEYS(20,7)                             -
   NONUNIQUEKEY                           -
   UPGRADE                                -
   RECORDSIZE(80,80))                     -
   DATA(NAME(MY.VSAM.KSDSAIX.DATA))       -
   INDEX(NAME(MY.VSAM.KSDSAIX.INDEX))
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will create MY.VSAM.KSDSAIX Alternate Index.

Define Path

Define Path is used to relate the alternate index to the base cluster. While defining path we specify the name of the path and the alternate index to which this path is related.
DEFINE PATH                        -
NAME(alternate-index-path-name)    -
PATHENTRY(alternate-index-name))
Above syntax has two parameters. NAME is used to specify the Alternate Index Path Name and PATHENTRY is used to specify Alternate Index Name.

Example

Following is a basic example to define Path in JCL −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
DEFINE PATH                          -
   NAME(MY.VSAM.KSDSAIX.PATH)    -
   PATHENTRY(MY.VSAM.KSDSAIX))
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will create path between Alternate Index to the base cluster.

Building Index

BLDINDEX command is used to build the alternate index. BLDINDEX reads all the records in the VSAM indexed data set (or base cluster) and extracts the data needed to build the alternate index.
BLDINDEX                           -
INDATASET(vsam-cluster-name)       -
OUTDATASET(alternate-index-name))
Above syntax has two parameters. INDATASET is used to specify the VSAM Cluster Name and OUTDATASET is used to specify Alternate Index Name.

Example

Following is a basic example to Build Index in JCL −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   BLDINDEX                           -
   INDATASET(MY.VSAM.KSDSFILE)        -
   OUTDATASET(MY.VSAM.KSDSAIX))
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will build the index.

VSAM - Commands

VSAM commands are used to perform certain operations on VSAM datasets. Following are the most useful VSAM commands −
  • Alter
  • Repro
  • Listcat
  • Examine
  • Verify

Alter

ALTER command is used to modify VSAM file attributes. We can change the attributes of VSAM file which we have mentioned in VSAM Cluster definition. Following is the syntax to change the attributes −
ALTER  file-cluster-name [password] 
   [ADDVOLUMES(volume-serial)] 
   [BUFFERSPACE(size)] 
   [EMPTY / NOEMPTY] 
   [ERASE / NOERASE] 
   [FREESPACE(CI-percentage CA-percentage)] 
   [KEYS(length offset)] 
   [NEWNAME(new-name)] 
   [RECORDSIZE(average maximum)] 
   [REMOVEVOLUMES(volume-serial)] 
   [SCRATCH / NOSCRATCH] 
   [TO(date) / FOR(days)] 
   [UPGRADE / NOUPGRADE] 
   [CATALOG(catalog-name [password]]
Above syntax shows which parameters we can alter in an existing VSAM cluster. The parameter description remains the same as mentioned in VSAM - Cluster module.

Example

Following example shows how to use ALTER command to increase Freespace, to add more volumes and to Alter Keys −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN DD  *
   ALTER  MY.VSAM.KSDSFILE 
   [ADDVOLUMES(2)] 
   [FREESPACE(6 6)] 
   [KEYS(10 2)] 
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will alter the Freespace, Volumes and Keys.

Repro

REPRO command is used to load data into VSAM dataset. It is also used to copy data from one VSAM data set to another. We can use this command to copy data from sequential file to VSAM file. IDCAMS utility uses REPRO command to load the datasets.
REPRO INFILE(in-ddname) 
   OUTFILE(out-ddname) 
In the above syntax, the in-ddname is DD name for the Input Dataset which is having records. The out-ddname is the DD name for the Output Dataset, where the input datasets records will be copied.

Example

Following example shows how to copy records from one dataset to another VSAM dataset −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//IN  DD DSN = MY.VSAM.KSDSFILE,DISP = SHR
//OUT DD DSN = MY.VSAM1.KSDSFILE,DISP = SHR
//SYSPRINT DD  SYSOUT = *
//SYSIN DD  *
   REPRO INFILE(IN) 
      OUTFILE(OUT)
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will copy all the records from MY.VSAM.KSDSFILE to MY.VSAM1.KSDSFILE VSAM file.

Listcat

LISTCAT command is used to get the catalog details of a VSAM dataset. Listcat command provides following information about VSAM datasets −
  • SMS Information
  • RLS Information
  • Volume Information
  • Sphere Information
  • Allocation Information
  • Dataset Attributes
LISTCAT ENTRY(vsam-file-name) ALL
In the above syntax, vsam-file-name is the VSAM dataset name for which we need all the information. ALL keyword is specified to get all catalog details.

Example

Following example shows how to fetch all the details using Listcat command for a VSAM dataset −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN DD  *
   LISTCAT ENTRY(MY.VSAM.KSDSFILE) 
   ALL 
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will show all the catalog details about MY.VSAM.KSDSFILE dataset.

Examine

Examine command is used to check the structural integrity of a key-sequenced data set cluster. It checks for index and data components and if any problem is found, the error messages are sent spool. You can check any of the IDCxxxxx messages.
EXAMINE NAME(vsam-ksds-name) -                                    
   INDEXTEST DATATEST -                  
   ERRORLIMIT(50)
In the above syntax, vsam-ksds-name is the VSAM dataset name for which we need to examine index and data part of VSAM cluster.

Example

Following example shows how to check whether Index and Data part of KSDS dataset are synchronized or not −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN DD  *
   EXAMINE NAME(MY.VSAM.KSDSFILE) -                                    
   INDEXTEST DATATEST -                  
   ERRORLIMIT(50)
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will show all problems with the VSAM data set in one of the IDCxxxxx messages in spool.

Verify

Verify command is used to check and fix VSAM files which have not been closed properly after an error. The command adds correct End-Of-Data records to the file.
VERIFY DS(vsam-file-name)                                  
In the above syntax, vsam-file-name is the VSAM dataset name for which we need to check the errors.

Example

Following example shows how to check and fix errors in VSAM dataset −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN DD  *
   VERIFY DS(MY.VSAM.KSDSFILE)                                  
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will fix the errors in VSAM dataset.

VSAM - LDS

LDS is known as Linear Data Set. Linear dataset is the only form of byte-stream dataset which is used in used in traditional operating system files. Linear datasets are rarely used. Following are the key features of LDS −
  • Linear datasets does not contain RDF's and CIDF's as it does not have any control information embedded in its CI.
  • Data that can be accessed as byte-addressable strings in virtual storage in Linear datasets.
  • Linear datasets has a control interval size of 4KBytes.
  • LDS is a kind of non-vsam file with some VSAM facilities like use of IDCAMS and VSAM specific information in the catalog.
  • DB2 is currently the biggest user of Linear Data Sets.
  • IDCAMS is used to define an LDS but it is accessed using a Data-In-Virtual (DIV) macro.
  • Linear dataset does not have concepts of records. All LDS bytes are data bytes.

Defining LDS cluster

The following syntax shows which parameters we can use while creating LDS cluster. The parameter description remains the same as mentioned in VSAM - Cluster module.
DEFINE CLUSTER (NAME(lds-file-name)      -
BLOCKS(number)                           -
VOLUMES(volume-serial)                   -
LINEAR                                   -
CISZ(number)                             -
[READPW(password)]                       -
[FOR(days)|TO(date)]                     -
[UPDATEPW(password)]                     -
[REUSE / NOREUSE])                       -
DATA                                     -
   (NAME(lds-file-name.data))  

Example

Following example shows how to create an LDS cluster in JCL using IDCAMS utility −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   DEFINE CLUSTER (NAME(MY.VSAM.LDSFILE)   -
   LINEAR                                  -
   TRACKS(1,1)                             -
   CISZ(4096) )                            -                            
   DATA (NAME(MY.VSAM.LDSFILE.DATA))      
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will create MY.VSAM.LDSFILE VSAM file.

Deleting LDS Cluster

LDS cluster is deleted using IDCAMS utility. DELETE command removes the entry of the VSAM cluster from the catalog and optionally removes the file, thereby freeing up the space occupied by the object.
DELETE data-set-name CLUSTER  
[ERASE / NOERASE] 
[FORCE / NOFORCE] 
[PURGE / NOPURGE] 
[SCRATCH / NOSCRATCH]
Above syntax shows which parameters we can use while deleting LDS cluster. The parameter description remains the same as mentioned in VSAM - Cluster module.

Example

Following example shows how to delete an LDS cluster in JCL using IDCAMS utility −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEPNAME EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   DELETE MY.VSAM.LDSFILE CLUSTER
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will delete MY.VSAM.LDSFILE VSAM Cluster.

VSAM - RRDS

RRDS is known as Relative Record Data Set. RRDS cluster is similar to an ESDS cluster. The only difference is that RRDS records are accessed by Relative Record Number (RRN), we must code NUMBERED inside the DEFINE CLUSTER command. Following are the key features of RRDS −
  • A Relative record dataset has records that are identified by the Relative Record Number (RRN), which is the sequence number relative to the first record.
  • RRDS allows access of records by number like record 1, record 2, and so on. This provides random access and assumes the application program has a way to get the desired record numbers.
  • The records in an RRDS dataset can be accessed sequentially, in relative record number order, or directly, by supplying the relative record number of the desired record.
  • The records in a RRDS dataset are stored in fixed length slots. Each record is referenced by the number of its slot, number can vary from 1 to the maximum number of records in the dataset.
  • Records in a RRDS can be written by inserting new record into an empty slot.
  • Records can be deleted from an RRDS cluster, thereby leaving an empty slot.
  • Applications which use fixed-length records or a record number with contextual meaning that can use RRDS datasets.
  • RRDS can be used in COBOL programs like any other file. We will specify the file name in JCL and we can use the KSDS file for processing inside program. In COBOL program specify file organization as RELATIVE and you can use any access mode (Sequential, Random or Dynamic) with RRDS dataset.

RRDS File Structure

Space is divided into fixed length slots in RRDS file structure. A slot can be either completely vacant or completely full. Thus, new records can be added to empty slots and existing records can be deleted from slots which are filled. We can access any record directly by giving Relative Record Number. Following example shows the basic structure of data file −

Data Component

Relative Record NumberRecord Field 1Record Field 2
1TutorialPoint
2MohtashimM.
3NishantMalik

Defining RRDS Cluster

The following syntax shows which parameters we can use while creating RRDS cluster.
The parameter description remains the same as mentioned in VSAM - Cluster module.
DEFINE CLUSTER (NAME(rrds-file-name)     -
BLOCKS(number)                           -
VOLUMES(volume-serial)                   -
NUMBERED                                 -
RECSZ(average maximum)                   -
[FREESPACE(CI-Percentage,CA-Percentage)] -
CISZ(number)                             -
[READPW(password)]                       -
[FOR(days)|TO(date)]                     -
[UPDATEPW(password)]                     -
[REUSE / NOREUSE])                       -
DATA                                     -
   (NAME(rrds-file-name.data))           

Example

Following example shows how to create an RRDS cluster in JCL using IDCAMS utility −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEP1  EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   DEFINE CLUSTER (NAME(MY.VSAM.RRDSFILE)  -
   NUMBERED                                -
   RECSZ(80 80)                            -
   TRACKS(1,1)                             -
   REUSE                                   - 
   FREESPACE(3 3) )                        -
   DATA (NAME(MY.VSAM.RRDSFILE.DATA))      
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will create MY.VSAM.RRDSFILE VSAM file.

Deleting RRDS Cluster

RRDS cluster is deleted using IDCAMS utility. DELETE command removes the entry of the VSAM cluster from the catalog and optionally removes the file, thereby freeing up the space occupied by the object.
DELETE data-set-name CLUSTER  
[ERASE / NOERASE] 
[FORCE / NOFORCE] 
[PURGE / NOPURGE] 
[SCRATCH / NOSCRATCH]
Above syntax shows which parameters we can use while deleting RRDS cluster. The parameter description remains the same as mentioned in VSAM - Cluster module.

Example

Following example shows how to delete an RRDS cluster in JCL using IDCAMS utility −
//SAMPLE JOB(TESTJCL,XXXXXX),CLASS = A,MSGCLASS = C
//STEPNAME EXEC PGM = IDCAMS
//SYSPRINT DD  SYSOUT = *
//SYSIN    DD  *
   DELETE MY.VSAM.RRDSFILE CLUSTER
/*
If you will execute the above JCL on Mainframes server. It should execute with MAXCC = 0 and it will delete MY.VSAM.RRDSFILE VSAM Cluster.