READ the last record from VSAM always.

Virtual Storage Access method - ESDS, KSDS, RRDS & LDS. Basic direct access method, Basic sequential -, Queued sequential -, Basic partitioned -, Indexed sequential -, Object - access method.
Post Reply
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

READ the last record from VSAM always.

Post 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.
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: READ the last record from VSAM always.

Post 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).
Sandy
Registered Member
Posts: 51
Joined: Sat Jun 15, 2013 1:07 pm

Re: READ the last record from VSAM always.

Post 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.
Post Reply

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

Register

Sign in

Return to “SMS & VSAM and BDAM, BSAM, QSAM, BPAM, ISAM, OAM.”