proper looping while updating
Aldevinas Katkus
10-11-23
Operating system: macOS
Simple(?) question:
How should we update a number of related records in a loop?

As far as I understand the table "cursor" moves to the new value, does not stay in the same place in the following case:
If we have SDNr values in the table like 79,79,78 and we would like to "update FuelSDrsr set FuelSDrsr.SDNr=81 where FuelSDrsr.SDNr=79" only the first occurence with SDNr=79 will be updated.


Is it a bug or feature? I (wrongly?) believe cursor/pointer should not move to the new record while we are looping the table if we do not call SetLoopPosition, ReadFirstxxx etc.

TrHs = true;
While LoopKey("SDNr",FuelSDrsr,1,TrHs) begin
if (FuelSDrsr.SDNr!=oldNr) then begin TrHs=false; end;
if (TrHs) then begin
RecordCopy(oldFuelSDrsr,FuelSDrsr);
FuelSDrsr.SDNr=newNr;
if (RecordUpdate(oldFuelSDrsr,FuelSDrsr,false)==0) then begin end; //why this moves table pointer to new position?
end;
end;

I have looked at IVVcOKTool2.hal where we have
if (found) then begin
RecordCopy(oldTBIVr,TBIVr);
TBIVr.Invoice = IVp.SerNr;
if (RecordUpdate(oldTBIVr,TBIVr,false)) then begin end;
// StepBack(TBIVr); stops loop too quickly
end;

and result is the same: if we change project invoice number to greater one, then only the first project transaction record will be updated with the new invoice number, others will have the old (wrong) invoice number.
Leave Comment
You can subscribe to notifications for this post by selecting the 'star' icon on the top right corner of the post.
Latest Posts
Reino Botha
Please check your version of android if it is the same as the server you are connecting too. ...
08:24 21 Nov 2024
Bror-Erik Kotiranta
In NC you hace operations>>ai chats. They are used for these Br, Bror-Erik...
05:12 21 Nov 2024