Memory Leak?

Hi Everybody,
I am not able to figure out the reason for the below behavior. Can someone let me know in detail;

Case 1:
DO TRANSACTION:
FOR FIRST customer EXCLUSIVE-LOCK WHERE customer.cust-num = 7:
DISP customer.
END.
END.

DISPLAY customer.cust-num.

In the above code snippet i can get the record available even after the transaction block. (Out of this transaction block i am able to update name of the customer)

Case 2:
DO FOR customer TRANSACTION:
FOR FIRST customer EXCLUSIVE-LOCK WHERE customer.cust-num = 7:
DISP customer.
END.
END.

DISPLAY customer.cust-num.

This code snippet doesn't allow us to even compile.

Can someone explain me what does Transaction block do in case 1 and case 2?

Thanks in advance.
 

RealHeavyDude

Well-Known Member
Congrats!!! You have just been introduced to transaction scope and buffer scope - which are, IMHO, one of the most important things you should know about when writing 4GL code. We could get philosophical about the rate how many times Progress does the right thing for you without you having to take care about, but, as a programmer you should be the one in charge. Relying on default behavior is sometimes a tricky thing.
  • Case 1 is a so called weak buffer scope. That means, since there is no strong scope specified the scope is determined by the most outer block in which the buffer is referenced. In this case it's the procedure itself. At the end of the transaction scope Progress automatically downgrades the lock on the buffer to a share lock (which is the default lock if you don't specify otherwise). As soon as you update it, Progress will automatically upgrade it again to an exclusive-lock. Having such share-locks, IMHO, is a bad, bad, bad thing because nobody else is able to get a share or exclusive-lock on the buffer as long as the procedure is executed.
  • Case 2 is a strong buffer scope. Since you specify "DO FOR buffer-name" the scope of the buffer is exactly that block. It's not allowed to make a reference to it outside the block with a weak scope and that's why this code even won't compile. For the code to compile you would need to enclose the DISPLAY statement in a "DO FOR buffer-name" block. Still you will need to re-find the record for the code to work.
HTH, RealHeavyDude.
 
Thanks for your congrats my boy... Jus wanna get to know this information. U have xplained me in a better way. Thanks dude..!!
 
Top