locktable and commit

mikest
Member Posts: 2
I have over a million records in this newtable. new status need to be saved after every 1000 records.
Database is NAV 4SP3 with SQL 2005.
And here is the code from the codeunit we are running
NewTable.RESET;
NewTable.SETCURRENTKEY(status);
NewTable.SETRANGE(status,NewTable.status::inactive);
IF NewTable.FINDSET(TRUE,TRUE) THEN //Navision does a locktable here
repeat
newtablecopy := newtable;
//some calculations here
.....................................
....................................
//end of caluclations
newtablecopy.status := NewTablecopy.status::active;
newtablecopy.modify;
counter := counter + 1;
if counter = 1000 then begin
counter := 0;
commit;
// The question is
//how do I lock the table again and still be in the same loop
// Is newtable.locktable good enough?
end;
until newtable.next = 0;
The question is
how do I lock the table again after commit and still be in the same loop
Is newtable.locktable good enough?
Cheers,
Mike
Database is NAV 4SP3 with SQL 2005.
And here is the code from the codeunit we are running
NewTable.RESET;
NewTable.SETCURRENTKEY(status);
NewTable.SETRANGE(status,NewTable.status::inactive);
IF NewTable.FINDSET(TRUE,TRUE) THEN //Navision does a locktable here
repeat
newtablecopy := newtable;
//some calculations here
.....................................
....................................
//end of caluclations
newtablecopy.status := NewTablecopy.status::active;
newtablecopy.modify;
counter := counter + 1;
if counter = 1000 then begin
counter := 0;
commit;
// The question is
//how do I lock the table again and still be in the same loop
// Is newtable.locktable good enough?
end;
until newtable.next = 0;
The question is
how do I lock the table again after commit and still be in the same loop
Is newtable.locktable good enough?
Cheers,
Mike
0
Comments
-
it's enough, the locktable sentence you use manually is the same Navision does._______________
so far, so good0 -
One remark: modifying copy of the record doesn't help from "next from hell" anymore. Better is to add the modifyed records into temporary table and after to save them in second loop. And it will help you much more in NAV 5.0SP1 with the delayed insert.
And if you are reding more than 500 records, better is to use LOCKTABLE and FIND('-'), because FINDSET is optimal for sets smaller than 500 records (depends on the settings in dtabase properties).0
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