karthi
karthi

Reputation: 1109

How to get highest key value in between the given range in VSAM

I want to get the maximum key value in between the given range.(Maximum value between 1000 to 2000). Below My VSAM data.

Key

1001

1002

1003

2001

2006

Now I have moved 1999 to key and start search

START VSAM-KSDS-FILE    KEY IS > 1999

Then I have read next record but I am getting 2001 But I want the maximum key value of 1003.(Maximum value between 1000 to 2000)

How can I get this value?

Upvotes: 0

Views: 1107

Answers (2)

DuncanKinnear
DuncanKinnear

Reputation: 4643

Before we got READ PREVIOUS in RM/Cobol (which was a god-send), we used a 'reverse key' for this sort of thing.

For example, let's assume that your key is only 4 digits. You would have a REV-KEY field in the record which was equal to 10000 minus the real key. Define that as an alternate key and you can start on that key with REV-KEY set to 10000 - 1999.

Of course, if you don't have the ability to change the structure of the file, then there's no way to do it without READ PREVIOUS.

Upvotes: 2

Bill Woodger
Bill Woodger

Reputation: 13076

It saves a lot of time if you already know something rather than having to go searching for it.

So, don't lose the value, keep it, and you never have to search for it.

Have a "Control Record" within the file, which contains the value you want, or have a separate "Control File" contain the Control Record.

You do check that all your data is for the same date, don't you? The "Business Date" or "Data Date"? So if using the Control File, that file will of course contain the Business/Data Date which you will match to your existing Business/Data Date on your KSDS.

No-one on a Mainframe just assumes that everything is correct. Do they?

Upvotes: -1

Related Questions