Data Access Worldwide Knowledge Base
Article ID 2147 Article Title PROBLEM: Infinite Loop when using HasRecord Function Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2147 KBase Category VDF11 Date Created 07/25/2005 Last Edit Date 07/25/2005
Article Text
QUESTION:
I created a program with the following code:
Send Request_Find of OrderDtl_DD FIRST_RECORD OrderDtl.File_Number 1
While (HasRecord(OrderDtl_DD))
Showln OrderDtl.Recnum
Send Request_Find of OrderDtl_DD NEXT_RECORD OrderDtl.File_Number 1
Loop
When executed, this code is stuck in a loop. I tried HASRECORD and CURRENT_RECORD and both return a value at the end of the file...
ANSWER:
This is because you are trying to use HasRecord and Current_Record as the FOUND indicator. After a request_find at the end of the file, the FOUND indicator will be FALSE, the file buffer will be cleared but the DD buffer will contain the same record as it had before the request_find.
You can see that if you run the following code through the debugger and put a breakpoint on SHOWLN "NOT FOUND" and step through the code with F10:
string sOrdNum sDetail
integer iCurRec
Send Request_Find of OrderDtl_DD FIRST_RECORD OrderDtl.File_Number 1
While (HasRecord(OrderDtl_DD))
get Current_Record of OrderDtl_DD to iCur
Showln "Current Record: " iCur
Showln OrderDtl.Recnum
Showln "From File Buffer: " OrderDtl.Order_Number " - " OrderDtl.Detail_Number
get file_field_current_value of OrderDtl_DD file_field OrderDtl.Order_Number to sOrdNum
get file_field_current_value of OrderDtl_DD file_field OrderDtl.Detail_Number to sDetail
Showln "From DD Buffer: " sOrdNum " - " sDetail
Send Request_Find of OrderDtl_DD NEXT_RECORD OrderDtl.File_Number 1
if (found);
showln "FOUND"
else;
showln "NOT FOUND"
Loop
Replace HasRecord with Found and your loop should work as you expected.
Contributed By:
Marcia Booth
Company: Data Access Worldwide
Web Site: http://www.dataaccess.com
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.