Monday, November 21, 2011

Allocation of file - SELECT Statement


 (ENVIRONMENT-> INPUT-OUTPUT-> FILE-CONTROL)

SELECT [OPTIONAL] FILENAME ASSIGN to DDNAME                           =>ALL Files
ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVE                           =>ALL Files
ACCESS IS SEQUNETIAL/RANDOM/DYNAMIC                                     =>ALL Files
RECORD KEY IS FILE-KEY1                                                             =>KSDS
RELATIVE KEY IS WS-RRN                                                             =>RRDS
ALTERNARE RECORD KEY IS FILE-KEY2 WITH DUPLICATES                   =>KSDS with
ALTERNARE RECORD KEY IS FILE-KEY3 WITHOUT DUPLICATES             =>AIX
FILE STATUS IS WS-FILE-STAT1                                                     =>ALL Files
                     [,WS-FILE-STAT2]                                                  =>VSAM Files
                  

SELECT Statement- OPTIONAL Clause

          This can be coded only for input files. If OPTIONAL is not coded, then the input file is expected to present in JCL. If not, an execution error will occur.
If OPTIONAL is coded, then if the file is not mapped in JCL, it is considered as empty file and the first read results end of file.
The file can also be dynamically allocated instead of static allocation in JCL.

SELECT Statement- ASSIGN TO
FILENAME is the logical name used inside the program and DDNAME is the logical name in the JCL, mapped with physical dataset. DDNAME can be prefixed with ‘S-‘ to indicate QSAM file, ‘-AS’ to indicate ESDS file and with no prefix to indicate KSDS/RRDS file.

JCL Step executing the program should have a dataset with DDNAME as label
//DDNAME  DD DSN=BPMAIN.EMPLOYEE.DATA,DISP=SHR

SELECT Statement-ORGANIZATION

It can be SEQUENTIAL (PS or VSAM ESDS), INDEXED (VSAM KSDS), RELATIVE (VSAM RRDS). Default is Sequential.

SELECT Statement-ACCESS MODE

SEQUENTIAL.

It is default access mode and it is used to access the records ONLY in sequential order. To read 100th record, first 99 records need to be read and skipped.

 

RANDOM.

Records can be randomly accessed in the program using the primary/alternate key of indexed file organization or relative record number of relative organization.100th record can directly be read after getting the address of the record from the INDEX part for INDEXED files.100th record can directly be read for RELATIVE files even without any index.

 

DYNAMIC.

It is mixed access mode where the file can be accessed in random as well as sequential mode in the program.
Example: Reading the details of all the employees between 1000-2000. First randomly access 1000th employee record, then read sequentially till 2000th employee record. START and READ NEXT commands are used for this purpose in the procedure division.

SELECT Statement-RECORD KEY IS                    
It is primary key of VSAM KSDS file. It should be unique and part of indexed record structure.

SELECT Statement-ALTERNATE RECORD KEY IS

This phrase is used for KSDS files defined with AIX. Add the clause WITH DUPLICATES if the AIX is defined with duplicates.
Referring to VSAM basics, every alternate index record has an associated   PATH and the path should be allocated in the JCL that invokes this program.
The DDNAME of the path should be DDNAME of the base cluster suffixed with 1 for the first alternate record clause, suffixed with n for nth ALTERNATE RECORD KEY clause in SELECT clause.

SELECT Statement-FILE STATUS IS WS-FILE-STAT1,WS-FILE-STAT2

WS-FILE-STAT1 should be defined as PIC X(02) in working storage section. After every file operation, the file status should be checked for allowable values.
WS-FILE-STAT2 can be coded for VSAM files to get the VSAM return code (2 bytes), VSAM function-code (1 byte) and VSAM feedback code (3 bytes).
This is a 6- byte field in working storage.

RESERVE Clause.
RESERVE clause [RESERVE integer AREA ] can be coded in the SELECT statement. The number of buffers to be allocated for the file is coded here.
By default two buffers will be allocated if the clause is not coded. Since similar option is available in JCL, this is not coded in program.

RESERVE 1 AREA allocates one buffer, for the file in the SELECT statement.


No comments:

Post a Comment