Page 1 of 1

READ the last record from VSAM always.

Posted: Tue Jan 15, 2019 11:57 am
by Sandy
Hi,

There is a VSAM file I am using. I'm reading this VSAM with alternate key but this gives more than one record from the VSAM. Could you please guide on what logic should I use so that I can to the last record every time for the given key.

Any help in this regard is appreciated.

Re: READ the last record from VSAM always.

Posted: Tue Jan 15, 2019 6:16 pm
by Robert Sample
The answer depends partly what you mean by "last record".

If by "last record" you mean the last alternate index primary key, just loop through the READ, when you get to end of file, that's the last alternate index primary key.

If by "last record" you mean the associated base cluster primary key with the highest value, you will need to initialize a SAVEKEY. Loop through the alternate index READ and if the primary key is greater than the SAVEKEY value, replace SAVEKEY. When you get to end of file, you have the primary key with the highest value in SAVEKEY.

And note that since alternate index primary keys are added to the end of the alternate index record, using these two methods will return different results (unless you run your program immediately after a rebuild of the alternate index and before any updates have been done, in which case the two methods will return the same record).

Re: READ the last record from VSAM always.

Posted: Fri Jan 18, 2019 2:15 pm
by Sandy
Robert Sample wrote: Tue Jan 15, 2019 6:16 pmIf by "last record" you mean the associated base cluster primary key with the highest value, you will need to initialize a SAVEKEY. Loop through the alternate index READ and if the primary key is greater than the SAVEKEY value, replace SAVEKEY. When you get to end of file, you have the primary key with the highest value in SAVEKEY.
Thanks. This is what I needed. This works. Thank you again.