Comparing strings (really, offtopic)

Horacio Villa

Comparing strings (really, offtopic)
Hi list,

do you know if there is a problem in REXX when comparing strings like this:
(the output is from a trace ?r)

145 *-* DO irba = 1 to nrba
>>> "1"
>>> "1"
146 *-* say selRba
>>> "000000000000"
000000000000
147 *-* say selRba.irba
>>> "00E000508202"
00E000508202
148 *-* IF selRba.irba = selRBA
>>> "1"
*-* THEN
*-* leave

As you can see, there are 2 strings, named selRba = "000000000000" &
selRba.1 = "00E000508202".
They are (obviously?) not equal, but when I compare them in REXX, what I
get is that they ARE equal.
What's going on? Is there a workaround?

Cheers,

Horacio Villa

---------------------------------------------------------------------------------
Welcome to the IDUG DB2-L list. To unsubscribe, go to the archives and home page at http://www.idugdb2-l.org/archives/db2-l.html. From that page select "Join or Leave the list". The IDUG DB2-L FAQ is at http://www.idugdb2-l.org. The IDUG List Admins can be reached at [login to unmask email] Find out the latest on IDUG conferences at http://conferences.idug.org/index.cfm

John McKown

Re: Comparing strings (really, offtopic)
(in response to Horacio Villa)
> -----Original Message-----
> From: DB2 Data Base Discussion List
> [mailto:[login to unmask email] On Behalf Of Horacio Villa
> Sent: Monday, December 19, 2005 2:54 PM
> To: [login to unmask email]
> Subject: [DB2-L] Comparing strings (really, offtopic)
>
>
> Hi list,
>
> do you know if there is a problem in REXX when comparing
> strings like this:
> (the output is from a trace ?r)
>
> 145 *-* DO irba = 1 to nrba
> >>> "1"
> >>> "1"
> 146 *-* say selRba
> >>> "000000000000"
> 000000000000
> 147 *-* say selRba.irba
> >>> "00E000508202"
> 00E000508202
> 148 *-* IF selRba.irba = selRBA
> >>> "1"
> *-* THEN
> *-* leave
>
> As you can see, there are 2 strings, named selRba = "000000000000" &
> selRba.1 = "00E000508202".
> They are (obviously?) not equal, but when I compare them in
> REXX, what I
> get is that they ARE equal.
> What's going on? Is there a workaround?
>
> Cheers,
>
> Horacio Villa

The "problem" is that REXX is doing a NUMERIC comparison! Why? Because
all numbers in REXX are stored as character strings. The character
string "000000000000" equates to zero, right? The character string
"00E000508202" is also zero! Why? Because it looks like "scientific
notation" to REXX. The "E" means "10 to the power of" or
00*power(10,508202) which is zero! You need to do a "strict comparison"
using the == symbol instead of the = symbol.

IF selRba.irba == selRBA THEN LEAVE

Similiarliy identically not equal would be /== instead of /=.

--
John McKown
Senior Systems Programmer
UICI Insurance Center
Information Technology

This message (including any attachments) contains confidential
information intended for a specific individual and purpose, and its'
content is protected by law. If you are not the intended recipient, you
should delete this message and are hereby notified that any disclosure,
copying, or distribution of this transmission, or taking any action
based on it, is strictly prohibited.


---------------------------------------------------------------------------------
Welcome to the IDUG DB2-L list. To unsubscribe, go to the archives and home page at http://www.idugdb2-l.org/archives/db2-l.html. From that page select "Join or Leave the list". The IDUG DB2-L FAQ is at http://www.idugdb2-l.org. The IDUG List Admins can be reached at [login to unmask email] Find out the latest on IDUG conferences at http://conferences.idug.org/index.cfm