Problem with SETRANGE statement.

JamieBrown
Member Posts: 107
Hi,
This is a follow-on from my last post, but I'm having trouble filtering the table on the date ranges.
The SETRANGE statement doesn't work at all. I'm sure I'm probably doing something stupid...
thanks as always.
This is a follow-on from my last post, but I'm having trouble filtering the table on the date ranges.
intyear := DATE2DMY(TODAY,3); FOR Counter := 1 TO 12 DO BEGIN datstartdate[Counter] := DMY2DATE(1,Counter,intyear); datenddate[Counter] := CALCDATE('<+1M-1D>',datstartdate[Counter]); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); netamount[Counter] := "Trans. Sales Entry"."Net Amount"; grossamount[Counter] := "Trans. Sales Entry"."Gross Amount"; qty[Counter] := "Trans. Sales Entry".Quantity; END;
The SETRANGE statement doesn't work at all. I'm sure I'm probably doing something stupid...
thanks as always.
0
Comments
-
What is in "Trans. Sales Entry" ? What is it referencing?
You need to do a FIND after the SETRANGE statement.0 -
MTC,
Thanks for the quick reply.
I'm trying ro reference:
"Trans. Sales Entry"."Net Amount";
"Trans. Sales Entry"."Gross Amount";
"Trans. Sales Entry".Quantity;
With the monthly date filter applied.
The following manual code does filter correctly for Jan."Trans. Sales Entry".SETFILTER(Date,'010106..310106');
thanks0 -
Your date calculation code is fine, but you need to do a IF "Trans. Sales Entry".FIND('-') THEN after the "Trans. Sales Entry".SETRANGE statement, otherwise it is always stuck in the same place and will not move.
I am supposing that there is only one record in "Trans. Sales Entry" per date range?0 -
Hello,
Have u tried to put a"Trans. Sales Entry".SETRANGE(date);
before applying any other date filters?
bye.0 -
MTC,
No there are tens of thousands of entries per date range.
I'm a little confused, wouldn't theFOR Counter := 1 TO 12 DO BEGIN
run through each record in "Trans. Sales entry" per date range?
Cletenaff, I tried your suggestion but it made no difference.
thanks0 -
JamieBrown wrote:MTC,
No there are tens of thousands of entries per date range.
I'm a little confused, wouldn't theFOR Counter := 1 TO 12 DO BEGIN
run through each record in "Trans. Sales entry" per date range?
Not unless you have got some sumindexfields setup, no, it's simply giving you 12 iterations.intyear := DATE2DMY(TODAY,3); FOR Counter := 1 TO 12 DO BEGIN datstartdate[Counter] := DMY2DATE(1,Counter,intyear); datenddate[Counter] := CALCDATE('<+1M-1D>',datstartdate[Counter]); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); IF "Trans. Sales Entry".FIND('-') THEN REPEAT netamount[Counter] += "Trans. Sales Entry"."Net Amount"; grossamount[Counter] += "Trans. Sales Entry"."Gross Amount"; qty[Counter] += "Trans. Sales Entry".Quantity; UNTIL "Trans. Sales Entry".NEXT = 0; END;
That would use each record within the date range.
I think. 8-[0 -
I think that better and faster way is:
1. Create key Date in "Trans. Sales Entry" with SumIndexFields "Net Amount", "Gross Amount" and Quantity
2. Insert "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity); after your setrange command0 -
lubost wrote:I think that better and faster way is:
1. Create key Date in "Trans. Sales Entry" with SumIndexFields "Net Amount", "Gross Amount" and Quantity
2. Insert "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity); after your setrange command
Yes, that would be faster, but I think that it's important for him to know why his loop would not work on its own.0 -
MTC, I have tried using FIND and the Navision client actually crashes. But I think I can see the problem with my original logic.
Lubost, I've never used sumindexfields. (Never created flow fields etc)
How would I go about 'coding' it.
many thanks0 -
To use the sumindexfield, you need to create a key in the table as described by lubost. Then, place the statement
SETCURRENTKEY(Primary Key,"Date"); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity);
instead of where you currently have the SETRANGE command. So, something like this:SETCURRENTKEY(Primary Key,"Date"); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity);
0 -
To use the sumindexfield, you need to create a key in the table as described by lubost. Then, place the statement
SETCURRENTKEY(Primary Key,"Date"); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity);
instead of where you currently have the SETRANGE command. So, something like this:intyear := DATE2DMY(TODAY,3); FOR Counter := 1 TO 12 DO BEGIN datstartdate[Counter] := DMY2DATE(1,Counter,intyear); datenddate[Counter] := CALCDATE('<+1M-1D>',datstartdate[Counter]); SETCURRENTKEY(Primary Key,"Date"); "Trans. Sales Entry".SETRANGE("date",datstartdate[Counter],datenddate[Counter]); "Trans. Sales Entry".CALCSUMS("Net Amount", "Gross Amount", Quantity); netamount[Counter] := "Trans. Sales Entry"."Net Amount"; grossamount[Counter] := "Trans. Sales Entry"."Gross Amount"; qty[Counter] := "Trans. Sales Entry".Quantity; END;
Whoops, sorry, I hit quote instead of edit.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