Repeat UNTIL Loop- Steps records backwards in the table

mduckmduck 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.
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.

Comments

  • AlbertvhAlbertvh Member Posts: 516
    Hi

    your next statement should read as follows
      UNTIL Customer.Next(-1) = 0;
    

    Hope this helps

    Albert
  • mduckmduck Member Posts: 8
    Thanks Albert.... Topic Solved. =D>
  • AlbertvhAlbertvh Member Posts: 516
    you're welcome
  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • mduckmduck Member Posts: 8
    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?

    Mike
  • XypherXypher Member Posts: 297
    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.
  • mduckmduck Member Posts: 8
    Xypher,
    Thanks for your reply. I will remember this when we migrate to SQL.

    Mike
  • bbrownbbrown Member Posts: 3,268
    With the new FINDSET command, you can only retrive records in ascending order.
    There are no bugs - only undocumented features.
  • kinekine Member Posts: 12,562
    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.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.