Pascal and User-action routines

Post Reply

Topic author
willemgrooters
Valued Contributor
Posts: 87
Joined: Fri Jul 12, 2019 1:59 pm
Reputation: 0
Location: Netherlands
Status: Offline
Contact:

Pascal and User-action routines

Post by willemgrooters » Mon Nov 30, 2020 3:39 pm

In a Pascal program, I'd like to use an indexed-sequential file with multiple keys, one consists of two fields in the record:

Code: Select all

    TMeta = record
        Date: integer;   { date (yyyymmdd }       
        SeqNr: integer; { seqnr in date }       
        PostID: integer;
    ;
Primary key is Date (yyyymmdd) and SeqNr, PostID is alternate key;

To get TMeta on a date, or PostID alone, I can simply open the file for keyed access, find the record and get the data. If more than one reference exists for one Date, I can of course read on until I access the right system, but I prefer to access is directly, so I need a user-action; also for adding a particular record (I guess). The VSI PASCAL documentation gives me too little information in what I need to set. Does anyone have a reference on how to use a user-action routine for this type of access?

User avatar

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

Re: Pascal and User-action routines

Post by arne_v » Mon Nov 30, 2020 9:39 pm

Can you explain more about what you are trying to do?

Pascal IO or direct RMS calls? Which calls? What user action?
Arne
arne@vajhoej.dk
VMS user since 1986


jreagan
VSI Expert
Master
Posts: 134
Joined: Tue Dec 01, 2020 8:40 am
Reputation: 0
Status: Offline

Re: Pascal and User-action routines

Post by jreagan » Tue Dec 01, 2020 8:48 am

They are documented in the User Manual, section 7.2 User-Action Functions

You can use the [KEY(0)] attribute on the 'date' integer field. Then you an use the FINDK function to find the record. Your secondary key is 8 bytes long? You can add another XABKEY with the user-action routine but without the additional key info, I'm not sure if FINDK would work on that too. Are you wanting to FINDK or do you want to use a $GET with KEYED access.


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

Re: Pascal and User-action routines

Post by hein » Fri Dec 25, 2020 5:45 pm

Ha die Willem. De beste wensen voor het nieuw jaar.

Is this still an active query?
With a user action routine you can get to FAB/RAB and call the low level OpenVMS RMS routines such as $GET directly.
But then you walk away from the language making maintenance much harder and from a lot of (error handling) help from the language RTL. Typically NO low level $PUT is needed, just use the language WRITE function providing the record and RMS will sort it out.

What you want to use is FINDK such as John indicated, but maybe you want better keys on you indexed files.
Judging by the comment, SeqNr is only unique within a date. Correct?
Surely Date+SeqNr is defined to be unique, and the primary key for the file. Is it?
Is PostID unique overall, or also just within the date.

I suggest you recreate the file with an FDL file redefining new alternate key as needed
Just make it be Date+PostID and perhaps also PostID+Date.

Please give more clear desired lookup examples if follow up is desired.
You wrote " until I access the right system," - how is that determined? PostID? SeqNr?

Instead of FINDK with Equal on 8 bytes, and sequentially scanning for the right one, can you not just provide a 12 byte structure and find it directly?

Now how about ORDER within a date? Is that important? Does SeqNr ever get larger than 255?
Exactly HOW is SeqNr added as a segment for the PK?
Is the PK perhaps simply 8+4 = 12 bytes starting at byte 0?
Well, that does NOT sort properly! RMS woudl see the above as a simple string of bytes, but the significance is reversed for the integer bytes!
So the PK key should really be defined with 5 segments as (offset,length) : 0,8 - 11,1 - 10,1 - 9,1 - 8,1
That would be just for the file. No need to let Pascal in on this little secret.

Ditto for PostID

Fwiw - as much a INTEGER is a natural programmers choice for a Sequence Number or similar - you may want to reconsider that and simply make is a 4 or 10 byte (zero filled?) numeric string! So much more practical in the long run.

Groetjes,
Hein


Topic author
willemgrooters
Valued Contributor
Posts: 87
Joined: Fri Jul 12, 2019 1:59 pm
Reputation: 0
Location: Netherlands
Status: Offline
Contact:

Re: Pascal and User-action routines

Post by willemgrooters » Wed Jan 06, 2021 1:38 pm

Ha Hein:

Ook voor jou (en je naasten) de beste wensen voor 2021.

Yeah, it is still a valid matter. I've done SOME work on this is a long past era but never as deep as I need to go now.
Of course, there are several ways to achive what I want. but the VSI PASCAL documentation is not all too clear on the matter and when searching the Internet, I don't get the answers I need. I can get around them some way, like creating the files using FDL in stead of using a program, access in the current phase is not very complex. However, for what I have in mind I may need to have some more influence on accessing the data.

Another issue MIGHT be requirement for performance. Not a real issue at the moment, but for what I might want to achieve, it will matter. And there user-actions routines may be required.

So some more knowlegde of the internals of RMS is welcome.

Contact me off-line for more details.


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

Re: Pascal and User-action routines

Post by hein » Thu Jan 07, 2021 12:19 am

Creating an application file through and FDL file is MUCH preferable over using some clumsy often restricted language constructs.

It is typically so much harder to (get permission to) change and rebuild a program vs tweak an FDL file and/or DCL script.

You could call FDL from the program, but it is preferable - more flexible - to create it outside notably for future tuning purposes. That 'influence accessing the data" you mention perhaps.
You need an FDL anyway for your monthly or yearly converts
Just keep as much out of the code as you can.

I agree you MIGHT need a useraction routine for some performance options such as RAB$V_NQO - No query lock. or the RRL+NLK workaround. At that point you'd better know what you are doing and if/when you do, I suspect that the manuals will proof to be good enough after all.

Groetjes,
Hein.


Topic author
willemgrooters
Valued Contributor
Posts: 87
Joined: Fri Jul 12, 2019 1:59 pm
Reputation: 0
Location: Netherlands
Status: Offline
Contact:

Re: Pascal and User-action routines

Post by willemgrooters » Tue Mar 09, 2021 5:29 am

Took your advise and redesigned key structure, saves me a lot of trouble indeed :)

Post Reply