Strange SumIndexField error, solved but curious why.

Mauddib
Member Posts: 269
NAV 5.0
Ok so there is a really bad key on one of my customers Gen. Journal Line table.
The key is:
Journal Template Name,Journal Batch Name,Account Type,Currenc
Yuck I know. What is worse is that the SumIndexField is "Amount (LCY)" which is also in the key!!!
Anyway I was changing some code and came accross this code block:
So I tested this in debugger and the first result it got was a Gen. Journal Line (there was just one in the filter I checked with COUNT) with a value 1189 but the CALCSUMS gave me 27347 which is EXACLTY 23 times bigger.
Any ideas why? There is more than 23 lines in that journal and MUCH more than 23 lines in the table.
I solved the issue with this addition:
But I have no idea why this fixes it. For my own interest Id like to know why.
Ok so there is a really bad key on one of my customers Gen. Journal Line table.
The key is:
Journal Template Name,Journal Batch Name,Account Type,Currenc
y Code,Account No.,Amount (LCY),Payment Order No.,Payment Type
Yuck I know. What is worse is that the SumIndexField is "Amount (LCY)" which is also in the key!!!
Anyway I was changing some code and came accross this code block:
GenJnlLine2.RESET; GenJnlLine2.SETCURRENTKEY("Journal Template Name","Journal Batch Name","Account Type","Currency Code", "Account No.","Amount (LCY)"); GenJnlLine2.SETRANGE("Journal Template Name",'ZAHLUNGSEI'); GenJnlLine2.SETRANGE("Journal Batch Name", 'PAYBACK'); GenJnlLine2.SETRANGE("Account Type",GenJnlLine2."Account Type"::Customer); GenJnlLine2.SETRANGE("Account No.",'DEB-C-0003490'); GenJnlLine2.CALCSUMS("Amount (LCY)");
So I tested this in debugger and the first result it got was a Gen. Journal Line (there was just one in the filter I checked with COUNT) with a value 1189 but the CALCSUMS gave me 27347 which is EXACLTY 23 times bigger.
Any ideas why? There is more than 23 lines in that journal and MUCH more than 23 lines in the table.
I solved the issue with this addition:
GenJnlLine2.SETFILTER("Amount (LCY)", '<>0');
But I have no idea why this fixes it. For my own interest Id like to know why.
0
Answers
-
I don't know why, but if you are on sql I would disable MaintainSQLIndex, and disable MainTainSift.
Also if the key is only used in the mentioned code, the Amount LCY doesn't need to be part of the key.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