Wednesday, May 27, 2009

10. COBOL VSAM Considerations

SELECT CLAUSE

SELECT file ASSIGN TO DDNAME / AS-DDNAME

ORGANIZATION IS SEQUENTIAL/INDEXED/RELATIVE
ACCESS MODE IS SEQUENTIAL/INDEXED/DYNAMIC
RECORD KEY IS primary Key Dataname
ALTERNATE KEY IS Alternate Key Dataname [With Duplicates]
FILE STATUS IS status-key.


Example 10.1 SELECT clause for VSAM datasets

status key=Cobol, VSAM
x(2) 9(2) - Return code
9(1) - Junction code
9(3) - Feedback code
FD Entry

Should have the record structure

If KSDS then key field must match with length and position of KEYS parameter in DEFINE CLUSTER information
File Processing

Regular COBOL file handling commands
Alternate index processing :

In JCL there must be a DD statement for base cluster and one or more DD statement for alternate index path name.

Note: There is no COBOL standard for assigning ddnames to alternate indexes, so a quasi-standard has emerged whereby a sequential number is appended to the eighth character of the base cluster ddname.

//LIBMAST DD DSN=DA0001T.LIB.KSDS.CLUSTER,
// DISP=SHR
//LIBMAST1 DD DSN=DA0001T.LIB.KSDS.NAME.PATH,
// DISP=SHR
//LIBMAST2 DD DSN=DA0001T.LIB.KSDS.DEPT.PATH,
// DISP=SHR
Example 10.2 JCL to access AIX

Remark:
No matter how many alternate indexes you specify in the program, there’s only one ASSIGN clause pointing to the ddname of the base cluster.

SELECT file ASSIGN TO LIBMAST

RECORD KEY IS ............
ALTERNATE KEY IS .........
[WITH DUPLICATES]

Example 10.3 Cobol SELECT clause for AIX

FD : Should have record description having primary key dataname and alternate key
dataname


KEY of reference : READ filename
KEY IS primary/alternate key
dataname
Key of Reference.

The key that is currently being used to access records is called the key of reference. When the program opens the dataset, the primary key becomes, by default, the key of reference. The primary key remains the key of reference when accessing records until it is changed. To start accessing records by an alternate index key, you merely change the key of reference by using the KEY phrase as part of one of the following statements.

A random READ statement, for example

READ EMP-MAST KEY IS EMP-NAME
Example 10.4 READ

A sequential READ statement, for example

READ EMP-MAST NEXT
KEY IS EMP-NAMEA

Example 10.5 READ for Accessing AIX

START statement, for example

START EMP-MAST
KEY IS EQUAL TO EMP-NAME.
Example 10.6 START verb

key-1 key-2 Cause
Successful Completion:
0 0 No further information,
2 Duplicate key detected.
4 Wrong fixed-length record.
5 Data set created when pened.With
sequential VSAM datasets,0 is returned.
7 CLOSE with NO REWIND or
REEL, for non-tape.
End-of-file.
1 0 No further information.
4 Relative record READ outside
dataset boundary.

Invalid key.
2 1 Sequence error.
2 Duplicate key.
3 No record found.
4 Key outside boundary of dataset.

Permanent I/O error :
3 0 No further information.
4 Record outside dataset boundary.
5 OPEN and required dataset not found.
7 OPEN with invalid mode.
8 OPEN of dataset closed with LOCK.
9 OPEN unsuccessful because of
conflicting dataset attributes.

Logic error :
4 1 OPEN of dataset already open.
2 CLOSE for dataset not open.
3 READ not executed before REWRITE.
4 REWRITE of different-record size.
6 READ after EOF reached.
7 READ attempted for dataset not opened I-O
or INPUT.
8 WRITE for dataset not opened OUTPUT,I-O
or EXTEND.
9 DELETE or REWRITE for dataset not opened I-O.


Specific compiler-defined conditions :
9 0 No further information.
1 VSAM password failure.
2 Logic error.
3 VSAM resource not available.
4 VSAM sequential record not available.
5 VSAM invalid or incomplete dataset information.
9 6 VSAM-no DD statement.
7 VSAM OPEN successful.Dataset integrity verified.
VSAM I/O error processing

I/O error handling is one vital area where VSAM dataset processing differs from non-VSAM dataset processing. When processing non-VSAM datasets, most programmers code their application programs to ignore errors, because the access method would abend the program if a serious I/O error occurs. Not so when processing VSAM datasets.
The COBOL FILE STATUS Key

VSAM places program control in the hands of the programmer, not the O/S. For this reason, it is important to check the COBOL status key designated in the FILE STATUS clause after every I/O operation. For some error keys you'll want to abend the program immediately; for others you can just display the key, the record, and an informative message and continue processing.
For these status key values, continue processing normally :
00 successful I/O.
02 duplicate alternate key encountered (expected).
10 end of file.

For these status key values, bypass the record, display pertinent information, and continue processing :

21 Input record out of sequence.
22 duplicate primary key or unique alternate key
encountered (un-expected).
23 record (or Key) not found.

Note: You may want to have the program count the number of times these key values are returned and terminate the program if the counter reaches an unacceptable number, which would likely to indicate that your input is bad

For the following status key values, terminate the program :

24 out-of-space condition (KSDS or RRDS).
30 Nonspecific I/O problem.
34 out-of-space condition(ESDS).
49 REWRITE attempted; dataset not opened for I-O.
90 Dataset unusable or logic error.
92 logic error.
93 Resource not available.
94 current record pointer undefined.
95 Nonzero HURBA for OPEN OUTPUT.
96 No corresponding JCL DD statement.
97 If your shop has enabled the implicit VERIFY command, this means
that the dataset was opened after and implicit VERIFY, and you can
continue processing.

Back to VSAM index

1 comment:

Anonymous said...

the post is really useful.. especially the dd name format for alt indx path is new one I read and its correct.