HP Basic Reverse file read


Topic author
kwfeese
Contributor
Posts: 10
Joined: Fri Nov 18, 2022 11:34 am
Reputation: 0
Status: Offline

HP Basic Reverse file read

Post by kwfeese » Tue Feb 28, 2023 6:32 pm

I'm trying to read a file in reverse using HP Basic and I came across this paragraph in Guide to OpenVMS File Applications:

8.4.3 Processing Indexed Files
Indexed files provide the most record-processing flexibility. Your program can read existing records from the file in sequential, random access by RFA mode or random access by key mode. RMS also allows you to write any number of new records into an indexed file if you do not violate a specified key constraint, such as not allowing duplicate key values.

In random access by key mode, RMS provides two forward search key options for use with one of four match options (see Section 8.4.3.2). A reverse search key option permits reverse random access when used in combination with either of the two forward search key options.

There was an example but it was written in C and, unfortunately, my current company doesn't have a C license.

Has anyone ever accomplished this and if so can you provide examples?

User avatar

arne_v
Master
Posts: 308
Joined: Fri Apr 17, 2020 7:31 pm
Reputation: 0
Location: Rhode Island, USA
Status: Offline
Contact:

Re: HP Basic Reverse file read

Post by arne_v » Wed May 03, 2023 9:49 pm

Maybe it makes sense to think of RFA as a bookmark to be used to get quickly back where one has been before.
Arne
arne@vajhoej.dk
VMS user since 1986

User avatar

neilrieck
Contributor
Posts: 19
Joined: Tue Jan 10, 2023 10:41 am
Reputation: 0
Location: Waterloo, Ontario, Canada
Status: Offline
Contact:

Re: HP Basic Reverse file read

Post by neilrieck » Mon Jul 31, 2023 4:57 pm

I've got a bunch of BASIC demos posted here. Some of them include accessing data via key.

https://neilrieck.net/demo_vms_html/ope ... index.html

Caveats:
  1. the industry refers to indexed RMS files by the generic name of ISAM (indexed sequential access method)
  2. unlike SQL, you can't just say I want data in reverse order. The Indexed RMS file must have already have a descending key (BASIC and COBOL allowed you to do this directly; other languages like C required you to do it with system call). However, you could also create a temp file with a reverse key, read the data into the temp file, then access the temp file normally (in reverse order). Believe it or not, this is how SQL engines do it when a reverse index hasn't been created.
  3. one of my BASIC demos opens then displays sys$system:SYSUAF.DAT 8-)


hein
Active Contributor
Posts: 41
Joined: Fri Dec 25, 2020 5:20 pm
Reputation: 0
Status: Offline

Re: HP Basic Reverse file read

Post by hein » Mon Jul 31, 2023 10:28 pm

>> you can't just say I want data in reverse order.

Yes you can. Using the REV bit. Me and Elinor thought it would be a neat thing to offer and she implemented it for 7.3-2 if i recall correctly. Within bucket it is easy to see how one could just return the record before the last one right? But what if you get to the beginning of bucket? There is no back pointer, only a next. Well, use the index above e. Up, left, down, last. Recurse as needed.

>>> The Indexed RMS file must have already have a descending key

No it doesn't. See above.

;-)

Hein

Post Reply