Trapping a record Lock in FOR EACH

manujmathew

New Member
Hi,
I have a say,

FOR EACH customer where customer.cust = 1.
assign customer.name = "test".
end.

Now in the above code i'm not using any locks.if somehow this code when run in batch process gets locked giving error saying this record is locked by so and so user at this point and gets aborted.i want to bypass that, and get the error message saying its locked as an alert in error file,I can't use no-wait and if locked statement since i'm not using find first statement,Is there any other way where i can use a find first without changing the above code or any other way other than using find.


Thanks & Regards
Manu.
 
Well, you ARE using a lock in the example given. It's a SHARE-LOCK, which is the default if you don't specify one.

Regardless, if you want to check on locking you need to use NO-WAIT, which means you need a FIND. So, I would change the code to something like:

DEFINE BUFFER b-customer FOR customer.

FOR EACH customer NO-LOCK:

FIND b-customer WHERE ROWID(b-customer) = ROWID(customer) EXCLUSIVE-LOCK NO-ERROR NO-WAIT.
IF LOCKED b-customer THEN
DO:
MESSAGE
"locked!"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
ELSE
DO:
b-customer.NAME = "test"
END.
END.
 
Back
Top