best way to handle table locks

#1
What is the best way to handle table locks in openedge codes.
sample code
============================
Code:
FOR EACH TT-TVS-DETAILS WHERE TT-TVS-DETAILS.T-RCPTNO = '' AND TT-TVS-DETAILS.T-FACNO <> '':
    FIND FIRST TEMP1 WHERE TEMP1.FACNO = TT-TVS-DETAILS.T-FACNO AND (TEMP1.SETAMT > 0 OR TEMP1.Overpmt > 0) NO-LOCK NO-ERROR.
    IF AVAILABLE TEMP1  THEN
    DO:
        FIND FIRST corpdata.serial WHERE corpdata.serial.brcode = mBRANCH AND corpdata.serial.code = "RCP"
            AND corpdata.serial.finbegdt <= mSYSDATE AND CORPDATA.serial.finenddt >= mSYSDATE NO-ERROR NO-WAIT.
        IF NOT LOCKED corpdata.serial THEN
        DO:
            FIND CURRENT corpdata.serial EXCLUSIVE-LOCK NO-ERROR.
            IF AVAILABLE  corpdata.serial THEN
            DO:
                Frcpno = mBRANCH + SUBSTRING(TRIM(STRING(YEAR(mSYSDATE))),3,2) + "R" + STRING(serial.serno + 1, "9999999").
                TT-TVS-DETAILS.T-RCPTNO = Frcpno.
                serial.serno = serial.serno + 1.
            END.
            ELSE 
            DO: 
                MESSAGE "<Serial No> table is use by another user, please wait!"
                      VIEW-AS ALERT-BOX info BUTTONS OK TITLE "InBank Information System".
                RETURN NO-APPLY.
            END.
            RELEASE serial.
        END.
        ELSE
        DO:
            MESSAGE "<Serial> table is locked, try later" VIEW-AS ALERT-BOX info BUTTONS OK TITLE "InBank Information System".
            RETURN NO-APPLY.
        END.
    END.
END.
 
Last edited by a moderator:
Top