Record Scope After FOR EACH

Dear All,

Hope you all are doing well :)

Although it seems very simple question but I am still unable to understand this.

Code:
FOR EACH customer EXCLUSIVE-LOCK:

    UPDATE customer.NAME.

END.

MESSAGE customer.NAME

    VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.

We are able to compile above code even if we are referencing customer buffer after FOR EACH block. Initially I thought that default buffer names/fields are available but when we use DO FOR TRANSACTION above it (please refer below code for this) then we are not even able to compile this so as per my understanding, some reference of customer buffer must be available after FOR EACH LOOP.

Code:
DO FOR customer TRANSACTION:

FOR EACH customer EXCLUSIVE-LOCK:

    UPDATE customer.NAME.

END.

END.

MESSAGE customer.NAME

    VIEW-AS ALERT-BOX INFORMATION BUTTONS OK.

Please suggest what kind of reference is available after FOR EACH Block because record scope cannot be available here as another user (in multi-user environment) is able to update the record after for each block.

Please suggest.

Kind Regards,

Learner
 

RealHeavyDude

Well-Known Member
The difference is weak (implicit) vs. strong (explicit) buffer scope. Without the "DO FOR customer" it is a weak scope and the compile extends the buffer scope to the outermost block which contains a reference to the buffer.

In the first case it is the message statement referencing the customer buffer which makes the compiler extend the weak scope.

In the second case you've strong scoped the buffer and the compiler can't extend the buffer scope because that would violate your strong scoping.

It has nothing to do with the transaction keyword / scope. It is simply buffer scope - not to be confused with transaction scope.
 
Thanks for your reply RHD.

In weak scope (First scenario), if message statement is referencing the customer buffer then what is the status of locking here because as per my understating, if buffer scope is available then it must be holding some lock.

It should not be NO-LOCK because EX-LOCK cannot be downgrade directly to NO-LOCK so it should be SHARED-LOCK and if it is SHARED-LOCK then how another user (in multi user environment) is able to update this record with EX-LOCK.

Please suggest.
 
Top