Buffer with no-lock

Hi All, hope you are doing well !

I know the use of Strong Scope with Exclusive-Lock but what should we do in case of find statements with no-lock. Example below:

1. Result is Yes.

Code:
define variable lCheck as logical no-undo.
if lCheck then 
do:
find first table no-lock no-error.
end.
message available (table) view-as alert-box.

2. Result is No:

Code:
define variable lCheck as logical no-undo.
if lCheck then 
do:
find first table no-lock no-error.
end.
release table.
message available (table) view-as alert-box.

3. We can’t refer buffer outside strong scope.

Code:
define variable lCheck as logical no-undo.
if lCheck then 
do for table:
find first table no-lock no-error.
end.
//message available (table) view-as alert-box.

I think we should take care of this buffer even it’s in no-lock state, if yes then what should be the correct approach (point 2 or 3 or anything else). Please share your inputs on this.

Regards,
Learner
 
I don't know what you want to achieve. The strong scope is recommended when you have to update/create/delete a record to have the smallest transaction possible.
however for no-lock you will only using it if you need to be sure that this buffer is only used in dedicated places in your code.
Can you be more specific ?
 
Hi Boby, thanks for your reply!

My point here is, with find no-lock statement (code at point 1) buffer still available after do block and as per my understanding it shouldn’t be available as we don’t need it.

I want to know whether we should handle that or not (I think we should handle) if yes then what is the best approach for this. For that I mentioned point 2 and 3. Hope it’s clear now.


Regards,
Learner
 
Ok I understand it now.

It depends of what you need to do with it.

If you only want it available in a specific place of your code the strong scope option is more suitable.

On your option 2 you could have error message because of no table record available if lCheck is False, in contrary to option 3 where the strong-scope option will manage the release of the record by himself.

You also could do this:
Code:
define variable lCheck as logical no-undo.
if lCheck then
do:
    find first table no-lock no-error.
    /* do something with table */
    release table no-error.
end.

message available (table) view-as alert-box.

However if you have to use the record on the long run on your code and play with his available status you don't need to release it.

Also I think some here would say that if you have the right indexes you could do it with a FOR EACH and not a FIND. But not really sur about that.
 
Point being that with the strong scope, you don't need to worry or query about the availability of the buffer outside of the strong scope because you know the buffer isn't available there. For the sake of satisfying yourself, you could define a second strong scope block there and test availability there, which it won't be without a new find.

Point being to always use strong scoping so that you know the scope of your buffers.
 
Thanks for your reply Tom and Tamhas!

So conclusively we should use strong scope with Find no-lock as well rather using a release statement. Is that correct ?

Regards,
Learner
 
And, It does not matter if you have a conditional in the "DO FOR",

Code:
IF FALSE THEN DO FOR pt_mstr:
 FIND FIRST pt_mstr NO-LOCK.
END.

DISPLAY AVAILABLE(pt_mstr).

/* This show error: ** Reference to table <table> conflicts with block statement reference. (244)
*/
 
Back
Top