Whenever you FIND
a record you can aquire a lock of it.
NO-LOCK: Used for read only operations. If you do a FIND <record> NO-LOCK
you cannot in any way modify the record.
FIND FIRST Customer NO-LOCK NO-ERROR.
EXCLUSIVE-LOCK: Used for updates and deletes. If you do this you will "own" the record and nobody else can modify it or delete it until you're done. They can read it (with no-lock) as long as you haven't deleted it.
FIND FIRST Customer EXCLUSIVE-LOCK NO-ERROR.
SHARE-LOCK: Avoid at all cost. This will cause mad headache.
FIND FIRST Customer EXCLUSIVE-LOCK NO-ERROR. //Do this instead.
UPGRADING your lock from NO-LOCK to EXCLUSIVE-LOCK
You can easily move from a NO-LOCK
to an EXCLUSIVE-LOCK
if the need to modify a record has arisen:
FIND FIRST Customer NO-LOCK NO-ERROR.
// Some code goes here
// Now we shall modify
FIND CURRENT Customer EXCLUSIVE-LOCK NO-ERROR.
You can go from EXCLUSIVE-LOCK to NO-LOCK as well.
LOCKED RECORDS
Whenever other users might aquire a lock of a record you better take this possibility into account. Collisions will occur!
It's better to handle this programmatically using the NO-WAIT
statement. This tells the AVM to just pass the FIND if the record is locked by somebody else and let you handle this problem.
FIND FIRST Customer EXCLUSIVE-LOCK NO-ERROR NO-WAIT.
/* Check for availability */
IF AVAILABLE Customer THEN DO:
/* Check that no lock (from somebody else) is present */
IF NOT LOCKED Customer THEN DO:
/* Do your stuff here */
END.
ELSE DO:
MESSAGE "I'm afraid somebody else has locked this record!" VIEW-AS ALERT-BOX ERROR.
END.
END.