Repeat UNTIL Loop- Steps records backwards in the table
mduck
Member Posts: 8
I am having problems stepping backwards through a table using the Repeat Until Loop. The logic is simple .... go to the bottom of the table then step backward by one record. Attached is a simple example.
When executed, the record remains at the last record.
Even if I add an explicit step -1 ...
I must be missing something?
As outline in the HELP...
Steps
Data type: integer
Used to define the direction of the search and how many records to step over. This value... Tells the system to...
> 0 Search Steps records forwards in the table.
< 0 Search Steps records backwards in the table.
= 0 No effect
If you do not specify Steps, the system finds the next record.
IF Customer.FIND('+') THEN
REPEAT
"Do Function"
UNTIL Customer.NEXT <0 ;
When executed, the record remains at the last record.
Even if I add an explicit step -1 ...
"Customer.NEXT(-1)"after the "Do Function" the record pointer advances by one when the Until command is reached.
I must be missing something?
As outline in the HELP...
Steps
Data type: integer
Used to define the direction of the search and how many records to step over. This value... Tells the system to...
> 0 Search Steps records forwards in the table.
< 0 Search Steps records backwards in the table.
= 0 No effect
If you do not specify Steps, the system finds the next record.
0
Comments
-
Hi
your next statement should read as followsUNTIL Customer.Next(-1) = 0;
Hope this helps
Albert0 -
Thanks Albert.... Topic Solved. =D>0
-
you're welcome0
-
This type of loop is not good for MS SQL! Do not use it when you are using MS SQL database, else you can have performance problems.0
-
Kine,
We plan on migrating to MS SQL within the year. What kind of loop procedure would you use under SQL to avoid this performance issue?
Mike0 -
You will want to define the table's sort order, if I remember reading this correctly on the forums here.
Set it to Descending and loop through the normal way...UNTIL Table.NEXT = 0;
[edited]Found it! (Not sure why kine didn't include this in his statement up above...)kine wrote:Or you can use ASCENDING(false) to sort the data in descending order if possible and you can go through in normal way. Next(-1) is not good for SQL caching etc.0 -
Xypher,
Thanks for your reply. I will remember this when we migrate to SQL.
Mike0 -
With the new FINDSET command, you can only retrive records in ascending order.There are no bugs - only undocumented features.0
-
bbrown wrote:With the new FINDSET command, you can only retrive records in ascending order.
Exactly, and it have much better performance for sets of records which have few records (less than 500). And it is why I have not included the "second" part about the descending sort order... ;-)
Better is to remember rule "do not use descending order and backward loop" if possible.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K 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
- 324 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
