Thursday, December 15, 2011

File Access Modes


   You can only access records in VSAM sequential files sequentially.  You
   can access records in VSAM indexed and relative files in three ways:
   sequentially, randomly, or dynamically.

   1.  Sequential access--Specify ACCESS IS SEQUENTIAL in the FILE-CONTROL
       entry.

       For indexed files, records are accessed in the order of the key field
       selected (either primary or alternate).

       For relative files, records are accessed in the order of the relative record numbers.

   2.  Random access--Specify ACCESS IS RANDOM in the FILE-CONTROL entry.
       For indexed files, records are accessed according to the value you place in a key field.
       For relative files, records are accessed according to the value you place in the relative key.

   3.  Dynamic access--Specify ACCESS IS DYNAMIC in the FILE-CONTROL entry.

       Dynamic access is a mixed sequential-random access within the same
       program.  Using dynamic access, you can write one program to perform
       both sequential and random processing, accessing some records in
       sequential order and others by their keys.

       For example, suppose you had an indexed file of employee records, and
       the employee's hourly wage formed the record key.  Also, suppose your
       program was interested in those employees earning between $7.00 and
       $9.00 per hour and those earning $15.00 per hour and above. To do
       this, retrieve the first record randomly (with a random-retrieval
       READ) based on the key of 0700.  Next, begin reading sequentially
       (that is, using READ NEXT) until the salary field exceeds 0900.  You
       would then switch back to a random read, this time based on a key of
       1500.  After this random read, switch back to reading sequentially
       until you reach the end of the file.

   

No comments:

Post a Comment