Copy Function

Hi,

What is the difference between these 2 statements:

  1. SalesHeader := Rec; //SalesHeader is a record variable which is the same as Rec

  2. SalesHeader.COPY(Rec);

Does statement 1 copy only the current record (1 record)? Does statement 2 copy all the records in rec?

Regards,

Anse

Hi Anse

SalesHeader.COPY(Rec) copies all filters, marks, keys and the values in the fields in the record.

SalesHeader := Rec only copies the values in the fields in the record.

Regards

Claus

  1. := transfers only the record.
  2. COPY transfers ALSO the filters,key

Both copy only the current record.

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;

Hi,

Thanks for your inputs.

More queries:

  1. What does FINDSET do (I did not find any help in the C/SIDE Reference Guide)?

  2. In Kriki’s code, since ‘a’ & ‘b’ refer to the same record variable, won’t the modifications to ‘b’ get reflected in ‘a’ also after the REPEAT loop?

3)Is it advisable to use COPY instead of := ?

Regards,

Anse

Hello.

  1. 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

J.

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.

Regards

Claus

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.

Once again, thanks for all your inputs.

Regards,

Anse