I’m looking at a bit of code put in a codeunit by my predecessor and I’m a little confused. Here’s what the code that has me a bit perplexed:
IF Rate.Tbl FIND(‘+’) THEN
REPEAT
Logic which assigns values to some variables
UNTIL RateTbl.NEXT=0;
I understand that FIND(‘+’) finds the last record in a set and that the variables will be assigned values until there are no more records in the set. Here’s where I get a little lost. In all the documentation I’ve read on using FIND in conjunction with NEXT the value 0 always moves one record forward. If the code starts with the last record in the set and moves forward then it will only read one record which appears to make the REPEAT…UNTIL section of the code unnecessary. If in fact NEXT=0 can also move backwards through a set of records then I can understand what’s happening. If that were the case the logic would repeat starting with the last record until it finds the first. So my question is this: Can the NEXT=0 actually be reading backwards in the set or is there some other possible reason why a programmer would have used a REPEAT…UNTIL section of code that apparently won’t repeat? Any help would be greatly appreciated. Thanks!
0
Comments
I think it's more logical to put "UNTIL RateTbl.NEXT(-1)=0;" which means go to back record.
Another solution is to put a message inside the loop to test if it appears more than a once.
Sergi Navarro
MCTS: Microsoft Dynamics™ NAV 2009 C/SIDE Solution Development
Visit my Navision Spanish Blog here: http://www.sergisoft.com
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
You need to go backward in the recordset to process all the records. You can, as sergisoft already mentioned, instead of NEXT, which is actually NEXT(1), use NEXT(-1). It means that you will go one record backward every time in the loop.
So NOT
IF Rate.Tbl FIND(‘+’) THEN
REPEAT
Logic which assigns values to some variables
UNTIL RateTbl.NEXT = 0;
But
IF Rate.Tbl FIND(‘+’) THEN
REPEAT
Logic which assigns values to some variables
UNTIL RateTbl.NEXT(-1) = 0;
It must solve your problem.
Rec.ASCENDING(FALSE);
IF Rec.FIND('-') THEN
REPEAT
MESSAGE(FORMAT(Rec));
UNTIL Rec.NEXT = 0;
FINDLAST = FIND('+')
Attain Navision
Usage of FIND(‘-’) or FINDFIRST very depends from the version of NAV you are using.
And in any case with REPEAT-UNTIL statement - best practice is to use FINDSET, not FINDFIRST
In fact, most of the time FIND('-') is replaced by FINDSET, because most of the time the intention is to loop through records.
RIS Plus, LLC
RIS Plus, LLC
Usage of FIND(‘-’) or FINDFIRST depends on, in order of relevance
1. the programmer
2. the version of Nav, SQL or Native
3. the required return of results
ERP Consultant (not just Navision) & Navision challenger
The keywords FIND('-') and FINDFIRST are not interchangeable, they simply do not mean the same thing.
RIS Plus, LLC
Some time ago, I wrote a series of blog articles, called "What impact does my C/AL have on SQL".
Specifically for the find-statements, you can find more here.
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
I can show you a few consultants who does not even know FINDSET, FINDFIRST existed until version 5.0 came out.
They had been working so hard at client's location that they were not aware of the new features.
If you don't know about it how can you even think of using it?
ERP Consultant (not just Navision) & Navision challenger
The fact remains that you are suggesting that FIND('-') and FINDFIRST are interchangeable, which clearly they are not.
RIS Plus, LLC
And I think I've laid down my criteria for my statements pretty obviously.
My point is if a programmer does not know the existence of FINDSET, how does the programmer use it? Where does your "relevance" even comes in? The programmer must first be educated about the new FINDSET features & its capabilities so as to know when & how to use it. And I'm making reference to the same programmer, ceteris paribus.
When have I ever gave the opinion that FIND('-') and FINDFIRST are interchangeable?
ERP Consultant (not just Navision) & Navision challenger
RIS Plus, LLC
I'm not down to the "relevance of using any keyword" yet. I'm still at knowledge of programmer. You're too fast.
If a programmer is unaware that FINDSET exists, he can only use FIND('-') do you agree?
ERP Consultant (not just Navision) & Navision challenger
Idiot describes the usage of the FIND* functions as it is in real life (often as it not should be)
while DenSter, Waldo, ... describe the usage of the FIND* functions how it should be.
|To-Increase|
And I agree ... I still see quite many people wrongly use these statements... even don't care about these statements. Just got someone on a job interview. 6 years experience in developing C/AL. But he wasn't able to use the FIND* statements in a decent way ...
Eric Wauters
MVP - Microsoft Dynamics NAV
My blog
By the way, those keywords have been available for years now. Any NAV programmer that still doesn't know how to use them has some serious competency issues in my opinion.
RIS Plus, LLC
The reason for this
is because you do not believe there exist people who
ERP Consultant (not just Navision) & Navision challenger
You don't choose keyword number 1 because someone is a rookie (or newbie, or greenhorn, or unexperienced, or stupid), you choose the keyword because the functionality calls for it. Not knowing a keyword is another discussion about competency, but for sure it is not the reason to use it.
RIS Plus, LLC