Re: Null string comparison.
Posted in 1999
Hi JouhShenToh@pg.SLR.com, When ever a test is done where one field is null the return value is always false. To get around this you may check each of the fields for the value you want as in: IF l_dummyvar = "Y" THEN If the field can be null you need to add a null test as in: IF l_dummyvar IS NULL THEN -- Do something ELSE IF l_dummyvar = "Y" THEN To remove the hassle of checking for NULL's each and every test you could write a function and change the test to.... IF nullvalue(l_dummyvar, "Y") = "Y" THEN -- nullvalue will return the following -- if l_value is null l_valueif_null is returned -- if l_value is not null l_value is returned FUNCTION nullvalue(l_value, l_valueif_null) DEFINE l_value CHAR(80), l_valueif_null CHAR(80) IF LENGTH(l_value) = 0 THEN RETURN l_valueif_null ELSE IF l_value[1]="$" THEN # Cope with money fields LET l_value[1]=" " END IF RETURN l_value END IF END FUNCTION Regards, Stephen Stephen C Manga Email: Stephen.Manga@dbgroup.co.nz Stephen@quanta.co.nz On Fri, 6 Aug 1999 JouhShenToh@pg.SLR.com wrote: > If I have two char(1) variables A and B, I need to do some actions when the > two variables differ. I used > IF A<>B THEN > LET lnCount=lnCount+1 > ELSE > DISPLAY "Same values" > END IF > > When 1 of the variable is null, I will get "Same values" which is not true. > How to overcome this null comparison problem? > > > Thanks. > >