reset vs ???

I seems to remember in the old avista or the current 2.0 that when using the find function it was necessary to “reset” to the begining of a file before running the find (next) again with different filters. I know the record.reset will acheive this but then all of the filters have to be reset instead of just one or two. Wasn’t there a way to reset without clearing all of the existing filters??

Assigning a new value to the field you want to filter on clears the previous setting for that field only. Changing a filter while being somewhere in a find/next loop won’t work, as far as I know, and surely isn’t “good programming practise” John

I understand that setting a filter will clear out the previous filter. I also understand that it is not a good idea to change filters while running a loop. My question is when running subsequent loops, within one function, with the only change being a different filter being set BETWEEN loops. Is it necessary to “reset” the records before executing the next loop? It Appears because it has already hit the end of file marker it does not start over at the beginning of the file automaticaaly with the next find("-") command.

Let’s take a look at a couple of examples for the Customer table (T18). As this forum deletes spaces on the beginning of lines in a message I put for better visibility underscores to idented lines. These underscored - of course - are not part of the correct syntax. Example: Cust.Reset; Cust.Setrange(“No.”,‘1000’,‘2000’); Cust.setrange(“Currency Code”,‘USD’); if Cust.find(’-’) then __Repeat ____ Do some code here __Until Cust.Next <= 0; //second loop with same filter if cust.find(’-’) then __Repeat ____ Do some code here __Until Cust.Next <= 0; // note: the find(’-’) command resets the filepointer // to the beginning of the filtered records // Now let’s watch all customers: Cust.Setrange(“No.”); if Cust.find(’-’) then __Repeat ____ Do some code here __Until Cust.Next <= 0; // Note: Using Setrange without second parameter resets this particular filter. Therefore we don’t filter Customer number anymore. But does this show all customers? No, it doesn’t as the filter on Currency Code from the first loop still remains. We would now get a list of all customers which pay in USD! This leads do some tips how to avoid common mistakes: 1) If the Customer table is a global variable which is being used in several functions within the object you cannot rely on which filters are set. General rule #1 therefore is: Use local variables whenever possible. rule #2: To make sure you have a defined state on the table, always start with table.Reset; table.setcurrentkey (… table.setrange ( 2) Use SETCURRENTKEY to sort the table according to a key which best matches your filter criteria. Otherwise you will end up with extremely slow performance if navision has to scan the table sequentially. During developement and testing this mistake will not affect your performance as at this stage the database is very small and contains only very little test-data. However you will hear about a year later if the customer has to wait 30 minutes for a report if the Item Ledger Entry Table with 1 Mio entries is being read sequentially! :frowning: Hope this helps Marcus Marcus Fabian phone: +41 79 4397872