Mainframes 360
The one stop destination for System Z professionals

Saturday, December 12, 2009

VSAM Tutorial 04 – Loading Records in VSAM KSDS

Q. How do you load data into VSAM KSDS Dataset?
Storing data in a VSAM KSDS file, is known as Loading. Initially, to begin with the KSDS File is empty, it doesn’t contain any records. Based on, the Control Interval Size, that you’d have specified, while creating the KSDS File, the MVS Operating System books and reserves empty Control Intervals of that size in the KSDS Cluster. These are yet to be filled up,populated with data-records.

To actually load data-records into a VSAM KSDS file, you use IBM Supplied Utility IDCAMS. Instruct the IDCAMs utility, what’s the task you would like to perform by providing an appropriate control statement(as instream data). The IDCAMS utility picks up the Control Commands, and acts accordingly. So, the control command used to Load Data records in VSAM KSDS File is REPRO Command. In this tutorial, effectively, you are going to REPRO in the data records from a plain Sequential file into a KSDS Dataset. At the same time you’ll also learn, how to unload the contents KSDS Dataset back to a plain sequential file.

Q. Hey, tell me what’s the syntax for the REPRO Command? How do I write a Batch Job/JCL with IDCAMS and REPRO Command?
The REPRO Command in it’s simplest form looks like this -

REPRO INFILE(input-ddname)

In the above syntax, the input-ddname is DD Card for the Input Dataset, which happens to be the Physical Sequential(PS) Dataset, the source which currently holds the data-records. The output-ddname is the DD Card for the Output Dataset, which should be the destination VSAM KSDS File. So, let me quickly put together an example, that’ll show how to load records in a dataset. I am going to create a KSDS Dataset, to store the data of Employees working in an Organisation. I would like to store their ENo, EName, Salary, JDate(Joining Date). Assume that, you’ve stored the following Employees Data in a sequential file -



As you can observe, all the data-records have a length = 23. Moreover, the Employee ID, is 2 digits. This can be used to uniquely identify each employee. Hence, this will acts as a Key in the VSAM KSDS Cluster. Note that all the Input Data Records are increasing(ascending) order of the Key(EMPLOYEE ID). If the records are out of order, it will throw an error. When you load data records in KSDS Dataset, it should always be Sequential Load.

Given below is the definition of the VSAM KSDS File : AGY0157.KSDS.EMPLOYEE, which will be used to store the Employee Records -


Notice, that the name of the VSAM KSDS Cluster is AGY0157.KSDS.EMPLOYEE. It has RECORDSIZE 23, and the Key values begin from column 0(offset) and are 2 columns wide. The word INDEXED is used to create KSDS.

To load or REPRO IN the Employee Data from PS Sequential File, AGY0157.SEQ.EMPLOYEE to VSAM KSDS File AGY0157.KSDS.EMPLOYEE, you would use the REPRO Command of the IDCAMS utility as follows :


Upon submitting this Job, the records are loaded successfully, and this can be verified by seeing the JOB SYSOUT Dataset.


You can see in bold that the NUMBER OF RECORDS PROCESSED WAS 6. This implies all the 6 records were successfully loaded into the VSAM KSDS File with Maximum Condition Code 0.

To many people who are thrown to work at a mainframe computer on their first job, they feel lost. Mainframe people seem to speak a completely different language and that doesn't make life easy. What's more, the books and manuals are incredibly hard to comprehend.

"What on earth is a Mainframe?" is an absolute beginner's guide to mainframe computers. We'll introduce you to the hardware and peripherals. We'll talk about the operating system, the software installed on a mainframe. We'll also talk about the different people who work on a mainframe. In a nutshell, we'll de-mystify the mainframe.

Readers based in India, can buy the e-book for Rs. 50 only or the print book. International readers based in the US and other countries can click here to purchase the e-book.