Loop on table
-matrix-
Member Posts: 103
Hi everybody!
I need to do a loop on table from the end to begin, do you think that this code is right?
I need to do a loop on table from the end to begin, do you think that this code is right?
TBTable.ASCENDING(FALSE); TBTable.SETRANGE(); IF TBTable.FINDFIRST THEN BEGIN REPEAT ......... ........... UNTIL (TBTable.NEXT = -1);
0
Answers
-
No, I think the code is not good.
Because you use a findfirst and choose a repeat afterwards (use findset or find('-'))
and second: next = 0 instead of next = -1 (This might be good, but I never use it) I find it too ambigous with next(-1)0 -
-matrix- wrote:Hi everybody!
I need to do a loop on table from the end to begin, do you think that this code is right?TBTable.ASCENDING(FALSE); TBTable.SETRANGE(); IF TBTable.FINDFIRST THEN BEGIN REPEAT ......... ........... UNTIL (TBTable.NEXT = -1);
try with:IF TBTable.FINDSET THEN BEGIN REPEAT ......... ........... UNTIL (TBTable.NEXT = 0);
take a look to "Next function (Record)" in OnLine help.
Edit: sorry to repeat what sog has already sad! =D>~Rik~
It works as expected... More or Less...0 -
Thanks for replies boys but is needful the ASCENDING with this sintax ?0
-
Did you try?
Item.ASCENDING(FALSE); IF Item.FINDFIRST THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT = 0;0 -
Hi,
I think if you want records in Descending Order and you do not get by findset after Ascending(False).
May be you need a key or doing some efforts by other way...Regards,
Hemant
They can conquer who believe they can.0 -
-matrix- wrote:Thanks for replies boys but is needful the ASCENDING with this sintax ?
FINDSET can only retrieve records in ascending order.0 -
Why do you think we didn't comment on the ascending: that part is correct.
ascending false will effectively sort the table in reverse.
The alternative was using a find('+') and using until table.next(-1) = 0
Mohanna, You ought not to use findfirst in a loop!0 -
Yes, I'm trying and It seems work with the FINDSET and with THE FINFIRST =D>0
-
Agree with you.Sog wrote:Mohanna, You ought not to use findfirst in a loop!0 -
I'm starting to get confused. Help tells me findset can only be used in descending order, which tells me default ascending is already false: Could you try with ascending(true)?
if that doesn't work, use find('-')
And please don't use findfirst, it's not meant for looping. (findfirst does a select top(1) from table) if nav detects a loop it uses a second query. while findset and find('-') only use 1 query to get the data.0 -
But so if I can't use the FINDSET what is the right instruction?0
-
Item.ASCENDING(FALSE); IF Item.FIND('-') THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT = 0;0 -
-
I did not misread the help, just a different version
NAV 5.0 SP1 help wrote:Furthermore, FINDSET only supports descending loops. If you want to loop from the bottom up, you should use FIND(‘+’).FINDSET can only retrieve records in ascending order. If you want to loop from the bottom up, then you should use FIND('+').0 -
This is the correct way. (or also ASCENDING(TRUE) and FIND('+') and NEXT(-1)mohana_cse06 wrote:Item.ASCENDING(FALSE); IF Item.FIND('-') THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT = 0;
But in certain cases, a better way may exist.
The FIND('-') creates a cursor in SQL that is slow and heavy on the system.
If you have few records (<= # of records in recordset ; defined in File=Database=Alter=>Tab advanced), it is better to use FINDSET and read them in ASCENDING and save them in a temptable and then read them in descending. If you code is run a lot of times by a lot of users, this makes it a lot less heavy on the system.Item.ASCENDING(TRUE); //Ascending! IF Item.FINDSET THEN REPEAT tmpItem := Item; tmpItem.INSERT(FALSE); UNTIL Item.NEXT = 0; tmpItem.RESET; tmpItem.ASCENDING(FALSE); IF tmpItem.FIND('-') THEN REPEAT Message('%1',tmpItem."No."); UNTIL tmpItem.NEXT = 0;
BTW: see also http://www.mibuso.com/howtoinfo.asp?FileID=22Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
Sog is right.
Usually you sould try to avoid Find('-') and Find('+') but in this senario you can ither
sort in descending order, find the first record and step forward:Item.ASCENDING(FALSE); IF Item.FIND('-') THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT = 0;
or
sort in ascending order, find the last record and step backward:Item.ASCENDING(TRUE); IF Item.FIND('+') THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT(-1) = 0;0 -
Thanks to Everybody for the numberous replies =D> , I used this solution :
Item.ASCENDING(FALSE); IF Item.FIND('-') THEN REPEAT Message('%1',Item."No."); UNTIL Item.NEXT = 0;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
- 323 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
