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.
READ the last record from VSAM always.
- Robert Sample
- Global Moderator
- Posts: 1896
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: READ the last record from VSAM always.
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).
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.
Thanks. This is what I needed. This works. Thank you again.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.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute