Monday, December 19, 2011

Various VSAM File processing techniques


Initially loading records sequentially into a file: Initially loading a file means
writing records into the file for the first time. This is not the same as writing
records into a file from which all previous records have been deleted.

To initially load a VSAM file:
1. Open the file.
2. Use sequential processing (ACCESS IS SEQUENTIAL) because it is faster.
3. Use WRITE to add a record to the file.

Using OPEN OUTPUT to load a VSAM file significantly improves the performance of
your program. Using OPEN I-O or OPEN EXTEND has a negative impact on the
performance of your program.

When you load VSAM indexed files sequentially, you optimize both loading
performance and subsequent processing performance, because sequential
processing maintains user-defined free space. Future insertions will be more
efficient.

With ACCESS IS SEQUENTIAL, you must write the records in ascending RECORD KEY
order.

When you load VSAM relative files sequentially, the records are placed in the file
in the ascending order of relative record numbers.

Opening a loaded file (a file with records)

To open a file that already contains records, use OPEN INPUT, OPEN I-O, or OPEN
EXTEND.

If you open a VSAM entry-sequenced or relative-record file as EXTEND, the added
records are placed after the last existing records in the file.

If you open a VSAM key-sequenced file as EXTEND, each record you add must have
a record key higher than the highest record in the file.

Replacing records in a VSAM file

For sequential files, the length of the record you rewrite must be the same as the
length of the original record.

For indexed files, you can change the length of the record you rewrite.

For variable-length relative files, you can change the length of the record you
rewrite.

To replace records randomly or dynamically, your program need not read the
record to be rewritten. Instead, to position the record that you want to update, do
as follows:

For indexed files, move the record key to the RECORD KEY data item and then
issue the REWRITE.

For relative files, move the relative record number to the RELATIVE KEY data item
and then issue the REWRITE.

Deleting records from a VSAM file
Open the file I-O and use the DELETE statement to remove an existing record from
an indexed or relative file. You cannot use DELETE on a sequential file.

When you use ACCESS IS SEQUENTIAL or the file contains spanned records, your
program must first read the record to be deleted. The DELETE then removes the
record that was read. If the DELETE is not preceded by a successful READ, the
deletion is not done and the status key value is set to 92.

When you use ACCESS IS RANDOM or ACCESS IS DYNAMIC, your program need not
first read the record to be deleted. To delete a record, move the key of the record to
be deleted to the RECORD KEY data item and then issue the DELETE. Your program
should check the file status key after each DELETE statement.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.