FINDSET REPEAT UNTIL

Angelo
Member Posts: 180
Hi All,
Previously, I've got issue after looping, not all my records are modified as I forgot to use second table variable after reading topic FINDSET on other forum. However, I saw there are 2 approaches as the following:
Rec1.SETRANGE(Field1,Value1);
IF Rec1.FINDSET THEN
REPEAT
Rec2.GET(Rec1.PrimaryKey);
Rec2.Field1 = Value2;
Rec2.MODIFY;
UNTIL Rec1.NEXT = 0
Rec1.SETRANGE(Field1,Value1);
IF Rec1.FINDSET THEN
REPEAT
Rec2 := Rec1
Rec2.Field1 = Value2;
Rec2.MODIFY;
UNTIL Rec1.NEXT = 0
are both do the same thing? are both guarantee that modify will be successful 100%?
Which one is the best?
Previously, I've got issue after looping, not all my records are modified as I forgot to use second table variable after reading topic FINDSET on other forum. However, I saw there are 2 approaches as the following:
Rec1.SETRANGE(Field1,Value1);
IF Rec1.FINDSET THEN
REPEAT
Rec2.GET(Rec1.PrimaryKey);
Rec2.Field1 = Value2;
Rec2.MODIFY;
UNTIL Rec1.NEXT = 0
Rec1.SETRANGE(Field1,Value1);
IF Rec1.FINDSET THEN
REPEAT
Rec2 := Rec1
Rec2.Field1 = Value2;
Rec2.MODIFY;
UNTIL Rec1.NEXT = 0
are both do the same thing? are both guarantee that modify will be successful 100%?
Which one is the best?
0
Answers
-
The fastest is to use MODIFYALL as Juhl suggested.
Among the two you have proposed the second one would be probably just a tad bit faster, I guess. The first one includes GET, which is, in theory, a relatively slow database access operation, but since you're GETting a record which has just been retrieved from the database it will be almost certainly fetched from the local cache.
On the other hand, if you want to stick to looping and MODIFY, rather than using MODIFYALL (although looking at the sample you've posted I can's see any reason why you would not want to use MODIFYALL), each time you have to modify a field which is also used in SETRANGE or SETCURRENTKEY commands do keep using two records
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030 -
Hi All,
My concern now is not about the performance but it's about modify record successfully.
I mentioned that some records were not modified,so that I try to change my code by using both approaches (use second variable). I hope MODIFYALL also give a guarantee 100% my record is modified perfectly.
0 -
Probably you were modifying something that was affecting your loop. Modifyall does not have that problem, there is no loop.0
-
@Slawek_Guzek - MODIFYALL is fastest to use if you are just modifying one record value but if you have multiple modifications then REPEAT UNTIL works faster then MODIFYALL.Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/0 -
Thanks everybody for the answer, so far my problem run smoothly by using Option 20
-
Also it is useful to use options in findset to speed up execution.
FINDSET(TRUE,FALSE) in your case.
Nav Upgrades and DEV outsourcing
Reports transformation to RDLC
List -1h , Complex List -3h, Document -4h (dev hours)
navisionupgrade.com0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K 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
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions