When I change records in a loop, you best do it with a second variable. I always use := and never had problems with it.
a.RESET;
a.SETCURRENTKEY(...);
a.SETRANGE(...,...);
IF a.FINDSET(...,...) THEN
REPEAT
b := a;
b."Field" := new value;
b.MODIFY(FALSE);
UNTIL a.NEXT = 0;
What does FINDSET do (I did not find any help in the C/SIDE Reference Guide)?
This function as (couple others) performs the same tasks as FIND, but is designed specially for SQL server option and is more efficient.
I found that info in C/SIDE Referencing guide presents starting from v.4.0 SP1:
FINDSET (Record)
Use this function to find a set of records in a table based on the current key and filter. The records can only be retrieved in ascending order.
Ok := Record.FINDSET([ForUpdate][, UpdateKey])
3)Is it advisable to use COPY instead of := ?
If u really need to copy the same filters etc. (as Claus wrote) to the new record from origin.
As for me it’s more easy to manage all needed conditions instead remembering that from early, that’s why I often use :=
But it depends- what you prefer (or can :).
Regards
It is the same record variable, but another instance.
So after the REPEAT-loop, they will be the same, but you need to do it like that, because the NEXT statement uses the current record-fields to find the next. So if you don’t use it, it can happen that records are skipped or records that are read twice.
I don’t know what happens with FINDSET on SQL. But I advice ALWAYS to use the system with 2 records.
Kriki worte:
But I advice ALWAYS to use the system with 2 records.
It is only necessary to use two records if you change a field that is either part of the sorting key used in the loop or if you change a field that you have applied a filter to. Anyway if you always used two records you won’t get any of these issues.
That is the reason I advice it. Also when someone else later has to change the filters or the fields to be changed, you can get into the problem. If you already use 2 record-variables, you always avoid it.