Page 1 of 1

What is INVALID key in VSAM?

Posted: Fri Oct 16, 2015 2:14 pm
by riathane
What is INVALID key in VSAM? And when do we need it?

In one of my programs, I've this:

Code: Select all

READ IN-ILEA 
INTO IN-RECORD 
INVALID KEY 
MOVE 'pass' TO WS-OUT 
In above code, IN-FILE is a KSDS file, ORGANIZATION IS INDEXED and ACCESS IS RANDOM. With this code, when INVALID KEY will execute and what does INVALID KEY do here?

Re: What is INVALID key in VSAM?

Posted: Fri Oct 16, 2015 2:53 pm
by William Collins
When the key is not found on the file. You also need to use END-READ, unless you have a very old COBOL, when you'd use a full-stop/period.

To my mind it is much better to use the FILE STATUS clause on the SELECT, and an 88 on the file-status field you define (one per file). "23" is "record not found".

Re: What is INVALID key in VSAM?

Posted: Fri Oct 16, 2015 6:07 pm
by Robert Sample
To my mind it is much better to use the FILE STATUS clause on the SELECT
And Enterprise COBOL supports extended file status bytes for VSAM which give you plenty of helpful information if your program doesn't run correctly.