Search code examples
openedgeprogress-4gl

How to implement FIND CURRENT & CURRENT-CHANGED in Progress4GL?


I tried reading the Progress knowledge base for FIND CURRENT statement. It didn’t help much. Can anyone tell me what does FIND CURRENT statement do and why/in which locking scenarios we use it? Also, it would be really helpful if it can be explained with the simple example. Note: Any example using the Sports database, which is not shown in the knowledge base. I implemented the below code, but it doesn’t seems to reach the CURRENT-CHANGED statement when I compile the procedure ( I’m using the DB I’ve created with the logical name “Personal”).

Thank you.

 FIND FIRST personal WHERE personal firstNAME = "Ganesh" EXCLUSIVE-LOCK.
 UPDATE personal.
 FIND CURRENT personal EXCLUSIVE-LOCK.
 UPDATE personal
 IF CURRENT-CHANGED personal THEN DO:
    MESSAGE "Record is changed"
    VIEW-AS ALERT-BOX INFORMATION BUTTONS OK
    DISPLAY personal.
 END

Solution

  • Your code example is not compilable as it stands. You seem to be confusing database name "personal" with a table name and then specifying a field name with a space between the table name and the field name. Or something like that.

    Normally you do not have any need to specify the database name in your code. One case when you might wish to do that is if you are connected to multiple databases with identically named tables - but that isn't your situation. If you were to be doing that the correct syntax to use is:

    dbname.tablename.fieldname

    One situation when you might use FIND CURRENT is when you think that other users might be changing the data while you are reviewing it in a NO-LOCK status.

    Another case might be to use FIND CURRENT if you want to upgrade the lock without having to specify the WHERE clause all over again (the example below is very simple so hardly worth saving the effort but you could have something a lot more complex).

    For instance:

    find customer no-lock where customer.custNum = 1.
    display customer.custName.
    pause.
    
    /* if you try to update the name at this point you will fail because the record is not locked */
    
    find current customer exclusive-lock.  /* upgrade from no-lock to an exclusive-lock */
    
    if current-changed customer = false then
      update customer.custName.
     else
      do:
        message "someone else changed things while you were reviewing the record :(".
      end.
    

    This is also explained here:

    https://docs.progress.com/bundle/openedge-abl-reference-117/page/CURRENT-CHANGED-function.html