Hi
Sometimes C/AL code like this is used:
Rec2 := Rec1
(Rec2 and Rec1 are record variable of the same type, for example "Item".)
The question: (category "what you always wanted to know but never dared to ask")
Is this the same like the following code?
Rec2.GET(Rec1."No.")
Any advantages/disadvantages using this kind of stile?
Curious about your answers, thanks a lot.
Thomas
Answers
Rec2.GET(Rec1."No.") is a database operation while Rec2 := Rec1 is only in-memory copy.
If between Rec1.GET(something) and Rec2.GET(Rec1."No.") the record got changed the Rec2.GET(Rec1."No.") will obviously refresh its content.
A side effect of this is that if between Rec1.GET(something) and Rec2.GET(Rec1."No.") the record gets locked then Rec2.GET(Rec1."No.") will wait for the oher session to release the lock.
I'd say that Rec2 := Rec1 will be faster as it does not involve any database roundtrips, but some might argue that after Rec1.GET(something) or whatever command was used to get the Rec1 it is already cached so there should be not much difference.
My personal preference is to use Rec2 := Rec1 whenever I can, except in cases when I need to be sure to have a fresh copy of the record from the database.
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
Thanks a lot. This brings some light to my question.
Thomas