I think it would also be useful to add some form of exit routine inside the LOCKWAIT loop. Something like a counter to only allow say 10 attempts at trying to obtain the lock. That way you don't keep looping for ever if some other process which has the lock does not release it for whatever reason. Cheers Peter
-----Original Message----- From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Woodward, Bob Sent: Friday, 8 February 2013 7:02 To: Jon Wells; U2 Users List Subject: Re: [U2] Record locks (Unidata 7.2) With the LOCKED clause included, the READU does not pause. You can put anything you want in that section but just realize that the statement fully executes and proceeds to the next command. If you want to simulate "wait until I obtain the lock" then you just have to create this into a small loop. Something like this: LOCKWAIT: READU xxx FROM yyy, zzz LOCKED Xxx commands, if you want to do anything other than just loop GOTO LOCKWAIT END THEN Xxx got the lock and have read the record so do whatever Xxx<14> = "I was here" END ELSE Xxx got the lock but it's a new record. Xxx = "" Xxx<14> = "I was here" END Do some more stuff. WRITE xxx ON yyy, zzz You don't HAVE to do anything in the locked section other than just goto your label. You could add a small delay, if you wanted, just so your process isn't in a super tight loop chewing up all your computers horsepower. Also, remember, you need to do something with the lock, even if it's a new record. Either a WRITE or RELEASE statement on the zzz key value. BobW -----Original Message----- From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Jon Wells Sent: Thursday, February 07, 2013 12:47 PM To: U2 Users List Subject: Re: [U2] Record locks (Unidata 7.2) What I'm wondering is; what can I put into the 'Xxx what to do if locked' section whereby it waits until the record lock clears, once it clears, set my own lock, read the record, alter the record, and then write the record (which would release my lock)? Thank you, Jon Wells ________________________________ From: "Woodward, Bob" <bob_woodw...@k2sports.com> To: U2 Users List <u2-users@listserver.u2ug.org> Sent: Thursday, February 7, 2013 12:35 PM Subject: Re: [U2] Record locks (Unidata 7.2) Sorry Mecki but I think you have the LOCKED in the wrong place. At least in my version of Unidata. It comes before the THEN segment so the full, proper syntax would be: READU xxx FROM xxx, xxx ON ERROR Xxx what to do if a hard error like file not open END LOCKED Xxx what to do if locked END THEN Xxx what to do if lock is obtained and record is read END ELSE Xxx what to do if lock is obtained but record does not exist. END There is a second format for the READU command but it's a lot easier if the OP just reads about, himself, in the HELP information. HELP UNIBASIC READU from ECL in Unidata will get him that. -----Original Message----- From: u2-users-boun...@listserver.u2ug.org [mailto:u2-users-boun...@listserver.u2ug.org] On Behalf Of Mecki Foerthmann Sent: Thursday, February 07, 2013 12:27 AM To: u2-users@listserver.u2ug.org Subject: Re: [U2] Record locks (Unidata 7.2) The READU statement has a LOCKED clause that is true if a record is locked. You can put all your locking ha logic in there. READU record FROM filevariable,itemID THEN code if record exists and isn't locked (optional) LOCKED code to handle locked record condition (optional) END ELSE code if record doesn't exist (required) END Now if you put that into a loop you can display a message and give the user the option to try again or abort. And if you put the code into a subroutine you can use that in all your programs with a single line like this. CALL SR.READU(record,filevariable,ItemID,Option,Err) On 06/02/2013 21:52, Jon Wells wrote: > Hi all, > > I have not looked at the world of record locks since my R83 Pick days. I'm hoping to add the ability for the program I'm working on to: > > * Check if a record is locked > * Wait until the lock is removed > * Once the lock is removed, or if the record is not locked: > * Lock the record > * Perform the WRITE statement > I'm hoping someone can share an example of how to accomplish this in UniBasic. > > > Thank you, > > > Jon Wells > Campbell University > _______________________________________________ > U2-Users mailing list > U2-Users@listserver.u2ug.org > http://listserver.u2ug.org/mailman/listinfo/u2-users > _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users ------------------------------------------------------------------------------- Note: This email (inc all attachments) is for the use of the intended recipient(s) only. Privileged or confidential information may be contained in this communication. If you have received this email in error, please notify the sender immediately and then delete all copies of this message from your computer network. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this email without the author's prior permission. If you are the intended recipient and you do not wish to receive similar electronic messages from us in future, then please respond to the sender to this effect. We have taken precautions to minimise the risk of transmitting software viruses, but advise you to carry out your own virus checks on this email and its attachments. We do not accept liability for any loss or damage caused by software viruses and do not represent that this transmission is free from viruses or other defects. Firstmac Limited (ABN 59 094 145 963) (AFSL 290600) ------------------------------------------------------------------------------- _______________________________________________ U2-Users mailing list U2-Users@listserver.u2ug.org http://listserver.u2ug.org/mailman/listinfo/u2-users