Wednesday, 25 April 2018

VSAM Tutorial


1.       VSAM Overview
Virtual Storage Access Method, File storage access method used in MVS, ZOS and OS/390 operating systems, used by COBOL. CICS to store & retrieve data, data set organization, organize & maintains data via a catalogue structure. Files can be read sequentially & randomly.
Benefits - Protects data, password/data set sharing both online & batch/Free Space reused automatically.
Limitation - Cannot be stored on TAPE volume only DASD space/requires many cylinders to store the data.

2.       VSAM Components -  VSAM Cluster/Control Area, Control Interval.

VSAM Cluster - Index Component, Data Component.

Control Interval(CI)
a)       Unit of I/O. Must be between 512 to 32K. Usually either 2K or 4K.
b)      Large   Interval increase performance for sequential processing while reverse is true for random access.
c)       Smallest unit of data transfer between a disk and the operating system. Consist of Logical Records, Control information fields, Free Space.
d)      Default Control Interval size is 4K bytes, can extend up to 32K bytes.
e)       Control information fields, Record Definition Field, RDF, 3 bytes long, tell how many adjacent record of same length.
f)       Control Interval Definition Field, CIDF, 4 bytes long, information about Control Interval.

Control Area
a)       CA size is calculated based on allocation type (Cylinder, tracks or records) and can be max of 1 cylinder.
b)      Size of VSAM file multiple of its CA.  Formed by putting together two or more Control Intervals. VSAM file multiple of its control area.


3.       VSAM CLUSTER  - Defined in JCL, uses IDCAMS utility (Access Method Services).

DEFINE CLUSTER (NAME(vsam-file-name), BLOCKS(number), VOLUMES (volume-serial),  INDEXED (for KSDS), NONINDEXED (For ESDS), NUMBERED (For RRDS), LINEAR (For LDS), RECSZ(average maximum), FREESPACE(CI-Percentage, CA-Percentage, Default Zero %, CISZ(Control Interval Size), KEYS(only KSDS file/range 1 to 255 bytes),  READPW(password of read level), UPDATEPW (password of update level), REUSE (reset to empty status without deleting and re-defining them), NOREUSE, DATA NAME(vsam-file-name.data), INDEX  NAME(vsam-file-name.index), CATALOG(catalog-name /password).


a)       Parameters CLUSTER level apply entire cluster. Parameters DATA or INDEX level apply data or index component.
b)      Deleting a Cluster - To delete VSAM file, VSAM cluster to be deleted using IDCAMS, DELETE command, remove of VSAM cluster from catalogue & optionally remove file. VSAM data set is not expired /use PURGE option.
c)       DELETE data-set-name CLUSTER / [ERASE / NOERASE] / [FORCE / NOFORCE] / [PURGE / NOPURGE] / [SCRATCH / NOSCRATCH].
d)      ERASE (override the ERASE attribute specified for object in catalogue) / FORCE/NOFORCE (to delete the SPACE and USERCATALOG even if they are not empty) / PURGE / NOPURGE (delete VSAM dataset if not expired) / SCRATCH/NOSCRATCH (used for non-vsam datasets like GDGs).               

4.       VSAM-ESDS   -
a)       Not (Random access, Deletion, Insertion).
b)      Yes (Rewrite, Length Change, Record can be of variable length).
c)       Entry Sequenced Data Set (behaves like sequential file organization), record inserted one after another/Relative Byte Address(RBA), if 80-byte record than RBA of 1st record (80) / RBA of 2nd record (160) / Record access sequentially by RBA.
d)      Deletion not possible, can marked inactive, records (fixed or Variable length)
e)       COBOL Program (file organization – Sequential, access mode=Sequential)

2.       VSAM-KSDS - 
a)       Random & Sequential retrieval & deletion. Record can be of variable length.
b)      Alternate Key (non-unique). Key Sequenced Data Set (index component/data component <- base cluster).
c)       Records within KSDS data set always kept sorted by key-field, stored in ascending, collating sequence by key, fixed length or variable length.
d)      COBOL program specify file organization as Indexed and access mode (Sequential, Random or Dynamic).

3.       VSAM-RRDS
a)       Random & Sequential insertion , updation & deletion. Does not have control field in control interval.  
b)      Fixed length slot. Relative Record Data Set, Relative Record Number (RRN/sequence number relative to the first record).
c)       Random access by record number, Fixed length only, Records can be deleted.
d)      COBOL programs - File organization as RELATIVE, Access mode (Sequential, Random or Dynamic).

4.       VSAM-LDS
a)       Similar control information. ESDS without Linear Data Set, not contain RDF's and CIDF's as it does not have any control information embedded in its CI, control interval size of 4KBytes.

5.       VSAM - Commands  - IDCAMS
a)       DEFINE – Create VSAM Object.
b)      EXPORT / IMPORT – Loading / Unloading.
c)       ALTER - Modify VSAM file attributes / ALTER  MY.VSAM.KSDSFILE / ADDVOLUMES(2) / FREESPACE(6 6) / KEYS(10 2) / BUFFERSPACE(size), EMPTY / NOEMPTY , ERASE / NOERASE , NEWNAME(new-name) , RECORDSIZE(average maximum)] / SCRATCH / NOSCRATCH , TO(date) / FOR(days) , UPGRADE / NOUPGRADE
d)      REPRO – COPYING / Load data into VSAM dataset/copy data from one VSAM data set to another. REPRO INFILE(IN) / OUTFILE(OUT)
e)       PRINT – List Dataset.
f)       LISTCATList catalouge information / SMS/ RLS / Volume /Sphere / Allocation / Dataset Attributes / LISTCAT ENTRY(MY.VSAM.KSDSFILE)
g)      EXAMINE - To check the structural integrity of a key-sequenced data set cluster/to check whether Index and Data part of KSDS dataset are synchronized or not. EXAMINE NAME(MY.VSAM.KSDSFILE) -                                    INDEXTEST DATATEST / ERRORLIMIT(50).
h)      VERIFY - Is used to check and fix VSAM files which have not been closed properly after an error. VERIFY DS (MY.VSAM.KSDSFILE).                    
i)        DELETE -  Delete VSAM object.           

6.       VSAM - Alternate Index - Additional index created for KSDS/ESDS datasets beside primary index/ provides access to records by using more than one key/ key of alternate index can be a non-unique key, it can have duplicates. Steps - Define Alternate Index/Define Path/Building Index.
Define Alternate Index
DEFINE AIX (NAME(MY.VSAM.KSDSAIX)
RELATE(MY.VSAM.KSDSFILE) <- VSAM cluster for which alternate index is created.             CISZ(4096)   (Note – FREESPACE, ESDS not required as cannot insert record also rewrite than same length)
FREESPACE(20,20) <- CI % (% of each CI to be left alone) / CA % (% of CI to be left empty in each CA)
KEYS(20,7) / NONUNIQUEKEY <- duplicate may exists ( Unique Key – no duplicate) UPGRADE / RECORDSIZE(80,80)       
DATA(NAME(MY.VSAM.KSDSAIX.DATA)) INDEX(NAME(MY.VSAM.KSDSAIX.INDEX))

Define Path - It will create path between Alternate Index to the base cluster.
DEFINE PATH  NAME(MY.VSAM.KSDSAIX.PATH)
PATHENTRY(MY.VSAM.KSDSAIX)) <- Alternate index to which path is related.

Building Index - BLDINDEX reads all the records in the VSAM base cluster and extracts the data needed to build the alternate index.                                                                                                                             BLDINDEX / INDATASET(MY.VSAM.KSDSFILE)
OUTDATASET(MY.VSAM.KSDSAIX))
7.       VSAM - Catalogue - 
a)       Catalogue maintains the unit and volume where dataset resides, used for retrieval of datasets.
b)      Non-VSAM datasets create a catalogue entry by means of Disposition Parameter in JCL.
c)       VSAM datasets maintains its own catalogue in form of KSDS cluster.
d)      Master Catalogue - A file which contains entries about system datasets and VSAM datasets, only one master catalogue in any system. Functions -  Password Authorization for files., Enhancing the Security, VSAM access for files, Space Management of file, Location of file, Free Space available in file.
e)       User Catalogue - Can be many in system, Master catalogue points to user catalogue which points to all files.

8.       Data Space
a)       An area of the direct access storage device that is exclusively allocated for VSAM use, must be created before creating VSAM clusters, hold the user catalogue entries.
b)      Unique Clusters, Sub-allocated Clusters, Non-VSAM datasets - resides on both tape and direct access storage. 
9.       VSAM - File Status
a)       02 - Non-Unique Alternate Index duplicate key found.
b)      04 - Invalid fixed length record.
c)       20 - End of File encountered.
d)      20 - Invalid Key for VSAM KSDS or RRDS.
e)       22 – Duplicate Key.
f)       30 - Record not found or File not found.
g)      30 - Permanent I/O Error.
h)      90 – VSAM Logic Error
i)        91 - Password or authorization failed.
j)        93 - Logic Error.
k)      93 - Resources are not available
l)        94 – No file position indicator for sequential request


10.   SHAREOPTS – Parameter in DEFINE, how an object can be shared among users.

SHAREOPTS (a,b)  / a – cross share region option / b - cross system option – two or more jobs share file.

11.   Sequence Set – Part of index that points to CA & CI of records being accessed.
Cluster -  Combination of index, sequence set & data portion of dataset.
Upgrade SetList of all AIXes that VSAM must maintain for a specific base cluster, if base cluster updated they also upadted.

12.   COPY from one file to another(Loading) – Loading empty cluster with data records. REPRO & IEBGENER.
REPRO INFILE (DD1) OUTFILE (DD2) SKIP (900) COUNT (700) / FROM ADDRESS / TO ADDRESS / FROM NUMBER / TO NUMBER / FROM KEY / TO KEY.
NOTE For KSDS sorting of input file required for ESDS & RRDS sorting not required.


No comments:

Post a Comment