Hi!
I have some problems with positions in the recordset. The record in scope is allways what_i_want - 1
I use this code to position my cursor and expect the Table.NEXT statement not to be executed when I have found the record I'm looking for.
REPEAT
IF Table.Field = what_looking _for THEN
found := TRUE
UNTIL (found=TRUE) OR (Table.NEXT(-1)=0)
...
IF found = TRUE THEN
use Table.Field.value (but the wrong one ..)
...
Is C/AL processing everything in the UNTIL or break when first hit a false?
Rossi
0
Comments
Table.NEXT;
use Table.Field.value (the right one ..)
end;
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Acording to the documentation it should be possible to BREAK a repeat loop, but the compiler does not allow me ( stupid compiler...)
I want so much to have the record I found in the repeat loop in scope in further processing. I'm processing a lot of records and I want to skip as much overhead parsing as possible.
Any suggestions?
Rossi
IF Table.Field = what_looking _for THEN BEGIN
found := TRUE;
Table2 := Table;
END;
UNTIL (found=TRUE) OR (Table.NEXT(-1)=0)
...
IF found = TRUE THEN
use Table2.Field.value (Use This record variable)
So : the solution is to make a local var local_rec and use local_rec.COPY(found_rec) when i found my record and use the local_rec in further processing.
How does this statement impact my speed needs? In 99,99 percent i check the needed record first. Is a COPY a byVal or ByRef..
Again: any suggestions kill nighttime work
Referenc
I don't think anything in navision is by reference, except paramaters for functions.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
The COPY statement gives me the all records looping through.
Would it be btter if i can retrieve the primery key field(s) and use a GET and use local_rec
Hmmm...
Rec2 := Rec1;
not
Rec2.COPY(Rec1);
The rec_furter := rec_found work judt as i wnat.
Thanks a lot!
Not employeed, call me!
Rosi
or:
It is realy bad practice to loop through recods with while statement. It has horrible performance compared to repeat until statement.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
You can break a loop by placing the loop in its own function and using an EXIT statement within the loop.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
RIS Plus, LLC
IF BreakTest THEN BEGIN...(Use Record1)
Function BreakTest : Boolean
IF Record1.FINDSET(TRUE, FALSE) THEN
REPEAT
IF (Condition True) THEN
EXIT(TRUE);
UNTIL Record1.NEXT = 0;
EXIT(FALSE);
Denster,
I'm not sure that's what ara3n meant... because unless you are settign additional filters in the loop, or deleting records, the code you wrote will be an infinite loop ( poor performance indeed ) or always false.
ara3n -- what did you mean?
This is only a basic example. It would of course be used along with code that set proper filters and keys on Record1 before calling the function.
NOTE: Condition True is just a placeholder in the example. In actual code the programmer would replace this with a actual statement to be evaluated as True or False.
What are you referring to?
Sort order should be Descending and then read forwards through the table (maybe only for SQL this might not matter on native). I had heard that it could degrade performance if you do reads in a While loop as opposed to a Repeat but I have yet to see solid evidence of this (as opposed to anecdotal). I agree that WHILE (MyRec.FIND('-')) DO is bad practice as I know that this does have performance issues. But this is entirely different from what I had suggested.
The first thing I said was that filtering should have been used!! I only offered the other solution as an alternative. I don't understand why go through all this unnecessary code when simple filtering will do the trick.
Here is the quote from SQL server resource Kit pdf file.
and looking at his code, I don't think the read ahead mechanism will be enabled.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Have you seen anything on how the new FINDSET(TRUE, TRUE) command impacts this?
This will cause SQL to teardown and rebuild its cursor each time. This can have a sizable peformance impact.