Using := Operator with Records
ta5
Member Posts: 1,164
Hi
Sometimes C/AL code like this is used:
The question: (category "what you always wanted to know but never dared to ask")
Is this the same like the following code?
Curious about your answers, thanks a lot.
Thomas
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
0
Best Answer
-
It is not the same.
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.
Slawek Guzek - www.yitron.co.uk
Business Central, MS SQL Server, Wherescape RED;7
Answers
-
It is not the same.
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.
Slawek Guzek - www.yitron.co.uk
Business Central, MS SQL Server, Wherescape RED;7 -
Hi Slawek
Thanks a lot. This brings some light to my question.
Thomas0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
