dbTalk Databases Forums  

If then weird compare

comp.databases.pick comp.databases.pick


Discuss If then weird compare in the comp.databases.pick forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
James Stoddard
 
Posts: n/a

Default If then weird compare - 05-03-2005 , 04:07 PM






I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Reply With Quote
  #2  
Old   
John Henderson
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 04:14 PM






James Stoddard wrote:

Quote:
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly
Force a string comparison instead of numeric. Eg:

IF 'A':IM.REC<114> = 'A':UPC THEN GOTO.NEXT.ITEM

John



Reply With Quote
  #3  
Old   
Glen B
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 04:17 PM



On Tue, 03 May 2005 21:07:10 GMT, "James Stoddard"
<wildcat66 (AT) hotmail (DOT) com> decreased the available storage
space of our news server by typing the following:

Why is there a leading period in the IM.REC variable and
no space between IF and that period?

IF.IM.REC<114> != IF IM.REC<114>

Quote:
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly




Reply With Quote
  #4  
Old   
Dave Weaver
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 04:47 PM



Quote:
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly


Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each value to
see if they are or are not identical.

Dave Weaver, Weaver Consulting



Reply With Quote
  #5  
Old   
Excalibur
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 05:39 PM



Hi
The rules for comparison as laid down in the original Pick are that a
numeric compare is always done first then an alpha compare when checking two
values in this manner.
In fact the original plan was to use EQ for alpha and = for numeric but this
got lost in the works very early on.
Regards
Peter McMurray
"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote

Quote:
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each value to
see if they are or are not identical.

Dave Weaver, Weaver Consulting




Reply With Quote
  #6  
Old   
Mark Brown
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 05:46 PM



Sorry, Dave, but I think I have to disagree.

The br.compare mode always acts the same: first it tries to do a command
called a POPN to pop a number off the stack. If that succeeds, it does a
numeric compare and, in this case, the two "strings" are numerically
equivalent. If that fails, then it does a POPS to pop a string and does a
string compare.

You have to append a non-numeric character of some sort either at the
beginning or end of the string to force a string compare.

Mark Brown


"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote

Quote:
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each value to
see if they are or are not identical.

Dave Weaver, Weaver Consulting




Reply With Quote
  #7  
Old   
Dave Weaver
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 06:02 PM




Mark Brown wrote:
Quote:
Sorry, Dave, but I think I have to disagree.

The br.compare mode always acts the same: first it tries to do a
command
called a POPN to pop a number off the stack. If that succeeds, it
does a
numeric compare and, in this case, the two "strings" are numerically
equivalent. If that fails, then it does a POPS to pop a string and
does a
string compare.

You have to append a non-numeric character of some sort either at the

beginning or end of the string to force a string compare.

Mark Brown


"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote in message
news:1115156852.776525.326740 (AT) z14g2000cwz (DOT) googlegroups.com...
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each value
to
see if they are or are not identical.

Dave Weaver, Weaver Consulting

Mark,

Say what? You disagree with my test code right in front of you?
Whether you quote the numbers or prepend or append an alpha character
to the numbers treats the numbers as a string. It is just a matter of
"programmer's preference". There are a number of ways to skin this cat!

But, the original problem was one of comparing NUMERIC data!
123 = 0000000123

Hint: Anytime you do a NUMERIC operation (compare, add, subtract,
multiply, divide) the leading zeros are stripped! I once saw code a
programmer had written consisting of about 15 lines of code to remove
the leading zeros! The proper (and easy) way is to just add zero to the
number --- walla, the leading zeros are gone!
A = 00000456
A = A + 0
PRINT A
result: 456

Dave Weaver, Weaver Consulting



Reply With Quote
  #8  
Old   
Dale Benedict
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 06:14 PM



I tried Mr. Weaver's little foofoo progam and the program operates as
displayed.

This surpised me just a little. I've always added an 'A' to the start of
numbers for these special comparisons.

What Dave doesn't hint at in his code is how to get the data read in from
disk to act like a string.

Any hints Dave?

Regards,

Dale

"Mark Brown" <mbrown (AT) drexelmgt (DOT) com> wrote

Quote:
Sorry, Dave, but I think I have to disagree.

The br.compare mode always acts the same: first it tries to do a command
called a POPN to pop a number off the stack. If that succeeds, it does a
numeric compare and, in this case, the two "strings" are numerically
equivalent. If that fails, then it does a POPS to pop a string and does a
string compare.

You have to append a non-numeric character of some sort either at the
beginning or end of the string to force a string compare.

Mark Brown


"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote in message
news:1115156852.776525.326740 (AT) z14g2000cwz (DOT) googlegroups.com...
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each value to
see if they are or are not identical.

Dave Weaver, Weaver Consulting






Reply With Quote
  #9  
Old   
Dave Weaver
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 07:30 PM



I don't think there is anything one can do to "get the data read in
from disk to act like a string".
Data/Datum 0000012345 stored that way on disk will come in as
0000012345 with all "READ" statements. That is why one must be careful
to not store leading-zeroed numbers unless they are absolutely
necessary for some purpose.

Once the data are (or datum is) read from disk, then the programmer may
have to fuss with the numeric data a bit, just as suggested above:
a. Prepend an alpha character to the number.
b. Append an alpha character to the number.
c. Surround the number with quotes (single or double quotes both work).

Be careful! If you are going to use the number(s) for subsequent
mathematical operations (like develop totals, etc.), the numbers better
be numbers (numeric) or they will blow out the math operation(s)!

Dave Weaver, Weaver Consulting


Reply With Quote
  #10  
Old   
Joe
 
Posts: n/a

Default Re: If then weird compare - 05-03-2005 , 07:36 PM



"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote in
news:1115161335.540048.272030 (AT) o13g2000cwo (DOT) googlegroups.com:

Quote:
Mark Brown wrote:
Sorry, Dave, but I think I have to disagree.

The br.compare mode always acts the same: first it tries to do a
command
called a POPN to pop a number off the stack. If that succeeds, it
does a
numeric compare and, in this case, the two "strings" are
numerically
equivalent. If that fails, then it does a POPS to pop a string and
does a
string compare.

You have to append a non-numeric character of some sort either at
the

beginning or end of the string to force a string compare.

Mark Brown


"Dave Weaver" <weaver22 (AT) pacbell (DOT) net> wrote in message
news:1115156852.776525.326740 (AT) z14g2000cwz (DOT) googlegroups.com...
I am doing a compare of a attribute of a file to a table


the actual IF statement is

IF.IM.REC<114> = UPC THEN GOTO.NEXT.ITEM


The actual values are


IM.REC<114> = 72288108174

UPC = 00072288108174


the IF statement acts as though it is a MATCH

Any ideas? Brain totally fried today and not thinkingclearly



Numerically, the NUMBERS are the same!
If you treat them as strings by surrounding each with quotes, the
values do not equal. Test ....

:CT WEAVER FOOFOO

FOOFOO
001 REC114 = "72288108174"
002 UPC = "00072288108174"
003 IF REC114 = UPC THEN PRINT "SAME" ELSE PRINT "NOT.SAME"

:FOOFOO
NOT.SAME
:

Note: Without the surrounding quotes, it comes up SAME.

Another thing you could do is ALSO check the lengths of each
value
to
see if they are or are not identical.

Dave Weaver, Weaver Consulting


Mark,

Say what? You disagree with my test code right in front of you?
Whether you quote the numbers or prepend or append an alpha
character
to the numbers treats the numbers as a string.
Not true. "123" is identical to 123, which is identical to "00123",
which is identical to 00123.

Quote:
It is just a matter of
"programmer's preference". There are a number of ways to skin this
cat!

But, the original problem was one of comparing NUMERIC data!
123 = 0000000123
Not true. In the original post, the comparison was an "attribute in a
file to a table". Numeric isn't mentioned and shouldn't be assumed.

Quote:
Hint: Anytime you do a NUMERIC operation (compare, add, subtract,
multiply, divide) the leading zeros are stripped! I once saw code a
programmer had written consisting of about 15 lines of code to
remove
the leading zeros! The proper (and easy) way is to just add zero to
the
number --- walla, the leading zeros are gone!
A = 00000456
A = A + 0
PRINT A
result: 456

Dave Weaver, Weaver Consulting
And if you encounter non-numeric data, kablooie.

Regards,
Joe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.