Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified Rows

shyl

New Member
After some frustrating tests, my question now just fall on the statement that "Shall CAN-FIND return true if there are more than 1 qualified rows". My logical thinking tells me a yes but the 4GL behavior in 9.1D says a no.

Here is an example to tell the story better:

Say table a has a two fields a_name & a_code. And that table has two rows:
a_name a_code
--------------------
a1 1
a2 1

And what will that 4GL segment show?

IF CAN-FIND(a WHERE a_code=1 NO-LOCK) THEN
MESSAGE "1 is in table" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "1 is NOT in table" VIEW-AS ALERT-BOX.

Surprise to me that it shows "1 is NOT in table". But if I can the 1st line into

IF CAN-FIND(FIRST a WHERE a_code=1 NO-LOCK) THEN

it shows "1 is in table" now.

Your comments are welcome.


Sincerely,
Lei
 
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

CAN-FIND reports whether or not a single record matching the criteria exists.

So if two or more (or no) records match the criteria, the answer is no.

This is a similar result as when using the FIND statement; if a FIND ... WHERE ... is issued without FIRST, and multiple records satisfy the criteria, an error results.

FWIW, I sympathise with your 'logical thinking' on CAN-FIND, as it has caught me out a couple of times too.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

with CAN-FIND and FIND if you do not specify FIRST/LAST then it is a UNIQUE find

that is there has to be only one unique record matching your WHERE clause

if there is no record or more then one unique record matching your WHERE clause

then no records will be returned or with CAN-FIND the return value will be NO.


i know Mr. Tom Bascom dislikes FIRST/LAST, especially, if they're used as the default :)

but personally i don't think UNIQUE should be the default.
 

Casper

ProgressTalk.com Moderator
Staff member
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

With find you can use the ambiguous function to check this. Can-find doesn't support this because the record isn't actually retrieved. Its just a way of saying wether or not it will be possible to retrieve that record with the statement given.


If you found this post useful, please click the karma button in the top right of this box. Every time you do this, Chris Schreiber sends me $100 which I use to rescue maltreated donkeys.
:lol: good one! :lol:


Casper.


progress.gif
 
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

If you found this post useful, please click the karma button in the top right of this box. Every time you do this, Chris Schreiber sends me $100 which I use to rescue maltreated donkeys.

:lol: good one! :lol:

It's my way of 'giving back', and keeping the karma thing going.

I presume as you - a moderator - are higher up the corporate ladder here at ProgressTalk than me, you get paid more per helpful post? :)
 

Casper

ProgressTalk.com Moderator
Staff member
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

I presume as you - a moderator - are higher up the corporate ladder here at ProgressTalk than me, you get paid more per helpful post? :)

No, I only feel really important now :awink:
But it is always good to give money to such a worthy cause.... :)

Last time somebody tried to give me karma it diminshed my karma points.... lol

Casper
 

tamhas

ProgressTalk.com Sponsor
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

Last time somebody tried to give me karma it diminshed my karma points.... lol

Must be one of those register overflow things!
 

tamhas

ProgressTalk.com Sponsor
Re: Shall/Will can-find(tablename) Return True When There are More Than 1 Qualified R

IF CAN-FIND(a WHERE a_code=1 NO-LOCK) THEN
MESSAGE "1 is in table" VIEW-AS ALERT-BOX.
ELSE
MESSAGE "1 is NOT in table" VIEW-AS ALERT-BOX.

If you make that "CAN-FIND( FIRST a" it will work as you expect. Despite the general negative noise about FIRST/LAST ... which is of concern ... if what you actually want to know is that there is at least one such record, then this is a legitimate use. As far as I think, anyway.
 
Top