by BillyBoyo » Sun Mar 11, 2012 6:51 pm
You are talking about a VSAM KSDS on a Mainframe, we assume. We also assume you are using Cobol.
You establish a file a being a KSDS with RANDOM access.
You open the file.
You populate a key field and issue a READ for that key. You can tell that you were able to read with that key, or that you weren't.
You cannot tell which record, as far as relative sequence in the file, you read.
To read another record with a lower key, all you need to do is set up the key and issue the read. Same for a record with a higher key.
There is nothing you can set or reset relating to the KSDS (or any VSAM file).
This is why we cannot make good sense of your question.
Although you can do RANDOM access with keys in any order, where possible you should do it in key order, as the program will run better (there will be no occasion where a buffer is filled, discarded because of a lower key, and then the same data is again accessed later, so ends up being physically read again).