Você está na página 1de 205

VIRTUAL STORAGE ACCESS METHOD (VSAM) Version 2.

VSAM

VSAM
VSAM means virtual storage access method
High performance access method and dataset organization designed specifically for VS environment. It resides in virtual storage Organizes and maintains data via a cataloged structure

VSAM

VSAM HISTORY
A] Standard VSAM. Only ESDS & KSDS

B] A+RRDS & AIX, Catld. Facility Enhanced VSAM

C] DF/EF VSAM ICF Cataloging

MVS/XA Ver. 1 Changes were compatible with DF/EF VSAM MVS/XA Ver. 2 LDS were added

VSAM

FEATURES OF VSAM

One coherent file storage system

(Stores and Retrieves Data)


Not a database management system

Not a programming language


Not a communication system VSAM has no equivalent for a PDS Introduction by IBM in 1973 DFP/VSAM Ver 1 in 1989

VSAM

ADVANTAGES OF VSAM
Protection of Data Cross-system (MVS & VSE) Compatibility Device Independence (Access Via Catalog) IDCAMS commands can be included in JCL to handle VSAM Used by CICS (OLTP) to store and retrieve data VSCOBOL II/PL-I/ASSMB. Long can access VSAM dataset

VSAM

TYPES OF VSAM DATASETS


Based on the way in which we store and access the records:

KSDS
ESDS RRDS LDS

Key Sequenced dataset


Entry Sequenced dataset Relative record dataset Linear dataset

All the four methods contain a data area in which data records are placed For KSDS, there is an index area in addition to data area
VSAM 6

CLUSTERS
VSAM files are often called clusters

A cluster is the set of catalog entries that represent a file A cluster consists of one or two components, a data component, which contains the actual records of a file, and for a KSDS only, an index component, which contains the indexes used to access records in the data component.
Must be defined for each dataset
VSAM 7

CLUSTERS
I. KSDS CLUSTER
INDEX COMPONENT

DATA COMPONENT

II.

ESDS, RRDS Cluster


DATA COMPONENT
VSAM 8

VSAM RECORDS
Can be fixed or variable length Records can also be spanned A Linear dataset has no records

Note : LDS - Linear dataset


(Newest Type) It is just a long string of bytes divided into 4k pages. Accessed by Relative Byte Address
VSAM 9

CONTROL INTERVAL

A control interval is the unit of data VSAM transfers between virtual and disk storage

Is similar to the concept of blocking in non-VSAM files.


Generally contains more than one 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.

Fixed length, selected at file creation time


For index, the size of CI is 512, 1K, 2K or 4K bytes
VSAM 10

CONTROL INTERVAL
A control Interval contains
Logical Records Control Information Free Space Control Interval Descriptor Field(CIDF) contains information about available space with in CI. Record Descriptor Field (RDF) contains the length of each record and how many adjacent records are of the same length. One RDF for each record in variable length files Only two RDFs per CI in case of fixed length files VSAM
11

RDF is of 3 bytes long

CONTROL INTERVAL
Logical Record Area (LRA) Freespace

Logical Record Area (LRA)

Unused Control Space Field

Rec 1

Rec 2

Rec 3

FSPS

U S

CF

<------------------- CISZ ------------------------> CF

Record definition Field RDF <---3 bytes--->

Control Interval Definition Field

CIDF <---4 bytes---->


VSAM 12

CONTROL AREA(CA)
CONTROL INTERVAL CONTROL INTERVAL CONTROL INTERVAL CONTROL INTERVAL

VSAM groups control intervals into contiguous, fixed length areas of storage called control areas.
Maximum of 1 cylinder

Can specify freespace in CA


Number of CI/CA is fixed by VSAM.
VSAM 13

SPANNED RECORDS
Spanned records are records larger than CI size. So one spanned record is stored in several CIs Each CI that contains a record segment of a spanned record has two RDFs. The right RDF gives the length of the segment and the left gives the update number of the segment

Can only be used in ESDS and KSDS


A CI that contains a record segment of a spanned record contains no other data

VSAM

14

ESDS
ESDS is a sequential dataset:

Records are retrieved in the order in which they are written to the dataset Additions are made always at the end of the file Records can be retrieved randomly 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 High-Used-RBA (HURBA)points to the end of the data High-Allocated-RBA (HARBA)is the highest byte that can be VSAM 15 used

HURBA AND HARBA


VSAM cluster
Data space allocated but empty Data space loaded with records

HARBA

HURBA

VSAM

16

VSAM DATASET STRUCTURE

VSAM

17

KSDS
It is similar in many ways to ISAM file, with better index structure and improved overflow handling Can be processed sequentially and randomly

A KSDS consists of two components:


Index component Data component

VSAM

18

DATA Component
Control Areas

I II III

IV V VI

Data Component

Control Intervals
VSAM 19

INDEX COMPONENT
Index Component Index Set Sequence Set

Points to control Intervals * There will be 1 record per CI (lower level of Indexing)
Points to Sequence Set * There will be one record per Sequence Set (higher level of indexing)
VSAM 20

KSDS STRUCTURE
Index Set and control areas for a KSDS
Key Ptr Key Ptr Index Set Index Compone nt Key Ptr Key Data Component

Sequence Set 1
Ptr Key Ptr Key

Sequence Set 2 Ptr Key Ptr Key Ptr

Control Areas

CI1 CI2 Control Area 1

CI3

CI3 CI4 Control Area 2

CI5

VSAM

21

KSDS STRUCTURE
Index Set Record
Binary Zeroes Hdr 48424 (SS-REC-1) Sequence Set Records Hdr 48011 (CI - 1) SS-Rec-1 48303 (CI - 2) 48424 (CI - 3) Hdr 91761 (CI - A) SS-Rec-2 95651 (CI - B) 95651 (SS-REC-2)

Horizontal pointers

VSAM

22

KSDS STRUCTURE
CI-1 CI-2 48012 CI-3 48304 48013 48416 FSPC 48424 FSPC FSPC
Data Records

44012

44039

44136

FSPC

CONTROL AREA 1 CI-A CI-B CI-C

48525 91762

90064 92373 FREE SPACE

90403 95651

FSPC FSPC

CONTROL AREA 2

VSAM

23

SEQUENCE SET OF KSDS


Key C Ptr 100 Key F Control Interval 1 Rec A Rec B Rec C Ptr 300 Key I Ptr 200 Key L Ptr 400

100

FSPC

CF

200
Rec G

Control Interval 2 Rec H Control Interval 3

Rec I

FSPC

CF

300
Rec D

Rec E

FSPC

CF

400
Rec J

Control Interval 4

Rec K

Rec L

FSPC

CF

VSAM

24

CONTROL INTERVAL SPLIT


INSERTION & DELETION OF RECORDS
Before Inserting New Record U S

Record 1

Record 2

Record 3

FSPC

CF

After Inserting Record 1 Record 2 New Record Record 3 FSPC U S CF

VSAM

25

CONTROL INTERVAL SPLIT


INSERTION & DELETION OF RECORDS Before Deletion:
Record 1 Record 2 New Record To Delete

Record 3

FSPC

U S

CF

After Deletion:
Record 1 Record 2 Record 3 FSPC

U S

CF

VSAM

26

CONTROL INTERVAL SPLIT


Before Control Interval Split
New Record Full Control Interval
Record 5 U S CF

Record 1

Record 2

Record 3

Record 4

FSPC

U S

CF

VSAM

Empty Control Interval

27

CONTROL INTERVAL SPLIT


After Control Interval Split
Record 1 Record 2 New Record Record 5 FSPC U S U S CF

Record 3

Record 4

FSPC

CF

VSAM

28

CONTROL INTERVAL SPLIT


Before Control Interval Split

Sequence set

K
Record C

100

Data Component

Record A
100 Record J 200

Record B

Record F

Record G

U S

CF

Record K

FSPC

U S

CF

FSPC

U S

CF

VSAM

29

CONTROL INTERVAL SPLIT


Sequence set
0 Data Component Record A 100 Record J 200 Record F Record G FSPC U S CF Record K FSPC U S Record B Record C FSPC U S

200

100

CF

CF

VSAM

30

CONTROL AREA SPLIT


Seq Set 060 001 180 012 190 018 025 050
DATA AREA

After adding 030 and 110


02 001 061 181 06 012 100 190 18 018 110 19

061
181

100
190

145

170

145

170

025
Seq Set 024 001 025 050 012 030 018 050
DATA AREA

030

050

110 111 181 061

180 145 190 100

190 170

110

CA split after adding 111

VSAM

31

IDCAMS COMMANDS

VSAM

32

IDCAMS
How VSAM is used by Application Programmers: Write IDCAMS utility program commands & execute them to create VSAM dataset Write application programs (in COBOL, PL/I Assembler Language, in CICS) Using the statements provided by these languages to write and read VSAM datasets Use IDCAMS utility program commands to list, examine, print, tune, backup, and export/import VSAM datasets

VSAM

33

IDCAMS
Can be invoked In batch mode with JCL Interactively with TSO commands With JCL can print/display program and sys messages and return codes can code multiple commands per job can specify IF-THEN-ELSE logic to execute command/s selectively based on condition codes LASTCC, MAXCC
VSAM 34

IDCAMS
Commands FUNCTIONAL Commands DEFINE BUILDINDEX REPRO PRINT DELETE VERIFY ALTER LISTCAT MODAL Commands IF-THEN-ELSE SET
VSAM 35

IDCAMS
// 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. /* //
VSAM 36

IDCAMS
Optionally: // JOBCAT DD DSN = catalogname, DISP= SHR // STEPCAT DD DSN = catalogname, DISP = SHR

may be used to indicate catalog names for a job/step, in which concerned dataset may be cataloged

VSAM

37

IDCAMS
FORMAT OF IDCAMS COMMAND verb object (parameters) Example : DEFINE CLUSTER NAME(DA0001T.LIB.KSDS.CLUSTER) CYLINDERS(5, 1) VOLUMES (BS3013) INDEXED ) Comment /* comment */
VSAM

38

IDCAMS RETURN CODES


CONDITION CODE: 0 : command executed with no errors 4 : warning - execution may go successful 8 : serious error - execution may fail 12 : serious error - execution impossible 16 : fatal error - job step terminates condition codes are stored in LASTCC/MAXCC both LASTCC and MAXCC contain zero by default at the start of IDCAMS execution
VSAM 39

IF Syntax

IF LASTCC/MAXCC comparand VALUE THEN command ELSE command

VSAM

40

IF Syntax

Comparands are : EQ/NE/GT/LT/GE/LE


Hyphen is the continuation character Comment is assumed as Null statement

ELSE is optional

VSAM

41

IF Syntax Example
.........
REPRO INFILE (INDD) OUTFILE (OUTDD) ................ IF LASTCC EQ 0 THEN PRINT OUTFILE (INDD) ELSE PRINT INFILE (OUTDD)

VSAM

42

USE OF DO/END

IF MAXCC LT 4 THEN DO /* COMMENT */ Command Command END ELSE Command

VSAM

43

SET COMMAND
LASTCC and MAXCC can be set to a value between 0-16

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
DEFINE CLUSTER IF LASTCC > 0 THEN SET MAXCC = 16 ELSE REPRO

e.g.
-

VSAM

44

DEFINING A CLUSTER

VSAM

45

The DEFINE CLUSTER Command This command tells IDCAMS to create and name a VSAM cluster. Format: Abbreviation: Used for: DEFINE CLUSTER (NAME (cluster name) parameters) DEF CL ESDS, KSDS, RRDS

Default:
Example:

None
DEFINE CLUSTER (NAME (DA0004T.LIB.KSDS.CLUSTER)) DATA (NAME (DA0004T.LIB.KSDS.DATA)) INDEX (NAME (DA0004T.LIB.KSDS.INDEX)) -

VSAM

46

The NAME parameter This is a required positional parameter. Format: (NAME (cluster name) cluster name: The name to be assigned to the cluster. None ESDS, KSDS, RRDS Yes

Abbreviation: Used for: Default:

Example:

DEFINE CLUSTER (NAME (DA0004T.LIB.KSDS.CLUSTER)) DATA (NAME (DA0004T.LIB.KSDS.DATA)) INDEX (NAME (DA0004T.LIB.KSDS.INDEX))

VSAM

47

The DATA parameter The DATA parameter tells IDCAMS that you going to create a separate data component. DATA is optional, but if coded must follow all of the parameters that apply to the cluster as a whole. Format: DATA (NAME (data name) parameters) NAME parameter is optional, but you should usually code it. If coded, it must the first DATA parameter. data name: The name you choose to name the data component.

Abbreviation:
Used for: Required: Default: Example:

None
ESDS, KSDS, RRDS No None DATA (NAME (DA0004T.LIB.KSDS.DATA)) INDEX (NAME (DA0004T.LIB.KSDS.INDEX))

VSAM

48

The INDEX parameter


The INDEX parameter creates a separate index component. INDEX is optional, but if coded must follow all of the parameters that apply only to the data component.

Format:

INDEX (NAME (index name) parameters)


index name: The name you choose for the index component.

Abbreviation: Used for: Required:

IX KSDS No

Default:
Example:

None
INDEX (NAME (DA0004T.LIB.KSDS.INDEX))

VSAM

49

The SPACE ALLOCATION parameter The space allocation parameter specifies space allocation values in the units shown below: Format: Code only one of the following: CYLINDERS (primary secondary) or TRACKS (primary secondary) or RECORDS (primary secondary) or KILOBYTES (primary secondary) or MEGABYTES (primary secondary) CYL, TRK, REC, KB, MB KSDS, ESDS, RRDS Yes None

Abbreviation: Used for: Required: Default:

Example:

CYLINDERS (10 4) RECORDS (400 500)

VSAM

50

Remark: It is best to apply space allocation to the entire cluster or to the data component, because VSAM then calculates the amount of space needed for the index, generally the most efficient technique; for example:

DEFINE CLUSTER (NAME (DA0004T.LIB.KSDS.CLUSTER) CYLINDERS (5 3) ) DATA (NAME (DA0004T.LIB.KSDS.DATA)) INDEX (NAME (DA0004T.LIB.KSDS.INDEX))
Or DEFINE CLUSTER (NAME (DA0004T.LIB.KSDS.CLUSTER) DATA (NAME (DA0004T.LIB.KSDS.DATA) CYLINDERS (5 3) ) INDEX (NAME (DA0004T.LIB.KSDS.INDEX))

VSAM

51

DEFINE CLUSTER
Primary : Allocated once when the dataset is created Secondary : Allocated a maximum of 122 times as needed during the life of the dataset

VSAM

52

The VOLUMES parameter The VOLUMES parameter assigns one or more storage volumes to your dataset. Multiple volumes must be of the same device type (3390, for example). Format: VOLUMES (vol ser) or VOLUMES (vol ser ........ vol ser) vol ser: The six-digit volume serial number of a volume. VOL KSDS, ESDS, RRDS Yes None VOLUMES (BS3011) VOLUMES (BS3011 BS3040 BS3042)

Abbreviation: Used for: Required: Default: Example:

VSAM

53

DEFINE CLUSTER
You can store the data and index on separate volumes and this may provide a performance advantage for large dataset.

VSAM

54

The RECORDSIZE parameter This parameter tells VSAM what size records to expect. The avg and max are average and maximum values for variable-length records If records are of fixed length, avg and max should be the same.

Format:

RECORDSIZE (avg max) avg : Average length of records max : Maximum length of records
RECSZ KSDS, ESDS, RRDS No RECORDSIZE (4086 4086) RECORDSIZE (80 80) [Fixed Length records] RECORDSIZE (80 120) [Variable Length records]

Abbreviation: Used for: Required: Default: Example:

RECORDSIZE can be assigned at the cluster or data level. For a KSDS, VSAM calculates the RECORDSIZE of the index based on the KEYS parameter.

VSAM

55

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 key offset: Offset in bytes of the primary key with records (0 to n)

Abbreviation:
Used for: Required: Default: Example:

None
KSDS No KEYS (64 1) KEYS (8 0)

VSAM records begin in position zero

VSAM

56

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 NONINDEXED: - Specifies an ESDS. No index is created and records are accessed sequentially or by relative byte address NUMBERED: - Specifies an RRDS LINEAR: - Specifies a LINEAR dataset

Abbreviation: Used for: Required: Default: Example:

IXD| NIXD | NUMD KSDS, ESDS, RRDS Yes INDEXED INDEXED NONINDEXED NUMBERED

VSAM

57

//DA0001TA JOB LA2719, PCS,MSGLEVEL=(1,1), MGCLASS=A,NOTIFY=DA0001T // * Define Cluster for ESDS VSAM Dataset //STEP1 EXEC PGM=IDCAMS // SYSPRINT DD SYSOUT=* // SYSIN DD * DEFINE CLUSTER (NAME (DA0001T.LIB.ESDS.CLUSTER) NONSPANNED REUSE NOERASE VOLUMES (BS3005) RECORDSIZE (80 80) RECORDS (30 50) CISZ (4096) SHR (1 3) ) DATA (NAME (DA0001T.LIB.KSDS.DATA)) /* //

VSAM

58

//DA0001TA JOB LA2719, PCS,MSGLEVEL=(1,1), MGCLASS=A,NOTIFY=DA0001T // * Define Cluster for KSDS VSAM Dataset //STEP1 EXEC PGM=IDCAMS // SYSPRINT DD SYSOUT=* // SYSIN DD * DEFINE CLUSTER (NAME (DA0001T.LIB.KSDS.CLUSTER) INDEXED KEYS (4 0) FSPC (10 20) NONSPANNED NOREUSE NOERASE VOLUMES (BS3005) SHR (1 3) ) DATA (NAME (DA0001T.LIB.KSDS.DATA) RECORDSIZE (80 80) RECORDS (30 50) CISZ (4096) ) INDEX (NAME (DA0001T.LIB.KSDS.INDEX)) VSAM /* //

59

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

Format:

CONTROLINTERVALSIZE (bytes)
bytes: The size of control interval in bytes. It should be a multiple of 512 or 2048 bytes, depending upon the type of catalog (ICF or VSAM) and the length of the record. VSAM rounds the CISZ value up to the next highest multiple of 512 Or 2048 if necessary.

Abbreviation: Used for: Required: Default: Example:

CISZ KSDS, ESDS, RRDS No, because of the default Calculated by VSAM CISZ (4096)

Note: If omitted VSAM calculates CISZ based on record size and other control information

VSAM

60

The FREESPACE parameter

Format:

FREESPACE (ci% ca%) ci%: - Percentage of control interval to leave free for expansion ca%: - Percentage of control area to leave free for expansion

Abbreviation: Used for: Required: Default: Example:

FSPC KSDS No, because of default. FREESPACE (0 0) FREESPACE (20 10) FREESPACE (20) FREESPACE (0 30)

Control interval only Control area only

VSAM

61

DEFINE CLUSTER
This FREESPACE parameter, which applies to the KSDS, allocates some percentage of control interval and control area for planned freespace. This freespace can be used for adding new records or for expanding existing variable records.

VSAM

62

DEFINE CLUSTER
Too much freespace results in more i/o, especially when doing sequential processing. Too little results in excessive control interval and control area split

VSAM

63

The BUFFERSPACE parameter Buffer space represents the amount of storage (in bytes) required to process the contents of a minimum of one control intervals worth of data. Format: BUFFERSPACE (bytes) Bytes: The number of bytes to allocate to each buffer.

Abbreviation:
Used for: Required: Default: buffer for KSDS. Example:

BUFSP
KSDS, ESDS, RRDS No, because of default. Two data buffers for all types of datasets, plus one additional index

BUFSP (8704)

VSAM

64

The following example shows the AMP parameter specifying additional data buffers to accommodate sequential and random processing.

//DD1
//DD1 //

DD
DD

DSN=DA0001T.LIB.KSDS.CLUSTER,DISP=SHR,AMP=(BUFND=10)
DSN=DA0001T.LIB.KSDS.CLUSTER,DISP=OLD, AMP=(BUFND=10,BUFNI=3)

VSAM

65

The RECOVERY | SPEED parameter These parameters are mutually exclusive. RECOVERY, the default, reformats the control areas during your initial dataset load, so that you can restart the job if it abends for some reason. The disadvantage of this parameter is that programmer has to write recovery routine to restart the job. SPEED is faster and does not pre-format the control areas. You must reload the dataset from the beginning if the job fails during initial loading.

Format:
Abbreviation: Used for: Required: Default: Example:

RECOVERY | SPEED
RCVY | None KSDS, ESDS, RRDS No, because of default. RECOVERY RECOVERY SPEED

VSAM

66

The SPANNED | NONSPANNED 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 is unusable by other records, even if they fit logically in the unused bytes. [NONSPANNED is the default] and it means that records cannot span control intervals Format: Abbreviation: Used for: Required: Default: Example: SPANNED | NONSPANNED SPND | NSPND KSDS, ESDS No, because of default. NONSPANNED NONSPANNED SPANNED

VSAM

67

The REUSE | NOREUSE parameter The REUSE parameter specifies that the cluster can be opened a second time as a reusable cluster. NOREUSE is the default, and specifies the cluster as non-reusable. Format: Abbreviation: REUSE | NOREUSE RUS | UNRUS

Used for:
Required: Default: Example:

KSDS, ESDS, RRDS


No, because of default. NOREUSE REUSE NOREUSE

VSAM

68

DEFINE CLUSTER
Some application call for temporary dataset or workfile that must be created, used and deleted each time the application run. To simplify these applications, VSAM lets you create reusable files.

VSAM

69

The SHAREOPTIONS parameter

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 among different users.

Format: SHAREOPTIONS (cr value cs value) cr value : Specifies the value for cross region sharing. Cross region sharing is defined as different jobs running on the same system using Global Resource Serialization (GRS), a resource control facility available only under MVS/XA and ESA cs value : Specifies the value for cross system sharing means different jobs running on different system in a NONGRS environment Value 1 multiple read OR single write 2 multiple read AND single write 3 multiple read AND multiple write Abbreviation: Used for: Required: Default: Example: SHR KSDS, ESDS, RRDS No, because of default. SHR (1 3) SHR (1) SHR (2 3)

VSAM

70

DEFINE CLUSTER
cr value : Specifies the value for cross region sharing. Cross region sharing is defined as different jobs running on the same system using Global Resource Serialization(GRS), a resource control facility available only under MVS/XA and ESA cs value : Specifies the value for cross system sharing means different jobs running on different system in a NONGRS environment

VSAM

71

The ERASE | NOERASE parameter The ERASE parameter instructs VSAM to overwrite sensitive data component with binary zeros when the cluster is deleted. NOERASE is the default and means that the deleted cluster is not to be overwritten with binary zeros. Format: Abbreviation: Used for: Required: Default: Example: ERASE | NOERASE ERAS | NERAS KSDS, ESDS, RRDS No, because of default. NOERASE NOERASE ERASE

VSAM

72

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 package like RACF. Format: MASTERPW (password) Allows the highest level of access to all cluster components, including DELETE and ALTER authority. UPDATEPW (password) Allows write authority to the cluster. READPW (password) Allows read-only access to the cluster. Abbreviation: Used for: Required: MRPW, UPDPW, RDPW KSDS, ESDS, RRDS No

Default: Example:

None MASTERPW (PATNI)VSAM UPDATEPW (XYZ) or READPW (ABC)

73

LISTCAT

VSAM

74

LISTCAT
LISTCATs basic function is to list information about VSAM and NONVSAM objects

VSAM

75

Format:

LISTCAT ENTRIES (entry name) options

LISTCAT LEVEL (level) options entry name: The generic name of each entry to list. level: The level of qualification at which to begin listing. Abbreviation: LISTC ENT LIST LVL KSDS, ESDS, RRDS and non-VSAM No, because of default. All entries are listed if just LISTCAT is coded LISTCAT ENTRIES (da0001t.lib.ksds.cluster)

Used for: Required: Default: Example:

LISTCAT LEVEL (da0001t.lib.ksds. *)

VSAM

76

Options are: HISTORY or HIST VOLUME or VOL ALLOCATION or ALLOC ALL

Examples: LISTCAT ENTRIES (DA0001T.VSAM.KSDS.CLUSTER) CLUSTER ALL -

VSAM

77

//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTCAT ENTRIES (DA0001T.LIB.KSDS.CLUSTER) ALL /* Example 4.2 LISTCAT Example LISTCAT LVL (DA0001T.*.KSDS) ALL

VSAM

78

LISTCAT
Example 1 : (in JCL) //STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT=* //SYSIN DD * LISTCAT ENTRIES(DA0001T.LIB.KSDS.CLUSTER) ALL /* Example 2 : (from TSO prompt) LISTCAT ENTRIES (LIB.KSDS.CLUSTER) ALL

VSAM

79

ALTERNATE INDEXES

VSAM

80

ALTERNATE INDEX
other fields of a record

Book No.
1 2 3 4 5 6 7 8 9 10 11 12 ... ... ... ... ... ... ... ... ... ... ... ...

Author
x y x z t x q z y b c t Data set having Book No as a Primary Key

VSAM

81

ALTERNATE INDEX
BASE CLUSTER (KSDS)
3 6 9 12 Index Component

1 ... x

2 ... y

3 ... x

us

C F C F C F C F

Data Component

4 ... Z
7 ... q 10 .. .b

5 ... t
8 ... z 11 ... c

6 ... x
9 ... y 12 ... t

us
us us

VSAM

82

ALTERNATE INDEX
Author Book No.

b
c

...
...

10
11

q
t x y z

...
... ... ... ...

7
5, 12 1, 3, 6 2, 9 4, 8

VSAM

83

ALTERNATE INDEX CLUSTER


FOR NON UNIQUE ALTERNATE KEY
X

Index Component

b 10

c 11

q 7

C F C F C F

12

Data Component

VSAM

84

ALTERNATE INDEX
Key Ptr Key Ptr
Index Component :

Control Interval 1

Hdr

Key

Ptr1

Ptr2

Ptr3

Hdr

Key Ptr 4

FSPC

U S

CF

Control Interval 2

Hdr

Key

Ptr9

Ptr10

Ptr11

Hdr

Key

Ptr12

FSPC

U S

CF

The pointers point to a control interval in the data component of the base cluster that contains the record
VSAM 85

ORGANIZATION OF AN ALTERNATE INDEX


KSDS :
HOUSE KEEPING 5

DATA COMPONENT :
ALT-INDX-KEY SOC_SEC_NUM 9 PRM-KEY EMP_NUM 8

RECORDSIZE(22 22) <-------------- PRM_KEY (S) -------------> HK 5 AUTH-LAST_NAME 25 LIB_NUM 8 RECORDSIZE(54 110) LIB_NUM 8 LIB_NUM 8

ESDS :

- Occupies Less Space - RBA-Access is Faster HK 5 TIMESTAMP 12 RBA 4

VSAM

86

ALTERNATE INDEX(S)
May be defined on one or more than one Alternate Key(s) i.e. Field(s) other than primary key Alternate Key(s) need not be unique Separate cluster is defined A path is also defined for connection between base cluster and alternate index cluster Each ALT. Index itself is a KSDS Consists of both data component and an index component Alternate Index upgradation is by default For ESDS, Vsam builds ALT. index by mapping one field to the records RBA.
VSAM 87

ALTERNATE INDEX(S)
Supported only for assembler or online CICS

Do not support a reusable base cluster


Greatly reduce data redundancy May lead to performance Degradation Build the ALT. index after the base cluster has been both defined and loaded with atleast 1 record.
VSAM 88

Creating an alternate index requires three separate steps: Define the alternate index using the IDCAMS DEFINE AIX command Define an alternate index path using the IDCAMS DEFINE PATH command Build the alternate index and populate it with records using the IDCAMS BLDINDEX command The above three steps need to repeated for each alternate index built over the base cluster.

VSAM

89

STEP 1: Defining the Alternate Index The first step in creating an alternate index is to define with the DEFINE AIX command The DEFINE ALTERNATEINDEX Command
Define the Alternate Index Cluster using the IDCAMS DEFINE AIX command. Format: Abbreviation: Use: Required: Default: Example: DEFINE ALTERNATEINDEX DEF AIX Alternate index over a KSDS, ESDS Yes, if an alternate index is defined. None DEFINE AIX

VSAM

90

The NAME parameter It is mandatory parameter that names the alternate index. Format: Abbreviation: Use: Required: Default: Example: NAME (index cluster name) None Alternate index over a KSDS, ESDS Yes, if an alternate index is defined. None NAME (da0001t.lib.ksds.ename.aix)

VSAM

91

The VOLUMES parameter The VOLUMES parameter specifies the volume (or volumes) where the alternate index is to be stored.

Format:

VOLUMES (vol ser) or VOLUMES (vol ser ... vol ser) Vol ser: The six-digit volume serial number of a volume.
VOL

Abbreviation:

Used for:
Required: Default: Example:

Alternate index over a KSDS, ESDS.


Yes, if an alternate index is defined. None VOLUMES (BS3011) VOLUMES (BS3011 BS3040 BS3042)

VSAM

92

The RELATE parameter This parameter establishes the relationship between the base cluster and the alternate index via the use of the base cluster name. It is unique to the DEFINE AIX command, and it is required. Format: Abbreviation: Use: Required: Default: RELATE (base cluster name) REL Alternate index over a KSDS, ESDS Yes, if an alternate index is defined. None

Example:

RELATE (da0001t.lib.ksds.cluster)

VSAM

93

The UPGRADE parameter Format: Abbreviation: Use: Required: Default: Example: UPGRADE | NOUPGRADE UPG | NUPG Alternate index over a KSDS, ESDS No, because of default. UPGRADE UPGRADE NOUPGRADE

VSAM

94

Changes made to the base cluster would be reflected automatically in all the alternates indexes provided you have specified UPGRADE option in each of the base clusters alternate indexes (DEFINE AIX command). For this to happen the application program has to open the base cluster The set of alternate indexes VSAM updates automatically is called Upgrade set
VSAM 95

The KEYS parameter This parameter defines the length and offset of the alternate index key. Format: KEYS (length offset) length: length in bytes of the alternate key offset: The offset is the keys displacement (in bytes) from the beginning of the record. None Alternate index over a KSDS, ESDS. No, because of the default. KEYS (64 0) KEYS (30 4)

Abbreviation: Used for: Required: Default: Example:

VSAM

96

The RECORDSIZE parameter

The RECORDSIZE parameter specifies the average and maximum of each alternate index record.
Format: Abbreviation: Use: Required: RECORDSIZE (avg max) RECSZ Alternate index over a KSDS, ESDS. No

Default:
Example:

RECORDSIZE (4086 32600)


RECORDSIZE (80 120)

VSAM

97

ORGANIZATION OF AN ALTERNATE INDEX


KSDS :
HOUSE KEEPING 5

DATA COMPONENT :
ALT-INDX-KEY SOC_SEC_NUM 9 PRM-KEY EMP_NUM 8

RECORDSIZE(22 22) <-------------- PRM_KEY (S) -------------> HK 5 AUTH-LAST_NAME 25 LIB_NUM 8 RECORDSIZE(54 110) LIB_NUM 8 LIB_NUM 8

ESDS :

- Occupies Less Space - RBA-Access is Faster HK 5 TIMESTAMP 12 RBA 4

VSAM

98

The FREESPACE parameter This FREESPACE parameter, allocates some percentage of both the control interval and control area for planned free space. This free space can be used for adding new records. FREESPACE applies only to the data component Format: FREESPACE (ci% ca%) ci%: - Percentage of control interval to leave free for expansion ci%: - Percentage of control area to leave free for expansion Abbreviation: Use: FSPC Alternate index over KSDS, ESDS.

Required:
Default: Example:

No, because of default.


FREESPACE (0 0) FREESPACE (20 10)

VSAM

99

Other DEFINE AIX Parameters You can also add the following parameters to your DEFINE AIX command. These parameters have been described in DEFINE CLUSTER command. BUFFERSPACE (bytes) CISZ (bytes) ERASE | NOERASE REUSE | NOREUSE SHAREOPTIONS UNIQUEKEY | NONUNIQUEKEY

VSAM

100

//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT =* //SYSIN DD * DEFINE AIX (NAME (DA0001T.LIB.KSDS.EMPNAME.AIX) VOLUMES (BS3013) RELATE (DA0001T.LIB.KSDS.CLUSTER) UPGRADE SHR (1 3) NOERASE NOREUSE KEYS (30 8) NONUNIQUEKEY FREESPACE (20 10) ) DATA (NAME (DA000A1T.LIB.KSDS.EMPNAME.DATA) TRACKS (10 1) RECORDSIZE (75 125) ) INDEX (NAME (DA0001T.LIB.KSDS.EMPNAME.INDEX)) /* //

VSAM

101

DEFINE AN ALTERNATE INDEX PATH


Note : Path is defined for each ALT. Index Path is a separate catalog entry Path is a logical connection thru the ALT. Index to the base cluster Pathname is the dataset name in JCL (DSN=PATHNAME)

VSAM

102

DEFINE PATH Command A path is considered a VSAM object that does not contain any records. The path name is specified in the JCL for applications that access records via the alternate index. Format: Abbreviation: Use: Required: DEFINE PATH (NAME (path name) parameters) DEF PATH Alternate index over a KSDS, ESDS. Yes, for an alternate index.

Default:
Example:

None
DEFINE PATH (NAME (da0001t.lib.ksds.ename.path))

VSAM

103

The PATHENTRY parameter The PATHENTRY parameter specifies the alternate index cluster name. This establishes the pathentry between alternate index cluster and the path. Format: PATHENTRY (entry name) entry name: The name assigned to the alternate index cluster

Abbreviation:
Use: Required: Default: Example:

PENT
Alternate index over a KSDS, ESDS. Yes, for an alternate index. None PATHENTRY (da0001t.lib.ksds.ename.aix)

VSAM

104

The UPDATE parameter Format: Abbreviation: Use: Required: Default: Example: UPDATE | NOUPDATE UPD | NUPD Alternate index over a KSDS, ESDS. Yes, for an alternate index. UPDATE UPDATE NOUPDATE

VSAM

105

Changes made to the base cluster would be reflected automatically in all other alternates indexes provided you have specified UPDATE in DEFINE PATH and UPGRADE in DEFINE AIX command
For this to happen the application program has to open the alternate index path

VSAM

106

//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT =* //SYSIN DD * DEFINE PATH (NAME (DA0001T.LIB.KSDS.EMPNAME.PATH) PATHENTRY (DA0001T.LIB.KSDS.AUTHNAME.AIX) UPDATE ) /* // Example JCL to define PATH for the AIX

VSAM

107

BUILD THE ALTERNATE INDEX


Note : To populate the data component of ALT. index with records VSAM constructs the index component of ALT. Index as it does for any KSDS Assume absolute control of base cluster by DISP=OLD

Output dataset can be ALT. index cluster or pathname


VSAM 108

The BLDINDEX command Format: BLDINDEX INFILE (ddname) OUTFILE (ddname) INTERNALSORT | EXTERNALSORT INFILE and OUTFILE to DD statements. BLDINDEX INDATASET (dataset name) OUTDATASET (dataset name) INTERNALSORT | EXTERNALSORT Abbreviation: Use: Required: Default: BIX Alternate index over a KSDS, ESDS. Yes, for an alternate index. None

VSAM

109

The INFILE/INDATASET parameters The INFILE parameter specifies a DD statement that refers to the input dataset. The INDATASET parameter names the dataset. Format: Abbreviation: Use: Required: INFILE (ddname) | INDATASET (dataset name) IFILE | IDS KSDS, ESDS. Yes, you must code one or the other.

Default:
Example:

None
INFILE (dd1) INDATASET (da0001t.lib.ksds.cluster)

VSAM

110

The OUTFILE/OUTDATASET parameters The OUTFILE parameter specifies a DD statement that refers to the output dataset. The OUTDATASET parameter names the dataset. Format: Abbreviation: Use: Required: Default: Example: OUTFILE (ddname) | OUTDATASET (dataset name) OFILE | ODS KSDS, ESDS. Yes, you must code one or the other. None

OUTFILE (dd2) OUTDATASET (da0001t.lib.ksds.empname.aix)


IDS and ODS dynamically allocate the input and output datasets and ensure that the job contains exclusive contro.

VSAM

111

//STEP1 //SYSPRINT //DD1 // //IDCUT1 //IDCUT2 // SYSIN

EXEC PG=IDCAMS DD SYSOUT =* DD DSN=DA0001T.LIB.KSDS.CLUSTER, DISP=OLD DD UNIT=SYSDA,SPACE=(TRK, (2, 1)) DD UNIT=SYSDA,SPACE=(TRK, (2, 1)) DD * BLDINDEX INFILE (DD1) OUTDATASET (da0001t.lib.ksds.empname.aix) INTERNALSORT

/* //

VSAM

112

DEFINE AN ALTERNATE INDEX


//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT =* //SYSIN DD * DEFINE AIX (NAME(DA0001T.LIB.KSDS.EMPNAME.AIX) VOLUMES (BS3013) RELATE(DA0001T.LIB.KSDS.CLUSTER) UPGRADE KEYS(25 9) FREESPACE(20 10) SHAREOPTIONS(1) NONUNIQUEKEY) ) DATA(NAME(DA000A1T.LIB.KSDS.EMPNAME.DATA) TRACKS(10 1) RECORDSIZE(70 110) CISZ(4096) )

VSAM

113

INDEX(NAME(DA0001T.LIB.KSDS.EMPNAME.INDEX)

DEFINE AN ALTERNATE INDEX


JCL:
//STEP1 EXEC PGM=IDCAMS //SYSPRINT DD SYSOUT =* //SYSIN DD * DEFINE PATH NAME(DA0001T.LIB.KSDS.EMPNAME.PATH) PATHENTRY(DA0001T.LIB.KSDS.EMPNAME.AIX) UPDATE ) /* //

VSAM

114

BUILD THE ALTERNATE INDEX


JCL:
//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

/*
VSAM 115

SEQUENCE FOR BUILDING INDEX


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) . ) BLDINDEX INDATASET(DA0001T.LIB.KSDS.CLUSTER) OUTDATASET(DA0001T.LIB.KSDS.AUTHNAME.AIX) . VSAM 116 )

REPRO COMMAND

VSAM

117

REPRO

Loads empty VSAM cluster with records. Creates backup of a dataset Merges data from two datasets (REPLACE) Catalog information is not copied Incase of KSDS, data and index component are build automatically

VSAM

118

REPRO
Example Loading Dataset: //DD1 DD DSN=DA0001T.INPUT.KSDS,DISP=OLD //DD2 DD DSN=DA0001T.OUTPUT.KSDS, DISP=OLD //SYSIN DD * REPRO INFILE(DD1) OUTFILE(DD2) FROMKEY(A001) TOKEY(A069)

VSAM

119

REPRO
Backup Considerations
Easy to transport data to another system

DELETE-DEFINE-REPRO sequence required to restore the cluster incase of KSDS, CI & CA splits are eliminated, Primary index is rebuild, freespace redistributed. Alternate Indexes to be redefined

VSAM

120

DELETE-DEFINE-REPRO
Example :
//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) VSAM OUTDATASET(DA0001T.LIB.KSDS.CLUSTER)

121

REPRO Command Format: REPRO INFILE (ddname) | INDATASET (dsname) OUTFILE (ddname) | OUTDATASET (dsname) optional parameters None KSDS, ESDS. RRDS Yes. None REPRO INFILE (dd2) OUTDATASET (da0001t.lib.ksds.empname.aix) -

Abbreviation: Use: Required: Default: Example:

VSAM

122

Limiting Input and Output Records

The FROMKEY and TOKEY parameters

FROMKEY specifies the key of the input record at which to begin reading. TOKEY specifies the key of th record to write. You can code either or both parameters. Format: FROMKEY (key)

TOKEY (key) key: You can code an asterisk (*) as the last character. Copying starts or stops if a record is enco that matches all the characters up to *. Abbreviation: Use: Required: Default: Example: FKEY, TKEY KSDS, ISAM No First record in dataset for FROMKEY and last record in dataset for TOKEY. FROMKEY (PAI) TOKEY (PAI*)

VSAM

123

The FROMADDRESS and TOADDRESS parameters FROMADDRESS specifies the relative byte address (RBA) value of the key of the input record at which to begin copying. TOADDRESS specifies the relative byte address (RBA) value of the key of the last input record to copy. You can code either or both parameters. Format: FROMADDRESS (address)

TOADDRESS (address) address: The RBA address of the first or last record to copy.
Abbreviation: Use: Required: Default: dataset Example: FADDR, TADDR KSDS, ESDS No First record in dataset for FROMADDRESS and last record in for TOADDRESS.

VSAM

124

The FROMNUMBER and TONUMBER parameters FROMNUMBER specifies the relative record number of the first RRDS record to copy. TONUMBER specifies the relative record number of the last record to copy. You can code either or both parameters. Format:

FROMNUMBER (relative number) TONUMBER (relative number) relative number: The relative record number of the first or last to copy. The first record is number 0. FNUM, TNUM

record

Abbreviation:

Use:
Required: Default:

RRDS
No First record in dataset for FROMNUMBER and last record in dataset for TONUMBER.

VSAM

125

Example:

FROMNUMBER (10)

The SKIP and COUNT parameters SKIP specifies the number of input records to skip before beginning to copy. COUNT specifies the number of output records to skip to copy. You can code either or both parameters. Fomat: SKIP (number) COUNT (number) number: The number of records to skip or copy. Abbreviation: Use: Required: None KSDS, ESDS, RRDS, non-VSAM datasets No

Default: SKIP defaults to the first record in dataset, and COUNT defaults to all the records in the dataset.

Example:

VSAM (1000) COUNT

SKIP (10)

126

//DD1 //DD2 //SYSIN

DD DSN=DA0001T.INPUT.KSDS,DISP=OLD DD DSN=DA0001T.OUTPUT.KSDS, DISP=OLD DD * REPRO INFILE (DD1) OUTFILE (DD2) FROMKEY (A001) TOKEY (A069) Example JCL for Loading Dataset:

/*

VSAM

127

The REPLACE Parameter for Merge Operations with REPRO

The REPRO command can also be used to merge two datasets into one. The target dataset can be a nonempty KSDS, ESDS or RRDS. If the target dataset is an ESDS, the merged records are added to the end of the existing dataset. You specify the REPLACE option as part of the REPRO command with duplicate primary keys (in case of a KSDS) or duplicate relative record numbers (in case of an RRDS) Format: Abbreviation: Use: Required: Default: Example: REPLACE REP KSDS, ESDS, RRDS No matching records are not replaced. REPLACE COUNT (500) -

VSAM

128

The VERIFY command Judicious use of the verify command is important for preserving data integrity. VERIFY verifies and updates the catalog with information from the physical end of the data in the cluster via a field called the HURBA (High Used Relative Address). VERIFY verifies that the catalog HURBA field stores the true values from the control block HURBA field in the data component. Format: VERIFY FILE (ddname /password) Or

VERIFY DATASET (entry name /password)


Abbreviation: Use: Required: Default: None. VFY KSDS, ESDS, RRDS (not valid for an LDS) No

Example:

VERIFY da0001t.lib.ksds.cluster VSAM VERIFY DATASET (da0001t.lib.ksds.cluster) VERIFY FILE (dd1)

129

The DELETE command The DELETE command can be used to delete both VSAM and non-VSAM objects. Format: DELETE entry name DELETE entry name/password options

Entry name: The name of the entry to delete. An asterisk can be coded as a wild card character in place of a name. Password: The password for the entry if there is one. Omit the /password if the entry doesnt have a password. Abbreviation: DEL

Use:
Required: Default: None.

KSDS, ESDS, RRDS, non-VSAM


No

Example: DELETE da0001t.lib.ksds.cluster

VSAM

130

Optional parameters are:


ALIAS AIX CLUSTER NONVSAM PATH GDG ERASE | NOERASE FORCE | NOFORCE PURGE | NOPURGE SCRATCH | NOSCRATCH

VSAM

131

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

VSAM

132

The PRINT command The PRINT command is used to view the contents of the dataset. Format: PRINT INDATASET (entry name/password) options PRINT INFILE (ddname/password) Entry name: The name of the entry to print Password: The password for the entry if there is one. Omit the /password if the entry doesnt have a password. ddname: The name of a DD statement

Abbreviation: PRINT IDS (entry name /password) PRINT IFILE (ddname /password) Use: Required: KSDS, ESDS, RRDS, non-VSAM No

Default: None. Example: PRINT da0001t.lib.ksds.cluster PRINT INDATASET (da0001t.lib.ksds.cluster) VSAM PRINT INFILE (dd1)

133

The following options are allowed: CHARACTER | DUMP | HEX or CHAR

Options CHAR | DUMP | HEX COUNT (number) FROMADDRESS, [TOADDRESS] FROMKEY, [TOKEY] FROMNUMBER, [TONUMBER] OUTFILE (ddname) SKIP (number)

VSAM

134

//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 Print VSAM Dataset

VSAM

135

If you want the printed output directed to other than SYSPRINT, such as another dataset, you can the OUTFILE parameter.

Format:
ddname: written. Abbreviation: Use: Required: Default: Example:

OUTFILE (ddname/password)
The name of a DD statement specifying where the output is to be

OFILE KSDS, ESDS, RRDS, non-VSAM No, because of default. OUTFILE (SYSPRINT) PRINT da0001t.lib.ksds.cluster OUTFILE (dd1) PRINT INDATASET (da0001t.lib.ksds.cluster)

VSAM

OUTFILE (dd1)

136

The ALTER command The general form of the ALTER command is as follows: Format: ALTER entry name/password parameters PRINT INFILE (ddname/password) Entry name: The name of the entry to alter

Password: The password for the entry if there is one. Omit the password if the entry doesnt have a password. parameters Abbreviation: None

Use:
Required: Default: None.

KSDS, ESDS, RRDS, non-VSAM


No

VSAM Example: ALTER da0001t.lib.ksds.cluster FSPC (30 20)

137

The following is a list of common attributes that are completely alterable.

Change name of the object Add volumes/Remove volumes Change Keys and uniqueness Change record size Change Upgrade option Change % of FREESPACE etc.

VSAM

138

Options: ADDVOLUMES (volumes) AUTHORIZATION (entry string) BUFFERSPACE (size) ERASE | NOERASE FREESPACE (ci% ca%) MASTERPW (password) NEWNAME (newname) READPW (password) SCRATCH | NOSCRATCH (for GDG) SHAREOPTIONS (cross region cross system) TO (date) |FOR (days) UPDATE | NOUPDATE UPDATEPW (password) UPGRADE | NOUPGRADE

VSAM

139

ALTER DA0001T.LIB.KSDS.CLUSTER NEWNAME (DA0001T.MY.CLUSTER) Example 7.6 Altering name of a Dataset

ALTER DA0001T.LIB.KSDS.CLUSTER ADDVOLUMES (BS3001 BS3005) Example 7.7 Adding additional volumes

VSAM

140

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 it with new attributes. CISZ Cluster type, IMBED/REPLICATE REUSE | NOREUSE

VSAM

141

ALTER PRINT DELETE COMMANDS

VSAM

142

Format:

VERIFY FILE (ddname /password) Or VERIFY DATASET (entry n


VFY KSDS, ESDS, RRDS (not valid for an LDS) No None.

Abbreviation: Use: Required: Default: Example:

VERIFY da0001t.lib.ksds.cluster VERIFY DATASET (da0001t.lib.ksds.cluster) VERIFY FILE (dd1)

VSAM

143

There are actually two HURBAs: one in the VSAM control block of the cluster and one in the catalog entry for the cluster. The danger is that if the catalog HURBA field is incorrect, theres a possibility that if that previously added records may be overwritten, especially in the event of this relationship.

VERIFY DATASET (DA0001T.LIB.KSDS.CLUSTER)

Example 7.1

VERIFY

Remark: VERIFY can be issued from a TSO or within a JCL statement either the FILE or DATASET parameter.

VSAM

144

End of data

VSAM cluster Control block HURBA Catalog HURBA

CA splits

Catalog

Fig: 7.2 Relationship between HURBA in catalog and cluster.

VSAM

145

The DELETE command


The DELETE command can be used to delete both VSAM and non-VSAM objects.
Format: DELETE entry name DELETE entry name/password options

Entry name: The name of the entry to delete. An asterisk can be coded as a wild card character in place of a name. Password: The password for the entry if there is one. Omit the /password if the entry doesnt have a password.

Abbreviation: Use: Required: Default: Example: None.

DEL KSDS, ESDS, RRDS, non-VSAM No

DELETE da0001t.lib.ksds.cluster

VSAM

146

DELETE DA0001T.LIB.KSDS.CLUSTER ERASE

Example 7.3 Deleting a Cluster

VSAM

147

Optional parameters are:


ALIAS AIX CLUSTER NONVSAM PATH GDG ERASE | NOERASE FORCE | NOFORCE PURGE | NOPURGE SCRATCH | NOSCRATCH

VSAM

148

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

Example 7.4 Delete VSAM Dataset

VSAM

149

The PRINT command


The PRINT command is used to view the contents of the dataset.
Format: PRINT INDATASET (entry name/password) options PRINT INFILE (ddname/password) Entry name: The name of the entry to print Password: The password for the entry if there is one. Omit the /password if the entry doesnt have a password. ddname: The name of a DD statement Abbreviation: PRINT IDS (entry name /password) PRINT IFILE (ddname /password) KSDS, ESDS, RRDS, non-VSAM No None.

Use: Required: Default: Example:

PRINT da0001t.lib.ksds.cluster PRINT INDATASET (da0001t.lib.ksds.cluster)

PRINT INFILE (dd1)

VSAM

150

The default output destination for PRINT is SYSPRINT. The following options are allowed: CHARACTER | DUMP | HEX or CHAR Options
CHAR | DUMP | HEX COUNT (number) FROMADDRESS, [TOADDRESS] FROMKEY, [TOKEY] FROMNUMBER, [TONUMBER] OUTFILE (ddname) SKIP (number)

VSAM

151

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

DISP=SHR

Example 7.5 Print VSAM Dataset

If you want the printed output directed to other than SYSPRINT, such as another dataset, you can the OUTFILE parameter.

VSAM

152

Format:

OUTFILE (ddname/password)

ddname: The name of a DD statement specifying where the output is to be written. Abbreviation: Use: Required: Default: Example: PRINT da0001t.lib.ksds.cluster OUTFILE (dd1) PRINT INDATASET (da0001t.lib.ksds.cluster) OFILE KSDS, ESDS, RRDS, non-VSAM No, because of default. OUTFILE (SYSPRINT)

OUTFILE (dd1)

VSAM

153

The ALTER command


The general form of the ALTER command is as follows:
Format: ALTER entry name/password parameters PRINT INFILE (ddname/password) Entry name: The name of the entry to alter Password: The password for the entry if there is one. Omit the /password if the entry doesnt have a password. parameters Abbreviation: Use: Required: Default: Example: None. No None KSDS, ESDS, RRDS, non-VSAM

ALTER da0001t.lib.ksds.cluster

FSPC (30 20)

VSAM

154

You can use this powerful command to change certain (but by no means all) attributes of a previously defined VSAM object. These objects include a base cluster and its data or index component, an alternate index cluster and its data or index component. The following is a list of common attributes that are completely alterable.

Change name of the object


Add volumes/Remove volumes Change Keys and uniqueness Change record size Change Upgrade option Change % of FREESPACE etc.
VSAM 155

Options:
ADDVOLUMES (volumes) AUTHORIZATION (entry string) BUFFERSPACE (size) ERASE | NOERASE FREESPACE (ci% ca%) MASTERPW (password) NEWNAME (newname) READPW (password) SCRATCH | NOSCRATCH (for GDG) SHAREOPTIONS (cross region cross system) TO (date) |FOR (days) UPDATE | NOUPDATE UPDATEPW (password) UPGRADE | NOUPGRADE

VSAM

156

ALTER

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

Example 7.6 Altering name of a Dataset

ALTER

DA0001T.LIB.KSDS.CLUSTER ADDVOLUMES (BS3001 BS3005)

Example 7.7 Adding additional volumes

VSAM

157

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 it with new attributes.

CISZ Cluster type, IMBED/REPLICATE REUSE | NOREUSE

VSAM

158

VSAM

159

VERIFY
Verify - preserves data integrity (HURBA) Format : VERIFY FILE(ddname/passwd) or VERIFY DATASET(entryname/passwd) VERIFY entryname/passwd (TSO) Example : VERIFY DATASET(DA0001T.LIB.KSDS.CLUSTER) Remark : 1. VERIFY can be issued from a TSO or within a JCL statement. 2. It is valid only for VSAM dataset except LDS.
VSAM 160

DELETE
- logically deletes dataset - catalog entry deleted

Format : DELETE entryname/passwd optional parameters Example : DELETE DA0001T.LIB.KSDS.CLUSTER ERASE Optional parameters are : - AIX - ERASE | NOERASE - CLUSTER - FORCE | NOFORCE - NONVSAM - PURGE | NOPURGE - PATH - SCRATCH | NOSCRATCH
VSAM

161

PRINT
default O/P destinations is SYSPRINT prints in CHAR/HEX/DUMP format limiting parameters like REPRO are available Format 1 : PRINT INDATASET (entryname/passwd) options Format 2 : PRINT INFILE (ddname/passwd) options

VSAM

162

PRINT
Options

CHAR | DUMP | HEX


COUNT (number)

FROMADDRESS, [TOADDRESS]
FROMKEY, [TOKEY] FROMNUMBER, [TONUMBER] OUTFILE (ddname) SKIP (number)
VSAM 163

ALTER
Used to change certain attributes of a previously defined VSAM object Following 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

VSAM

164

ALTER
Options :
ADDVOLUMES (volumes)

BUFFERSPACE (size)
ERASE | NOERASE FREESPACE(ci% ca%) MASTERPW(password) NEWNAME(newname)

READPW (password)

VSAM

165

ALTER
SCRATCH | NOSCRATCH

SHR(cross region cross system)


TO(date) |FOR(days) UPDATE | NOUPDATE UPDATEPW(password) UPGRADE |NOUPGRADE

VSAM

166

ALTER
Examples
ALTER DA0001T.LIB.KSDS.CLUSTER NEWNAME(A2000.MY.CLUSTER) ALTER DA0001T.LIB.KSDS.INDEX FREESPACE(30 30) -

The following attributes are alterable only for empty clusters


KEYS(length offset) RECORDSIZE(avg max) UNIQUEKEY | NONUNIQUEKEY
VSAM 167

ALTER
The following attributes are unalterable. You have to DELETE the cluster and redefine it with new attributes.
- CISZ

- Cluster type,
- IMBED/REPLICATE

- REUSE | NOREUSE

VSAM

168

SAMPLE PROGRAMS

VSAM

169

SAMPLE PROGRAM
//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 * 123456789123456789 AAAAAAAABBBBBBCCCC /* //DD2 DD DSN=DA0001T.ESDS.CLUSTER //SYSIN DD * REPRO INFILE(DD1) OUTFILE(DD2) VSAM /*

170

SAMPLE PROGRAM
//DA0001TA JOB LA2719,PCS,MSGLEVEL= (1,1),
// MSGCLASS=A, NOTIFY=DA0001T //* Load Data from a file into ESDS VSAM Dataset

//STEP1
//SYSPRINT //DD1

EXEC PGM=IDCAMS
DD SYSOUT = * DD DSN=DA0001T.ESDS.CLUSTER1

//DD2
//SYSIN

DD DSN=DA0001T.ESDS.CLUSTER2
DD * REPRO INFILE(DD1 OUTFILE(DD2) -

/*

VSAM

171

SAMPLE PROGRAM
//DA0001TA JOB LA2179,PCS,MSGLEVEL=(1, 1) ,

//
//* Print VSAM Dataset //PRG1

NOTIFY=DA0001T
EXEC PGM=IDCAMS

//FILE1
//

DD DSN=DA0001T.LIB.KSDS.CLUSTER,
DISP=SHR DD SYSOUT = *

//SYSPRINT

// SYSIN
/* //

DD *

PRINT INFILE(FILE1) CHARACTER

VSAM

172

SAMPLE PROGRAM
//DA0001TA JOB LA2179,PCS,MSGLEVEL=(1, 1) ,

//
//STEP1

NOTIFY=DA0001T
EXEC PGM=IDCAMS

//* Deletes VSAM Dataset

//SYSPRINT
//SYSIN

DD SYSOUT = *
DD *

DELETE DA0001T.TRAIN.ITMFOIV

/*
//

VSAM

173

GENERATION DATA GROUP

VSAM

174

GENERATION DATA GROUP


Group of datasets which are related to each other chronologically and functionally Generations can continue until a specified limit is reached
Limit specifies total number of generations that can exist at any one time Once limit is reached the oldest generation is deleted.

VSAM

175

GENERATION DATA GROUP


MVS uses the generation data groups catalog entry to keep track of relative generation numbers. As a result, GDGs must be cataloged and each generation dataset thats a part of the group must be cataloged too.
When you create a generation data groups catalog entry, you specify how many generations should be maintained eg. You may specify that five generations including the current generation, be maintained. During each processing cycle, the new version of the file becomes the current version.

VSAM

176

GENERATION DATA GROUP


file.c1(+1) Next Generation file.c1(0) Current Generation file.c1(-1) Previous Generations file.c1(-2) file.c1(-3) There are 3 previous generation, 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 the current generation is always referred to as relative generation 0.
VSAM 177

GENERATION DATA GROUP


MVS uses Absolute Generation Numbers in the form GnnnnV00 to identify each generation dataset uniquely. GnnnnV00 represents the chronological sequence 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 to the sequence number.

VSAM

178

GENERATION DATA GROUP


filename.GnnnnV00 35 chars 9 chars Example : Using GDG
// IN DD DSN=DA0001T.MASTER, DISP=SHR // OUT DD DSN=DA0001T.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)
VSAM 179

GENERATION DATA GROUP


Relative Name and Absolute Name
DA0002T.MASTER.DAY90) ---> Relative Name DA0002T.MASTER.DAY.G00001V00 -->Absolute Name Defining a GDG // Step1 EXEC PGM=IDCAMS // SYSPRINT DD SYSOUT = * // SYSIN DD * DEFINE GDG(NAME(DA0001T.MASTER.DAY) LIMIT(5) SCRATCH EMPTY) /* //
VSAM 180

GENERATION DATA GROUP


Following code contains 1 job with 2 steps....
//DA0003TA JOB //UPDATE EXEC PGM=PAY3200 //OLDMAST DD DSN=DA0001T.MMA2.PAY.MAST(0),DISP=OLD //NEWMAST DD DSN=DA0001T.MMA2.PAY.MAST(+1), // DISP= (NEW,CATLG),UNIT=3300, // VOL=SER=BS3001, // DCB=(LRECL=80,BLKSIZE=1600) //PAYTRAN DD DSN=DA0001T.MMA2.PAY.TRAN,DISP=OLD //PAYLIST DD SYSOUT=* //REPORT EXEC PGM=PAY3300 //PAYMAST DD DSN=DA0001T.MMA2.PAY.MAST(+1),DISP=OLD //PAYRPT DD SYSOUT=*
VSAM 181

GENERATION DATA GROUP


Following code contains 2 jobs.........
//JOB1 //UPDATE //OLDMAST //NEWMAST // // // //PAYTRAN //PAYLIST //* //JOB2 //REPORT //PAYMAST //PAYRPT JOB EXEC PGM=PAY3200 DD DSN=DA0001T.MMA2.PAY.MAST(0),DISP=OLD DD DSN=DA0001T.MMA2.PAY.MAST(+1), DISP=(NEW, CATLG), UNIT=3300, VOL=SER=BS3001, DCB=(LRECL=80, RECFM=FB,BLKSIZE=0) DD DSN=DA0001T.MMA2.PAY.TRAN,DISP=OLD DD SYSOUT =* JOB ........... EXEC PGM=PAY3300 VSAM DD DSN=DA0001T.MMA2.PAY.MAST(0),DISP=OLD182 DD SYSOUT=*

CONSIDERATIONS FOR USING GDGs


Have to be created before data sets 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 be specified System must be informed each time a new dataset added to or deleted from GDG System must be informed if the entire GDG is to be deleted
VSAM 183

SPECIFICATIONS FOR CREATING A GDG


Name of the GDG
Number of generations that are to be retained Action when number of generations to be retained reaches the limit

VSAM

184

FEATURES OF GDGs
All datasets within a GDG will have the same name Generation number of a dataset within a GDG is automatically assigned by OS when created Datasets within a GDG can be referenced by there relative generation number Generation 0 always references current generation

VSAM

185

GDGs
CREATION OF GDGs Create and catalog the index Use IDCAMS statement DEFINE GDG for creating Index Parameters for creating index SPECIFICATION Name of GDG Number of generations Uncataloging oldest generation once limit reached Uncataloging all generations when limit reached Physical deletion of entry Uncataloging entry without physical deletion VSAM 186 Defining a model for the GDG.

GDGs

NAME LIMIT NOEMPTY EMPTY SCRATCH NOSCRATCH

VSAM

187

GDGs
JCL for creating index
//STEP1 EXEC PGM=IDCAMS

//SYSIN

DD
DEFINE GDG (NAME(DA0001T.ACCOUNTS.MONTHLY) LIMIT(5) EMPTY SCRATCH ) -

/*

//

VSAM

188

GDGs
Modifying Features of GDG Can be modified by the ALTER command
Example : //STEP1 EXEC PGM=IDCAMS //SYSIN DD ALTER DA0001T.ACCOUNTS.MONTHLY NOSCRATCH EMPTY /* //
VSAM

189

GDGs
Deleting GDG Index Can be deleted by the DELETE parameter of IDCAMS Will result in an error on reference to any generation datasets of the GDG
/STEP1 EXEC PGM=IDCAMS //SYSIN DD DELETE DA0001T.ACCOUNTS.MONTHLY GDG /* //

VSAM

190

GDGs
Adding a Dataset to a GDG Name of the model containing the GDG DCB parameters is coded in the DCB parameter of the DD statement
Example :
//STEP1 //FILE1 // // // // EXEC PGM=GDG1 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)

VSAM

191

GDGs
Deleting GDG Index and Datasets FORCE parameter in the DELETE statement of IDCAMS can be used
Example :
/STEP1 EXEC PGM=IDCAMS //SYSIN DD DELETE DA0001T.ACCOUNTS.MONTHLY GDG FORCE /* //
VSAM

192

COBOL VSAM CONSIDERATIONS

VSAM

193

COBOL-VSAM CONSIDERATIONS
SELECT CLAUSE
SELECT file ASSIGN TO DDNAME / AS-DDNAME ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVE ACCESS MODE IS SEQUENTIAL/DYNAMIC/RANDOM RECORD KEY IS <primary Key Dataname> ALTERNATE KEY IS <Alternate Key Dataname> [WITH DUPLICATES] FILE STATUS IS status-key

Note: A prefix AS- has to be attached to DDNAME to indicate to COBOL that the file selected is an ESDS dataset.
VSAM 194

COBOL - VSAM CONSIDERATIONS


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

VSAM

195

COBOL-VSAM CONSIDERATIONS
Alternate index processing : In your JCL there must be a DD statement for base cluster and one or more DD statement for alternate 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.

VSAM

196

COBOL-VSAM CONSIDERATIONS
For e.g : //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

In the example above LIBMAST is the base cluster and LIBMAST1, LIBMAST2 are path names of Alternate Indexes built on the base cluster
VSAM 197

COBOL-VSAM CONSIDERATIONS
REMARK: No matter how many alternate indexes you specify in the program, there is 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] ALTERNATE KEY IS ......... [WITH DUPLICATES]
FD : Should

have record description having primary key dataname and alternate key VSAM dataname

198

COBOL-VSAM CONSIDERATIONS
Key of Reference The key that is currently being used to access records. primary key becomes, by default, the key of reference. To access records by an alternate index key, you merely change the key of reference by using the KEY phrase as part of one of the following statements. A random READ statement, for example
READ EMP-MAST KEY IS EMP-NAME

Position record pointer on the desired record


START EMP-MAST KEY IS EQUAL TO EMP-NAME.
VSAM 199

FILE STATUS CODES


VSAM I/O ERROR PROCESSING. Most programmers ignore errors, because the access method will abend the program if a serious I/O error occurs. Not so when processing Vsam datasets. 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 after every I/O operation.

VSAM

200

FILE STATUS CODES


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 continue processing : 21 Input record out of sequence. 22 duplicate primary key or unique alternate key encountered(un-expected). 23 record (or Key) not found.
VSAM 201

FILE STATUS CODES


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 is likely to indicate that your input is bad

VSAM

202

FILE STATUS CODES


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.

VSAM

203

FILE STATUS CODES


94
95

current record pointer undefined.


Nonzero HURBA for OPEN OUTPUT.

96
97

No corresponding JCL DD statement.

If your shop has enabled the implicit VERIFY command, this means that the dataset was opened after and implicit VERIFY, and you can continue processing.

VSAM

204

BIBLIOGRAPHY
MVS/VSAM for Application Programmer by Brown and Smith

VSAM by Doug Lowe

VSAM for COBOL Programmer by Doug Lowe

VSAM

205

Você também pode gostar