Progress
Programming
Handbook


Updating Browse Rows

By default, Progress handles the process of updating data in an updatable browse. Assuming that the browse starts with the record in NO–LOCK state, Progress follows these steps:

The 4GL programmer also has the option to disable this default behavior and programmatically commit the changes by way of a trigger on the ROW–LEAVE event. First, you must supply the NO–ASSIGN option in the DEFINE BROWSE statement.

The following code example shows how to use a ROW–LEAVE trigger:

p-br08.p
DEFINE QUERY q1 FOR customer SCROLLING. 
DEFINE BROWSE b1 QUERY q1 DISPLAY cust-num name credit-limit  
    ENABLE credit-limit WITH 10 DOWN SEPARATORS NO-ASSIGN 
    TITLE "Update Credit Limits". 
DEFINE FRAME f1 
    b1 
        WITH SIDE-LABELS ROW 2 CENTERED NO-BOX. 
ON ROW-LEAVE OF BROWSE b1 DO: 
    IF INTEGER(customer.credit-limit:SCREEN-VALUE IN BROWSE b1) > 100000  
    THEN DO: 
        MESSAGE "Credit limits over $100,000 need a manager’s approval."  
            VIEW-AS ALERT-BOX ERROR BUTTONS OK  
            TITLE "Invalid Credit Limit". 
       DISPLAY credit-limit WITH BROWSE b1. 
       RETURN NO-APPLY. 
    END. 
    DO TRANSACTION: 
        GET CURRENT q1 EXCLUSIVE-LOCK NO-WAIT. 
        IF CURRENT-CHANGED(customer) THEN DO: 
             MESSAGE "The record changed while you were working." 
                 VIEW-AS ALERT-BOX ERROR BUTTONS OK TITLE "New Data".  
             DISPLAY credit-limit WITH BROWSE b1. 
             RETURN NO-APPLY. 
        END.  
        ELSE ASSIGN INPUT BROWSE b1 credit-limit.  
    END. /* TRANSACTION */ 
    GET CURRENT q1 NO-LOCK.  
END. 
OPEN QUERY q1 FOR EACH customer NO-LOCK. 
ENABLE ALL WITH FRAME f1. 
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW. 

The ROW–LEAVE trigger checks for a special condition where the new data should not be committed to the database. If it encounters such data, the trigger is canceled without any writes taking place. If the data is valid, the GET CURRENT statement is used to re-get the current record with an EXCLUSIVE-LOCK NO–WAIT. It also uses the CURRENT–CHANGED function to ensure that another user has not changed the record since the query first retrieved it. Note that the lock must be downgraded manually at the end of the trigger with another GET CURRENT statement.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095