for each customer:
custNum = custNum + 10000.
end.
repeat preselect each customer:
find next customer.
custNum = custNum + 10000.
end.
Yep, already experienced that...It isn't that FOR EACH is bad -- but if you update a field used in the selection of the records you can be surprised.
PRESELECT gives you a snapshot -- IOW if you are changing the value of a field used in the index you won't see the record again.
Bad idea:
Code:for each customer: custNum = custNum + 10000. end.
Better:
Code:repeat preselect each customer: find next customer. custNum = custNum + 10000. end.
It isn't that FOR EACH is bad -- but if you update a field used in the selection of the records you can be surprised.
for each customer exclusive-lock:
customer.custNum = customer.custNum + 10000.
end.
define buffer updCustomer for customer.
for each customer no-lock:
do for customer transaction:
find updCustomer exclsuive-lock where recid( updCustomer ) = recid( customer ).
updCustomer.custNum = customer.custNum + 10000.
end.
end.
Actually it should be:
Code:for each customer exclusive-lock: customer.custNum = customer.custNum + 10000. end.
... or, if we want to tightly control transaction scope, perhaps:
Code:define buffer updCustomer for customer. for each customer no-lock: do for customer transaction: find updCustomer exclsuive-lock where recid( updCustomer ) = recid( customer ). updCustomer.custNum = customer.custNum + 10000. end. end.
Always! Let's see if KrisM can see the other typo.Yeesh! The errors just keep piling up!
On the bright side it is nice to see that you guys are actually reading this stuff
Might be even more correct with error-handling...Corrected correction:
-undothrow 2Might be even more correct with error-handling...
<ducking behind cover>