NEXT function with FIND('+')

blh
Member Posts: 24
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!
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
-
Are you sure this is the line: "UNTIL RateTbl.NEXT=0;" ?
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.com0 -
May be that the code inside the loop is changing the position in the set somehow. But the code as was posted is strange... 8)0
-
It is true that FIND(‘+’) is finding the last record in the set. When you are executing NEXT operator – system try to get next record (going forward) which is not exist, because you are already at the end of the set.
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.0 -
As a solution you can also change the sort order in the record set from ascending to descending and use standard loop processing.
Rec.ASCENDING(FALSE);
IF Rec.FIND('-') THEN
REPEAT
MESSAGE(FORMAT(Rec));
UNTIL Rec.NEXT = 0;0 -
FINDFIRST = FIND('-')
FINDLAST = FIND('+')MCSD
Attain Navision0 -
2Becka.
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 FINDFIRST0 -
Becka wrote:FINDFIRST = FIND('-')
FINDLAST = FIND('+')
In fact, most of the time FIND('-') is replaced by FINDSET, because most of the time the intention is to loop through records.0 -
Spawn wrote:Usage of FIND(‘-’) or FINDFIRST very depends from the version of NAV you are using.0
-
Spawn wrote: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
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 resultsNAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
idiot wrote:Usage of FIND(‘-’) or FINDFIRST depends on, in order of relevance
1. the programmer
The keywords FIND('-') and FINDFIRST are not interchangeable, they simply do not mean the same thing.0 -
I agree with Denster.
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.0 -
DenSter wrote:No I don't agree, it's mostly the intention of the code that determines which one you use.
The keywords FIND('-') and FINDFIRST are not interchangeable, they simply do not mean the same thing.
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?NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
You're putting the horse behind the wagon. Just because a few consultants don't know about some of the most important keywords does not mean that it's the programmer that determines the relevance of using any keyword.
The fact remains that you are suggesting that FIND('-') and FINDFIRST are interchangeable, which clearly they are not.0 -
One of us is definitely either having problem understanding English or taking things with a lot of assumptions in place.
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?NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
idiot wrote:One of us is definitely either having problem understanding English or taking things with a lot of assumptions in place.idiot wrote:When have I ever gave the opinion that FIND('-') and FINDFIRST are interchangeable?idiot wrote:Usage of FIND(‘-’) or FINDFIRST depends on, in order of relevanceidiot wrote:My point is if a programmer does not know the existence of FINDSET, how does the programmer use it?0
-
idiot wrote: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 resultsDenSter wrote:...determines the relevance of using any keyword.
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?NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
Or to put it bluntly
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.0 -
I was starting to get it ;°)
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 ...0 -
idiot wrote:I'm not down to the "relevance of using any keyword" yet. I'm still at knowledge of programmer. You're too fast.idiot wrote:If a programmer is unaware that FINDSET exists, he can only use FIND('-') do you agree?
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.0 -
Sog & Waldo knows what I'm implying & encountering.
The reason for thisDenSter wrote:...because you're not making any sense to me...
is because you do not believe there exist people whoDenSter wrote: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.NAV - Norton Anti Virus
ERP Consultant (not just Navision) & Navision challenger0 -
I never said I don't believe there are people who don't know things, there are many people like that, in fact I am one myself. I just don't agree with you that the developer's skill level is a reason to choose a certain keyword. Any keyword.
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.0 -
Can anyone help me pls https://forum.mibuso.com/discussion/71498/get-different-dimension-value/p1? new=1 ?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K 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
- 320 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