Will WAIT-FOR statement release a record from the buffer ?

Posted by anzeljamal on 25-Nov-2014 02:12

I have a scenario where a set of records are displayed in the browse which has a default no-lock associated with it. Once you double click a record on the browse, it will call a procedure which fetches the record in the share-lock and then will call another procedure which will enable a frame where the record is displayed to update. Once i modify the data and try to press F2, the record is unable to update, showing an error as "<table> record has no-lock status, update to field not allowed".
Once i did an analysis through promon, I found out that just above the WAIT-FOR statement, the record was in share-lock and after the WAIT-FOR statement is executed the record is getting released and going into a no-lock status. If i try to fetch the record in exclusive-lock instead of share-lock, then when the WAIT-FOR statement is executed, the record is going into Limbo lock. As per my understanding, limbo lock happens when the records gets released inside a transaction and the transaction is still active. As it is still in Limbo lock, i am unable to update the record. If i try to use a pause statement instead of WAIT-FOR, the record remains in share-lock.
So can anyone please let me know whether the WAIT-FOR statement releases a record, if the query which fetched the record is associated with a browse ? Is it an expected behaviour or if not what could be the cause for this ? 
I am attaching the sample code along with this. Please let me know your valuable inputs.
/** Sample Code with the mentioned scenario **/

/* ***************************  Definitions  ************************** */
DEFINE BUTTON upd-samp LABEL "Update Sample".   
DEFINE BUTTON exit-app LABEL "Exit". 
DEFINE QUERY seq-samp FOR Sample. 
DEFINE BROWSE brow-samp QUERY seq-samp  
  DISPLAY Sample.SampId Sample.SampleName  WITH 10 DOWN. 

/* ********************  Preprocessor Definitions  ******************** */


/* ***************************  Main Block  *************************** */

FORM 
  exit-app SKIP(1) 
  brow-samp 
  WITH FRAME main-frame. 
  
FORM 
  Sample.SampId Sample.SampleName 
  WITH FRAME curr-frame COLUMN 40. 
  
OPEN QUERY seq-samp FOR EACH Sample. 

ON MOUSE-SELECT-DBLCLICK OF BROWSE brow-samp DO: /* TRANSACTION */ 
 RUN UPD-REC.
END. 

ENABLE ALL WITH FRAME main-frame. 
APPLY "VALUE-CHANGED" TO brow-samp. 
PAUSE 0 BEFORE-HIDE. 
WAIT-FOR CHOOSE OF exit-app OR WINDOW-CLOSE OF DEFAULT-WINDOW. 



/* **********************  Internal Procedures  *********************** */


PROCEDURE FRAME-UPDATE:
/*------------------------------------------------------------------------------
 Purpose: display a frame to update the record.
 Notes:
------------------------------------------------------------------------------*/

ON GO OF FRAME CURR-FRAME DO:
  ASSIGN Sample.SampleName.
  /** Uncomment the below statement to assign the value when Pause statement is used,
  Since the widgets are not enabled with wait-for **/
  /** ASSIGN Sample.SampleName = "abcd". **/
END.

/*UPDATE Sample.SampId Sample.SampleName  WITH FRAME cuRR-frame VIEW-AS DIALOG-BOX
TITLE "SAMPLE UPDATE".*/

DISPLAY Sample.SampId Sample.SampleName  WITH FRAME CURR-FRAME.

FRAME CURR-FRAME:SENSITIVE = TRUE.

ENABLE ALL WITH FRAME CURR-FRAME.
WAIT-FOR GO OF FRAME CURR-FRAME.
/*
PAUSE 5.
APPLY "GO" TO FRAME CURR-FRAME. */

END PROCEDURE.

PROCEDURE UPD-REC:
/*------------------------------------------------------------------------------
 Purpose: To fetch the record in shared lock.
 Notes:
------------------------------------------------------------------------------*/
GET CURRENT seq-samp.
RUN FRAME-UPDATE.  
END PROCEDURE.

All Replies

Posted by Fernando Souza on 25-Nov-2014 08:08

When the WAIT-FOR executes, the browse is getting an ENTRY event which is causing it to refresh the current record with the default locking (no-lock), so when you go update it, it does not have the lock anymore. You can avoid that from happening by doing an APPLY ENTRY to a fill-in CURR-FRAME right before the WAIT-FOR.

Posted by anzeljamal on 27-Nov-2014 04:34

Thanks Fernando for your valuable input. Its working fine.

This thread is closed