Transaction lock not releasing on the last record

Status
Not open for further replies.
D

dayv2005

Guest
I have an include file with 2 functions. One of the functions works perfectly fine so I won't include it in this. I will include the function that is causing the issue.

The ss_update function is the one causing me issue and not releasing the lock as I assumed it would. I finally got to work this way adding the find current screenstate no-lock. statement. I wondering if someone can explain this to me and if there is a better way to handle this situation.

FUNCTION ss_update RETURNS INTEGER
( INPUT iUserName AS CHAR,
INPUT iScreenName AS CHAR,
INPUT iWidgetName AS CHAR,
INPUT iWidgetValue AS CHAR ):

DEFINE VARIABLE retStatus AS INTEGER NO-UNDO.


FIND ScreenState EXCLUSIVE-LOCK WHERE ScreenState.userName = iUserName AND
ScreenState.screenName = iScreenName AND
ScreenState.widgetName = iWidgetName NO-ERROR.
IF AVAIL ScreenState THEN
DO:
IF ScreenState.widgetValue <> iWidgetValue THEN
DO:
ASSIGN
ScreenState.widgetValue = iWidgetValue.
END.
retStatus = 1.
END.
IF NOT AVAIL ScreenState THEN
DO:
CREATE ScreenState.
ASSIGN
ScreenState.screenStateId = NEXT-VALUE(seq-ScreenStateId)
ScreenState.userName = iUserName
ScreenState.screenName = iScreenName
ScreenState.widgetName = iWidgetName
ScreenState.widgetValue = iWidgetValue.

retStatus = 2.
END.

/* This was added to release the lock. */
FIND CURRENT screenstate NO-LOCK.

RETURN retStatus.

END FUNCTION.


I have code that will call the update function several times in a row. Like this...

ss_update(USERID(LDBNAME(1)), "FindComp2.w", "t-ActiveOnly", t-ActiveOnly:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "t-BadAdd", t-BadAdd:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "LastCompany", company.companyId).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "rs-Filter", rs-Filter:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "cb-Salesman", cb-Salesman:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "cb-Search", cb-Search:SCREEN-VALUE).
ss_update(USERID(LDBNAME(1)), "FindComp2.w", "scr-Search", TRIM(scr-Search:SCREEN-VALUE)).


The problem I was having was that progress wasn't releasing the lock from the last called ss_update function. I had to add find current screenstate no-lock to downgrade the lock. This just seems ugly and not properly coded and was wondering why this happened and what is the proper way to handle this such issue.

Continue reading...
 
Status
Not open for further replies.
Top