ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Declare reference inside IF condition

Post new topic  Reply to topic
 Declare reference inside IF condition « View previous topic :: View next topic » 
Author Message
KIT_INC
PostPosted: Thu Jul 22, 2010 7:52 am    Post subject: Declare reference inside IF condition Reply with quote

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
View user's profile Send private message
Vitor
PostPosted: Thu Jul 22, 2010 7:59 am    Post subject: Re: Declare reference inside IF condition Reply with quote

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
View user's profile Send private message
mqjeff
PostPosted: Thu Jul 22, 2010 8:01 am    Post subject: Reply with quote

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
View user's profile Send private message
Gaya3
PostPosted: Thu Jul 22, 2010 8:01 am    Post subject: Re: Declare reference inside IF condition Reply with quote

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
View user's profile Send private message
KIT_INC
PostPosted: Thu Jul 22, 2010 9:04 am    Post subject: Reply with quote

Knight

Joined: 25 Aug 2006
Posts: 589

Thanks for sharing the knowledge. I learn a lot from this forum.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Declare reference inside IF condition
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.