Author |
Message
|
rajbuddha |
Posted: Tue Apr 24, 2012 11:03 pm Post subject: Issue with 'String followed by space' in IF condition - ESQL |
|
|
 Apprentice
Joined: 02 Aug 2011 Posts: 47 Location: chennai
|
I am facing the below issue in WMB6.0 as well as WMB8.0 :
My requirement is to do soemthing like :
IF InputRoot.XMLNSC.A.B = 'XYZ'
THEN
SET OutputRoot.XMLNSC.C.D = 'Hi';
ELSE
SET OutputRoot.XMLNSC.C.D = 'Bye';
END IF;
When my input contains a value of 'XYZ ', i.e., XYZ followed by spaces, the same is being treated equivalent to just 'XYZ' (without a space) and I am receiving a 'Hi' instead of 'Bye' in the output.
Please note that the same behaviour is observed while using CASE statement as well.
Has anyone faced similar issues before ?
Any inputs that you could provide on the above would help.
Thanks ! _________________ -----------
Raju Buddha
Never Wait for your 2nd Opportunity..!Becoz it may be harder than the 1st One... |
|
Back to top |
|
 |
zpat |
Posted: Tue Apr 24, 2012 11:20 pm Post subject: |
|
|
 Jedi Council
Joined: 19 May 2001 Posts: 5866 Location: UK
|
It's fairly standard, in flexible languages, when different length strings are being compared to automatically pad the shorter one on the right with blanks.
So make sure the strings the same length using LEFT or SUBSTR or whatever and a length value. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Apr 25, 2012 2:29 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Code: |
if TRIM(InputRoot.XMLNSC.A.B) = 'XYZ' |
|
|
Back to top |
|
 |
sree4vit |
Posted: Wed Apr 25, 2012 2:56 am Post subject: |
|
|
 Novice
Joined: 05 Aug 2010 Posts: 21
|
Quote: |
DECLARE Counter CHARACTER LENGTH (InputRoot.XMLNSC.A.B);
IF Counter = 3 AND InputRoot.XMLNSC.A.B = 'XYZ'
THEN
SET OutputRoot.XMLNSC.C.D = 'Hi';
ELSE
SET OutputRoot.XMLNSC.C.D = 'Bye';
END IF; |
- try this |
|
Back to top |
|
 |
mgk |
Posted: Wed Apr 25, 2012 4:33 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
This behaviour with string comparison is by design. From the infocenter:
Quote: |
Trailing blanks are regarded as insignificant in character comparisons. Thus if you want to ensure that two strings are truly equal you need to compare both the strings themselves and their lengths. For example:
Code: |
'ABC ' is equal to 'ABC' |
|
Kind Regards, _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Apr 25, 2012 5:10 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
zpat wrote: |
It's fairly standard, in flexible languages, when different length strings are being compared to automatically pad the shorter one on the right with blanks. |
Not only flexible languages. Most variants of COBOL do this too....
I'm surprised you've not noticed this in your other coding experiences. As my most worthy & knowledgeable associate (who I beleve is giving a REST in Vegas on Friday the 4th!) points out this is documented & you need something like the code snippets posted to deal with it. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|