Fundamentals of VSAM Part 2 © Copyright IBM Corp., 2000, 2004. All rights reserved.
Jan 12, 2016
Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved.
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 2 of 31
UNIT Practical VSAM Applications
� VSAM Applications
Topics:
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 3 of 31
In this unit, you will learn how to use IDCAMS to create a KSDS file statement that defines a VSAM file.
This unit also demonstrates how to process a KSDS file.
Unit Introduction
Unit: Practical VSAM Applications
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 4 of 31
At the end of this unit, you will be able to:
• Explain how to use IDCAMS to create a KSDS file statement that defines a VSAM file
• Explain how to process a KSDS file statement using a program written in a language such as OS/VS COBOL or COBOL II
Unit Objectives
Unit: Practical VSAM Applications
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 5 of 31
UNIT Practical VSAM Applications
� VSAM Applications
Topics:
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 6 of 31
At the end of this topic, you will be able to:
• Explain how to use IDCAMS to create a KSDS file statement that defines a VSAM file
• Explain how to process a KSDS file statement using a program written in a language such as OS/VS COBOL or COBOL II
Topic Objectives
Unit: Practical VSAM Applications Topic: VSAM Applications
Introduction
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 7 of 31
Creating a KSDS File Statement
This example shows a partial record layout of a KSDS customer master file.
The records are 120 byte, fixed length records. CUST – ACCT is the primary key here.
Continued…
Unit: Practical VSAM Applications
CUST-ACCT PIC X(06).
CUST–TYPE PIC X(01).
CUST-NAME PIC X(38).
.
.
.
.
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 8 of 31
Creating a KSDS File Statement (cont’d)
This example shows a basic set of IDCAMS commands and parameters to create a KSDS.
A continuation character is needed to continue an IDCAMS command on a new line. Otherwise, IDCAM will flag it as an error.
Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
(NAME(KISVS.CUST.CLUSTER) _
CYLINDERS (4 1) _
VOLUME (TESTO8) _
INDEXED) _
DATA
(NAME(KISV,CUST,DATA) _
RECORDIZE(120 120) _
KEYS (6 0)) _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 9 of 31
Creating a KSDS File Statement (cont’d)
Beginning with the DEFINE command, identify the VSAM object to be defined. The general form is:
DEFINE object
Use the NAME parameter to give the VSAM object a name. It should be placed immediately after the object definition. Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
(NAME(KISVS.CUST.CLUSTER) _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 10 of 31
Creating a KSDS File Statement (cont’d)
Indicate how much space the cluster will need. The space parameter can be expressed in CYLINDERS, TRACKS or RECORDS, depending on the size of the cluster.
Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
(NAME(KISVS.CUST.CLUSTER) _
CYLINDERS (4 1) _
VOLUMES(TESTO8) _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 11 of 31
Creating a KSDS File Statement (cont’d)
The RECORDSIZE parameter specifies both the average and the maximum length of the data records.
The general form is:
RECORDSIZE(avg-length max-length)
Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
(NAME(KISVS.CUST.CLUSTER) _
CYLINDERS (4 1) _
VOLUMES (TEST08) _
RECORDSIZE(120 120) _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 12 of 31
Creating a KSDS File Statement (cont’d)
Tell IDCAMS what the key length is and its relative position in the record. The general form is:
KEYS(length offset)
The other parameter for the cluster is the INDEXED parameter, which indicates that the VSAM file is a KSDS. It is the default and does not need to be coded. Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
(NAME(KISVS.CUST.CLUSTER) _
CYLINDERS (4 1) _
VOLUMES(TEST08) _
RECORDSIZE(120 120) _
KEYS(6 0) _
INDEXED)
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 13 of 31
Creating a KSDS File Statement (cont’d)
Next, the data and index components of the cluster needs to be defined and named.
This completes the job.
The example here shows a complete IDCAMS statement that defines a VSAM file.
Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
NAME(KISVS.CUST.CLUSTER) _
CYLINDERS (4 1) _
VOLUMES(TEST08) _
RECORDSIZE(120 120) _
KEYS(6 0) _
INDEXED) _
DATA _
(NAME(KISVS.CUST.DATA)) _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 14 of 31
Creating a KSDS File Statement (cont’d)
The example shows the format of another IDCAMS command REPRO. REPRO performs the following tasks:
• It loads a VSAM file.
• It makes a copy of a VSAM file. Continued…
Unit: Practical VSAM Applications
REPRO INDATASET (entry-name) or
INFILE (ddname)
OUTDATASET (ENTRY-NAME) or
OUTFILE (ddname)
O SKIP (count)
P PROMKEY (key)
T FROMNUMBER (number)
I
O COUNT (count)
N TOKEY (key)
A TONUMBER (number)
L TOADDRESS (address)
REUSE . NORUSE
REPLACE . NOREPLACE
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 15 of 31
Creating a KSDS File Statement (cont’d)
Here is an example of a REPRO command that can be used to load a KSDS from a sequential file.
Continued…
Unit: Practical VSAM Applications
REPRO INDATASET(KSVS.MAST.TRAN) _
OUTDATASET(KSVS.MAST.CLUSTER)
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 16 of 31
Creating a KSDS File Statement (cont’d)
The rest of the parameters for REPRO are optional.
To load a part of the file, use the parameter to establish a range for both input and output data sets. The example here shows code for the same.
Continued…
Unit: Practical VSAM Applications
Input:
SKIP(no.-records-to-skip)
FROMKEY(key-value) KSDS or ISAM
FROMNUMBER(RELATIVE-RECLORD-NUMBER)
RRDS only
FROMADDRESS(relative-byte-address) KSDS
or ESDS only
Output:
COUNT (no.-records-to-be-copied)
TOKEY(key-value) KSDS or ISAM only
TONUMBER (relative-record-number)
RRDS only
TOADDRESS(relative-byte-address) KSDS or
ESDS only
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 17 of 31
Creating a KSDS File Statement (cont’d)
This example shows the REPRO command defined with a range of records skipped (SKIP) and copied (COUNT).
Continued…
Unit: Practical VSAM Applications
REPRO INDATASET(KSVS.MAST.SEQ) _
OUTDATASET(KSVS.CUST.MAST) _
SKIP(100)
COUNT(500)
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 18 of 31
Creating a KSDS File Statement (cont’d)
Use the REUSE parameter to specify that a file may be loaded even if the output file already contains records, if it is specified earlier in the DEFINE CLUSTER command.
The REPLACE option is a method for dealing with KSDS duplicate methods.
Continued…
Unit: Practical VSAM Applications
DEFINE CLUSTER _
NAME(KSVS.CUST.CLUSTER) _
REUSE
REPRO INDATASET(KSVS.TRAN) _
OUTDATASET(KSVS.CUST.CLUSTER)
REUSE
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 19 of 31
Creating a KSDS File Statement (cont’d)
To see any data after it is loaded, use the PRINT command. This dumps the contents of the data set in CHARACTER, HEX or DUMP format.
Continued…
Unit: Practical VSAM Applications
PRINT INDATASET (entry-name) or
INFILE (ddname) (format)
Input:
SKIP(no.-records-to-skip)
PROMKEY (key-value) KSDS or ISAM
FROMNUMBER (relative-record-number)
RRDS only
FROMADDRESS (relative-byte-address)
KSDS or ESDS only
Output:
COUNT (no.-records-to-be-copied)
TOKEY (key-value) KSDS or ISAM only
TONUMBER (relative-record-number)
RRDS only
TOADDRESS (relative-byte-address)
KSDS or ESDS only_
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 20 of 31
Creating a KSDS File Statement (cont’d)
This example shows the LISCAT, ALTER and DELETE commands.
Unit: Practical VSAM Applications
LISCAT ENTRIES (KISVS.CUSTOMER.*)
ALTER KSVS.CUSTOMER.DATA
INHIBIT
DELETE
KSVS.CUSTOMER.CLUSTER _
CLUSTER _
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 21 of 31
Processing a KSDS
This example shows the complete PROCEDURE DIVISION of a program to load a sample KSDS with records.
Continued…
Unit: Practical VSAM Applications
PROCEDURE DIVISION.
OPEN INPUT IN-FILE OUTPUT CUST-MAST.
IF CUST-STATUS NOT – 00
DISPLAY ERROR OPENING KSDS
DISPLAY STATUS IS CUST-STATUS
ELSE
READ IN-FILE
AT END SET END-OF-FILE TO TRUE
END READ
PERFORM UNTIL END-OF-FILE OR ERROR
MOVE IN-RECORD TO MASTER-REC
WRITE MASTER-RECORD
EVALUATE CUST-STATUS
WHEN 00
READ IN-FILE
AT END SET END-OF-FILE TO TRUE
END READ
END-PERFORM.
CLOSE IN-FILE CUST-MAST
IF CUST-STATUS NOT – 00
DISPLAY ERROR CLOSING KSDS
DISPLAY STATUS IS CUST-STATUS
END-IF
STOP RUN.
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 22 of 31
Processing a KSDS (cont’d)
This example shows a SELECT statement to use for sequential access.
DATA DIVISION and WORKING STORAGE is also shown.
Continued…
Unit: Practical VSAM Applications
SELECT CUST-MAST ASSIGN TO CUSTMAST
ORGANIZATION IS INDEXED
ACCESS MODE IS SEQUENTIAL
RECORD KEY IS CUST-ACCT
FILE STATUS IS CUST-STATUS.
DATA DIVISION.
FD CUST-MAST
LABEL RECORDS ARE STANDARD
01 MASTER-RECORD.
.
.
10 CUST-ACCOUNT PIC X(6).
10 CUST-REMAINING PIC X(114)
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 23 of 31
Processing a KSDS (cont’d)
The example shows the PROCEDURE DIVISION statements to read this file.
Continued…
Unit: Practical VSAM Applications
100-MAIN.
OPEN INPUT CUST-MAST.
IF CUST-STATUS NOT = 00
abend program.
200-READ
READ CUST-MAST
EVALUATE CUST-STATUS’
WHEN 10
SET END-OF-FILE TO TRUE
ELSE
other processing options.
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 24 of 31
Processing a KSDS (cont’d)
To retrieve a record randomly, the program moves the desired key into the key of the KSDS.
In this example the abbreviated FDs have been used for both a TRAN-FILE and CUST-MAST.
The TRAN-FILE contains a sequential file of the keys to be randomly retrieved.
Now here are the PROCEDURE DIVISION statements. Notice the TRAN-KEY is moved to the CUST-ACCT before CUST-MAST is read.
Continued…
Unit: Practical VSAM Applications
FD TFAN-FILE
LABEL RECORDS ARE STANDARD.
01 TFAN-REC.
05 TFAN-KEY PIC X(6).
05 TFAN-REMAIN PIC X(114).
FD CUST-MAST
LABEL RECORDS ARE STANDARD.
01 MASTER-RECORD...
10 CUST-ACCT PIC X(6).
10 CUST-REMAIN PIC X(114).
100-MAIN.
OPEN INPUT CUST-MAST, TFAN-FILE.
IF CUST-STATUS – 00
PERFORM 200-READ UNTIL EOF OR
EAD-ERROR....
200-READ.
READ TFAN-FILE
AT END SET EOP TO TRUE
IF NOT EOP
MOVE TFAN-KEY TO CUST-ACCT
READ CUST-MAST......
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 25 of 31
Processing a KSDS (cont’d)
This example shows a technique for the REWRITE statement to update a VSAM file. The VSAM file needs the OPEN I-O statement, so that it can be open for input and output.
Unit: Practical VSAM Applications
100-MAIN.
OPEN INPUT TFAN-FILE.
OPEN I-0 CUST-MAST.
IF CUST-STATUS – 00
PERFORM 200-UPDATE UNTIL EOF OR EAD-ERROR....
200-UPDATE.
READ TFAN-FILE AT END ....
IF NOT EOF
MOVE TFAN-KEY TO CUST-ACCT
READ CUST-MAST
IF CUST-STATUS = 00
(perform update processing)
REWRITE MASTER-RECORD
(do REWRITE error processing)
ELSE
(do READ error processing).
Topic: VSAM Applications
Concepts
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 26 of 31
Now that you have completed this topic, you should be able to:
• Explain how to use IDCAMS to create a KSDS file statement that defines a VSAM file
• Explain how to process a KSDS file statement using a program written in a language such as OS/VS COBOL or COBOL II
Topic Summary
Unit: Practical VSAM Applications Topic: VSAM Applications
Summary
MVS/ESA Fundamentals of VSAM Part 2
© Copyright IBM Corp., 2000, 2004. All rights reserved. Page 27 of 31
Now that you have completed this unit, you should be able to:
• Explain how to use IDCAMS to create a KSDS file statement that defines a VSAM file
• Explain how to process a KSDS file statement using a program written in a language such as OS/VS COBOL or COBOL II
Unit Summary
Unit: Practical VSAM Applications
Summary