Find / Find First - Help!!

Crittar

Member
I have some code within a for each loop:

Code:
FIND bbsbi NO-LOCK
  WHERE bbsbi.nl-loc = '2'
	AND bbsbi.st-loc = oldstloc.st-loc
	AND bbsbi.st-item = oldstloc.st-item NO-ERROR.

If I modify the code to be FIND FIRST (with no other changes) it finds fewer records than the first snippet of code.

Can anyone please explain to me why this should be?

Surely they should retrieve the same number of records?

:confused: :confused: :confused: :confused:
 

MHotovec

Member
Ummm.. I don't think I have THE answer - but there is a thought or two rattling in my head.

'Find first', but it's very nature, is only going to find one record.
'Find' has the potential to find more than one. But in MY world that will cause Progress to puke (technical term) because of an ambiguity. However I DON'T know if that's a setting particular to our house, or is something that Progress just does.



Crittar said:
I have some code within a for each loop:

Code:
FIND bbsbi NO-LOCK
  WHERE bbsbi.nl-loc = '2'
	AND bbsbi.st-loc = oldstloc.st-loc
	AND bbsbi.st-item = oldstloc.st-item NO-ERROR.

If I modify the code to be FIND FIRST (with no other changes) it finds fewer records than the first snippet of code.

Can anyone please explain to me why this should be?

Surely they should retrieve the same number of records?

:confused: :confused: :confused: :confused:
 

bendaluz2

Member
Given that find first will always retrieve one record when at least one exists for the conditions given, and find wont retrieve a record if more than one satisfies the condition, I would expect find first to retrieve more records if anything. If the table bbsbi is non unique on the fields nl-loc, st-loc and st-item then I would expect to either use find first, specify another condition which does make the find unique or use for each to retrieve all records that satisfy the conditions. It all depends on exactly what you are trying to do.

Crittar said:
I have some code within a for each loop:

Code:
FIND bbsbi NO-LOCK
  WHERE bbsbi.nl-loc = '2'
	AND bbsbi.st-loc = oldstloc.st-loc
	AND bbsbi.st-item = oldstloc.st-item NO-ERROR.

If I modify the code to be FIND FIRST (with no other changes) it finds fewer records than the first snippet of code.

Can anyone please explain to me why this should be?

Surely they should retrieve the same number of records?

:confused: :confused: :confused: :confused:
 

Crittar

Member
I would expect that there may well be more than one record available for the values I specify, that's why I originally coded it as a 'find first'.

A colleague was checking what I was doing independently and he used find and retrieved more records.

I agree with the comments Bendaluz2 made and so find (no pun intended) the situation worrying: Anything which casts doubt on the results needs to be understood and explained. Anyone out there with further thoughts / possible explanation?
 

Skc

Member
Crittar said:
A colleague was checking what I was doing independently and he used find and retrieved more records.


As far as I am aware, Find or Find first is a command that will only find a maximum of 1 record and bring it into the record buffer. It cannot find multiple records even if there are multiple records that satisfy the criteria. If there are multiple records that fits the criteria, Find (w/o first) will fail and will find NO records - Ambiguous function would return true.

Have you had a look at the codes of your colleague? If he can retrieve multiple records, then I suspect the find command is within a Repeat block and also it would probably be a Find NEXT command.


Regards
Skc
 

Crittar

Member
Skc,

I agree with you - I would only expect a maximum of one record. Indeed, as all I am trying to do is prove the existance of a record, I initially had a can-find. The reason I changed to a find was to establish if that was the cause of my colleague and I retrieving a different number of records. It was only after a little investigation that we discovered it was the 'first' that made the difference.

There is definitely no 'find next' in my colleague's code.

So - I am left with the same confusion as expressed initially - why does 'find' find more records than 'find first' when you would expect either the same number or a greater number in the case of 'find first' (given the possible ambiguity).

PLEASE - can anyone out there shed any light on this?
 

Crittar

Member
Ooops - My brain has now returned from vacation:

The snippet of code I published was too small, it was followed by:

Code:
IF AVAILABLE bbsbi THEN
  NEXT.
 
ASSIGN
  cnt = cnt + 1.

It is the value in cnt which was increasing which is of course exactly what you would expect as the ambiguity would result in fewer records being available and thus the count being higher.

:blush1:

Well - everyone is allowed a bad day now and again!
 

bendaluz2

Member
:lol:

happens to the best of us mate

Crittar said:
Ooops - My brain has now returned from vacation:

The snippet of code I published was too small, it was followed by:

Code:
IF AVAILABLE bbsbi THEN
  NEXT.
 
ASSIGN
  cnt = cnt + 1.

It is the value in cnt which was increasing which is of course exactly what you would expect as the ambiguity would result in fewer records being available and thus the count being higher.

:blush1:

Well - everyone is allowed a bad day now and again!
 
Top