Nested loops + MarkedOnly

abartonicek
Member Posts: 162
Because of some circumstances I have to use marking as ONLY solution for my filtering so it comes down to this:
SL has SETSELECTIONFILTER set on it.
SL1 is a group of marked sales lines and I must select all the lines where "Document No." are the same!
This "selecting" is actually unmarking the marked lines which do not meet required conditions.
Speed would be acceptable IF IT WOULD WORK THIS WAY.
When I run this piece of code Navision freezes :oops:
What did I do wrong (beside poor solution design :oops: )
... SL.MARKEDONLY; SL.FIND('-'); REPEAT Flag := TRUE; SL1.FIND('-'); REPEAT IF SL1."Document No." <> SL."Document No." THEN SL1.MARK(FALSE) ELSE SL1.MARK(TRUE); IF SL1.MARK THEN Flag := FALSE; IF SL1.NEXT = 0 THEN Flag := FALSE; UNTIL Flag; UNTIL SL.NEXT = 0; SL1.MARKEDONLY; ...SL and SL1 are record variables of the same subtype.
SL has SETSELECTIONFILTER set on it.
SL1 is a group of marked sales lines and I must select all the lines where "Document No." are the same!
This "selecting" is actually unmarking the marked lines which do not meet required conditions.
Speed would be acceptable IF IT WOULD WORK THIS WAY.
When I run this piece of code Navision freezes :oops:
What did I do wrong (beside poor solution design :oops: )
Better to be critical then self-critical 

0
Answers
-
I think your solution is a little too complicated.
Better try something like this (didn't test it though)// tmpSL is a temptable // put all SL1 marked records in a temptable SL1.MARKEDONLY(TRUE); IF SL1.FIND('-') THEN REPEAT tmpSL := SL1; tmpSL.INSERT(FALSE); UNTIL SL1.NEXT = 0; // now delete all records I want TO KEEP from the temptable SL.MARKEDONLY(TRUE); SL.FIND('-'); REPEAT tmpSL.RESET; tmpSL.SETRANGE("Document No.",SL"Document No."); tmpSL.DELETEALL(FALSE); UNTIL SL.NEXT = 0; // all the records still in the temptable, I do NOT want in SL1 tmpSL.RESET; IF tmpSL.FIND('-') THEN REPEAT SL1.GET(tmpSL-key-fields); SL1.MARK(FALSE); UNTIL tmpSL.NEXT = 0; // now in SL1 you have the records you want
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Why it is not working? Because:
You are filtering for MarkedOnly.
You change mark on some record to false.
Where will go the NEXT command? You changed "field" which is used for filtering in the loop... it is common problem...
The next will be lost in the loop if you do that.0 -
It slipped my mind O:)
I was soooo occupied with that nested loop #-o
Thanks, both of you!Better to be critical then self-critical0 -
It would probably go much faster if you used a temporary table and insert the ones from the regular table into it, and then you use the temp table to display.0
-
Sorry for not saying this before but I solved the problem. It was simple after my mind started to work ](*,)
I added one Boolean flowfield to the table which checks all my conditions and now I'm filtering by that field. I don't know how I didn't figured that out before :?:
Thanks for your help, guysBetter to be critical then self-critical0
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