for each will behave like free reference?

GaneshP

New Member
Hi,
i am able to see procedure level buffer scope and transaction scope in below code
for each customer exclusive-lock:
end.
update name.

can any one explain can we say for each also free reference in some situations like in above scenario.
...\Practise\scope.p 09/13/2019 13:19:59 PROGRESS(R) Page 1

{} Line Blk
-- ---- ---
1 1 FOR EACH customer EXCLUSIVE-LOCK:
2 1
3 END.
4 UPDATE NAME.
...\Practise\scope.p 09/13/2019 13:19:59 PROGRESS(R) Page 2

File Name Line Blk. Type Tran Blk. Label
-------------------- ---- ----------- ---- --------------------------------
...\Practise\scope.p 0 Procedure Yes
Buffers: Sports2000.Customer
Frames: Unnamed

...\Practise\scope.p 1 For Yes
 

Cringer

ProgressTalk.com Moderator
Staff member
Whilst your code is "correct", it's not good. Essentially the lock has bled outside the block it was scoped to. This is possible with weakly scoped transaction blocks, and it can cause real problems in a production system.
To avoid this bleeding you should strongly scope your transactions:

Code:
DEFINE BUFFER bcustomer FOR customer. 
DO FOR bcustomer TRANSACTION:
  FOR EACH bcustomer EXCLUSIVE-LOCK:
  END. 
END.

You will find that you are no longer able to update the Customer outside the transaction block and your code is less likely to cause long running transactions.
 

GaneshP

New Member
@Cringer you are correct. but my question is in that code it is raising the buffer scope and transaction scope in procedure level due to update statement, its behaving like free reference. so can we say for each also behaving like free reference in such situations?
 

Cringer

ProgressTalk.com Moderator
Staff member
I don't understand the question I'm afraid. Whatever you want to label it, it's incredibly bad practise and potentially dangerous.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
I'm not sure where all this is heading but given the leading questions and the path "...\Practise\scope.p", it feels like we're doing someone's homework assignment for them.
 
Top