Author |
Message
|
KIT_INC |
Posted: Thu Jul 22, 2010 7:52 am Post subject: Declare reference inside IF condition |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
I am using WMB 61 and toolkit csd 5.
I want to define a dynamic reference based on a condition
If I do
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG.DATA.CUSTOMER;
DECLARE ADD CHAR;
SET ADD = ZZ.ADDRESS;
it works.
But if I do
DECLARE COND INT;
IF COND = 1 THEN
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG.DATA.CUSTOMER;
ELSE
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG.DATA1.CUSTOMER;
END IF ;
DECLARE ADD CHAR;
SET ADD = ZZ.ADDRESS;
I'll get a warning saying "Identifier "ZZ" cannot be resolved" and the deployment will fail.
Is this a bug? |
|
Back to top |
|
 |
Vitor |
Posted: Thu Jul 22, 2010 7:59 am Post subject: Re: Declare reference inside IF condition |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
KIT_INC wrote: |
Is this a bug? |
No. If declared inside the IF statement, it's out of scope outside it. DECLARE it outside & MOVE it according to the condition. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Thu Jul 22, 2010 8:01 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
No, this is not a bug.
It's simple scoping.
IF/END IF is a block. Anything defined inside that is not visible outside the block.
Code: |
--oh look I used code tags
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG;
DECLARE COND INT;
if COND =1 THEN
MOVE ZZ to InputRoot.XMLNS.MY_MSG.DATA.CUSTOMER;
ELSE
MOVE ZZ to InputRoot.XMLNS.MY_MSG.DATA1.CUSTOMER;
END IF;
DECLARE ADD CHAR;
if LASTMOVE() THEN
SET ADD = ZZ.ADDRESS;
ELSE
SET ADD = "SOMETHING WENT WRONG";
END IF; |
|
|
Back to top |
|
 |
Gaya3 |
Posted: Thu Jul 22, 2010 8:01 am Post subject: Re: Declare reference inside IF condition |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
KIT_INC wrote: |
But if I do
DECLARE COND INT;
IF COND = 1 THEN
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG.DATA.CUSTOMER;
ELSE
DECLARE ZZ REFERENCE TO InputRoot.XMLNS.MY_MSG.DATA1.CUSTOMER;
END IF ;
DECLARE ADD CHAR;
SET ADD = ZZ.ADDRESS;
I'll get a warning saying "Identifier "ZZ" cannot be resolved" and the deployment will fail.
Is this a bug? |
adding to Vitor's point, add it outside, as you are trying to access it outside the if-else loop or assign the value to add inside the loop itself. _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
KIT_INC |
Posted: Thu Jul 22, 2010 9:04 am Post subject: |
|
|
Knight
Joined: 25 Aug 2006 Posts: 589
|
Thanks for sharing the knowledge. I learn a lot from this forum. |
|
Back to top |
|
 |
|