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?
0
Answers
Just modify the field.
You can also use modifyall
Rec1.MODIFYALL(Field1,Value2,FALSE);
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
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
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.
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
FINDSET(TRUE,FALSE) in your case.
Reports transformation to RDLC
List -1h , Complex List -3h, Document -4h (dev hours)
navisionupgrade.com