140 likes | 654 Views
VSAM ACCESS METHODS. Sequential Start at the beginning of the file and read the records in sequence by either a primary key or a foreign key (Alternate Index) Random Read a particular record from the file (usually by primary key) Dynamic
E N D
VSAM ACCESS METHODS • Sequential • Start at the beginning of the file and read the records in sequence by either a primary key or a foreign key (Alternate Index) • Random • Read a particular record from the file (usually by primary key) • Dynamic • Read a particular record from the file and then sequentially until a particular condition is reached. Commonly used with non-unique foreign keys (Alternate Index)
SELECT Statements Sequential Access -By primary key SELECT file-name ASSIGN TO DA-jclname ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY is record-key FILE STATUS is status-name. Where record-key is in the 01 layout immediately under FD for the file-name. The Primary Key status-name is declared in working storage as PIC XX. The file status line is optional
SELECT Statements Sequential Access -By foreign key (alternate index) SELECT file-name ASSIGN TO DA-jclname ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY is record-key ALTERNATE KEY is ai-name WITH DUPLICATES FILE STATUS is status-name. Where ai-name is in the 01 layout immediately under the FD for the filename WITH DUPLICATES is used if alternate index is nonunique (in the Define Alternate Index)
SELECT Statements Random Access - by Primary Key SELECT file-name ASSIGN TO DA-jclname ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY is record-key FILE STATUS is status-name. Change from sequential access: ACCESS is SEQUENTIAL to ACCESS is RANDOM
SELECT Statements Random Access - by Alternate Key SELECT file-name ASSIGN TO DA-jclname ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY is record-key ALTERNATE INDEX IS ai-name WITH DUPLICATES FILE STATUS is status-name. Change ACCESS is SEQUENTIAL to ACCESS is RANDOM
SELECT Statements Dynamic Access - by Alternate Index (can also be used with primary keys but generally is NOT) SELECT file-name ASSIGN TO DA-jclname ORGANIZATION IS INDEXED ACCESS IS RANDOM RECORD KEY is record-key ALTERNATE INDEX IS ai-name WITH DUPLICATES FILE STATUS is status-name. Change: ACCESS is SEQUENTIAL to ACCESS is DYNAMIC
The Start Statement • Used with sequential access by AI • Initialize the AI to spaces (PIC X) or zeros (PIC 9) to start reading the data file at the start by AI • Generally used immediately after the opens
The Start Statement MOVE spaces/zeroes TO alternate key in FD START file-name KEY > alternate key in FD For Example: Assume TEXT-COPY is the file name The Alternate Key in the SELECT statement is AI-KEY Then the START statement would be: MOVE SPACES TO AI-KEY. START TEXT-COPY KEY > AI-KEY.
READ Statements Sequential Read by Primary Key READ file-name INTO file-layout AT END MOVE ‘Y’ to end-of-file switch.
READ Statements RANDOM Read by Primary Key MOVE something TO record-key. READ file-name INTO file-layout KEY IS record-key INVALID KEY imperative statements NOT INVALID KEY imperative statements END-READ. Invalid key/Not invalid key clauses are optional Can be checked with status codes
READ Statements Dynamic Read by Alternate Key 1) First read is a random read by alternate index 2) Subsequent reads is a sequential read
READ Statements RANDOM Read by Alternate Key MOVE something TO record-key. READ file-name INTO file-layout KEY IS alternate-key INVALID KEY imperative statements NOT INVALID KEY imperative statements END-READ. Invalid key/Not invalid key clauses are optional Can be checked with status codes
READ Statements Dynamic Read (Sequential portion) by Alternate Key READ file-name NEXT RECORD INTO file-layout AT END MOVE ‘Y’ to end-of-file switch.
JCL Notes For any VSAM file Previously created with IDAMS - DEFINE CLUSTER //GO.JCLNAME DD DSN=clustername,DISP=SHR (or OLD) For any VSAM file with ALTERNATE KEY clause in SELECT //GO.JCLNAME DD DSN=clustername,DISP=SHR (or OLD) //GO.JCLNAME1 DD DSN=pathname,DISP=SHR (or OLD)