Begins begins behave diffrently

shireeshn

Member
HI all talkers,

Yesterday a i have found Tricky think with "Begins".

Can any one give me clear ideia on this.I know wht i happening but why it is happening i dont know. plz suggest on this.

Hear is the example


DEFINE TEMP-TABLE tt_cust
FIELD cust-no AS CHAR
FIELD custix AS LOGICAL
INDEX Icustno cust-no .

CREATE tt_cust.
ASSIGN
tt_cust.cust-no = "AFS"
tt_cust.custix = YES.
CREATE tt_cust.
ASSIGN
tt_cust.cust-no = "AFS01"
tt_cust.custix = YES.
CREATE tt_cust.
ASSIGN
tt_cust.cust-no = "AFS02"
tt_cust.custix = YES.
CREATE tt_cust.
ASSIGN
tt_cust.cust-no = "AFS03"
tt_cust.custix = YES.

FIND tt_cust WHERE tt_cust.cust-no BEGINS "AFS" NO-LOCK NO-ERROR.
MESSAGE AVAIL tt_cust AMBIG tt_cust
VIEW-AS ALERT-BOX INFO BUTTONS OK.

===============
ANS:- yes no
===============

BUT when u remove the index in the temp table i get the output as

===============
ANS:- no yes
===============


i was suprised to see this, i dont have clear idea of this why it is behaving like this. :confused:
 

enoon

Member
It is because BEGINS uses indexes whenever it can:
"BEGINS is useful in a WHERE phrase that specifies which records should be retrieved in a FOR EACH block. Unlike the MATCHES operator, which requires that all records in the file be scanned, BEGINS uses an index wherever possible." (HELP). Since the field you are searching for is part of an index, it uses that and matches exactly a record since you search for a string that is equal to it. Let's say you search for something ambiguous like "AFS0" it will fail finding an exact record because the FIND matches 3 records at the same time.
 

shireeshn

Member
hi enoon,

Wht u said is correct but in my customer system iam accessing record from database, when i am finding record using "Beigns" it says AMBIG the same data in my system says AVAIL (index is same in both systems). :confused: :cool:


i dont know why it is behaving like this in my customer system ????
 

enoon

Member
It is for sure some difference. Look at the details maybe you omitted something. AMBIG is the same thing as not putting the NO-ERROR at the find. The compile will tell you that it found multimple records matching the FIND. So having two different systems with the same data you should get the same result, otherwise it is something different.
 
Top