Kbase P48336: How to make user A aware in real time that record is changed?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/2007 |
|
Status: Unverified
GOAL:
How to make a user aware that a record has changed since the last FIND?
FIX:
Use FIND CURRENT record and use the CURRENT-CHANGED function to let the user know whether the record has changed since last accessed.
The following code demonstrates the optimistic locking scheme. Under this scheme, a record is accessed NO-LOCK initially and modifications to the record are done in the record local buffer. Before saving these changes, a check is made to see if another user changed the record. This code uses the AVAILABLE and LOCKED functions to advise the user whether the record is available or locked:
FIND FIRST Customer WHERE CustNum = 444 NO-LOCK NO-WAIT NO-ERROR.
IF NOT ERROR-STATUS:ERROR AND NOT LOCKED(Customer) THEN DO:
/* No error was generated...Try to get record exclusive lock */
FIND CURRENT Customer EXCLUSIVE-LOCK NO-WAIT NO-ERROR.
IF AVAILABLE(Customer) THEN DO:
/* Record is available */
IF CURRENT-CHANGED Customer THEN
MESSAGE "the record has changed since last read"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
ELSE
/* Record has not changed since last FIND */
/* Put code to commit the record changes here */
END.
ELSE DO:
/* Record is NOT available */
MESSAGE "record is not available now"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
IF LOCKED Customer THEN
MESSAGE "record is currently locked"
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END. /* IF NOT ERROR-STATUS */
ELSE
/* An error was generated finding the record...display it */
MESSAGE ERROR-STATUS:GET-MESSAGE(1)
VIEW-AS ALERT-BOX INFO BUTTONS OK.