Question Repeat for and do for

Hi Community,

Can anyone explain in what cases do for transaction and repeat for transaction would be used?
The difference between a block that should or should not update something and continue vs a block that should or should not update something and repeat.
 

RealHeavyDude

Well-Known Member
The reason why you would add the transaction keyword to a do block is because a do block by default does not have transaction capabilities. That means without specifying the transaction keyword the transaction scope will be increased to the next outer block with transaction capabilities. In a worst case scenario the transaction scope could be increased as much as to the procedure block.

The repeat block by default does have transaction capabilities. Therefore if a transaction is invoked within a repeat block ( by updating the database or fetching data with an exclusive lock ) the transaction will automatically be scoped to the repeat block and adding the transaction keyword won't change anything. But, in case there is already an inner block with transaction capabilities ( for example a for each ) you can deliberately expand the transaction scope to the repeat block. Please be aware that increasing the transaction scope, be it intentional or not, you might end up creating transactions that are much larger than need be and which might introduce all sorts of of other problems.

You might want to make yourself familiar with transaction scope:
 

TomBascom

Curmudgeon
"DO FOR buffer TRANSACTION" is the critical component of a carefully controlled "limited strong scoped" strategy. This is fundamental to making good clean code that does not suffer from unexpected (and unhandled) lock conflicts and silently expanded transaction scope leading to out of control bi growth.
 
Top