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

Reply via email to