Author |
Message
|
kwelch |
Posted: Mon Apr 15, 2002 6:34 am Post subject: |
|
|
 Master
Joined: 16 May 2001 Posts: 255
|
Hi,
We are attempting to use the new Declare ... Reference To ... in WMQI 2.1 and find that we are unable to get it to work in an IF statement unless all of the statements that then reference this variable are also in the IF statement. A deploy error is given if we try to reference the variable outside the IF statement.
Has anyone else experienced this? Is this working as it's supposed to or is there a fix available? Thanks in advance for any help on this one.
Karen |
|
Back to top |
|
 |
kolban |
Posted: Mon Apr 15, 2002 7:11 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
Can you post the ESQL used and the error message received. What exact release and maintenance level is being used and on what platform? |
|
Back to top |
|
 |
kwelch |
Posted: Mon Apr 15, 2002 8:01 am Post subject: |
|
|
 Master
Joined: 16 May 2001 Posts: 255
|
Hi Kolban,
Sure! This is just a simple example for the sake of this post, but it illustrates the issue that we are hitting. We are at CSD01 I believe and running the Broker on NT with a combination of NT/2000 Control Centers. Here is the one that works:
DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
SET OutputRoot.Properties.MessageFormat = 'XML';
IF InputBody.TOT.MSG[1].LAST = 'WELCH' THEN
SET OutputLocalEnvironment.Variables.TOT.*[] = InputBody.TOT.*[];
DECLARE MSGNM REFERENCE TO OutputLocalEnvironment.Variables.TOT.*[];
SET MSGNM.MSG[1].LAST = 'KAREN';
SET MSGNM.MSG[1].FIRST = 'WELCH';
END IF;
Here is the one that gets the deploy error:
DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
SET OutputRoot.Properties.MessageFormat = 'XML';
IF InputBody.TOT.MSG[1].LAST = 'WELCH' THEN
SET OutputLocalEnvironment.Variables.TOT.*[] = InputBody.TOT.*[];
DECLARE MSGNM REFERENCE TO OutputLocalEnvironment.Variables.TOT.*[];
END IF;
SET MSGNM.MSG[1].LAST = 'KAREN';
SET MSGNM.MSG[1].FIRST = 'WELCH';
It receives the following error at deploy time:
BIP2432E: (18, 5) : The correlation name 'MSGNM' is not valid. Those in scope are: Environment, InputLocalEnvironment, OutputLocalEnvironment, InputRoot, InputBody, InputProperties, OutputRoot, InputExceptionList, OutputExceptionList, InputDestinationList, OutputDestinationList, I.
The first element of a field reference must be a valid correlation name, from those in scope. This message may sometimes be due to an incorrectly formed or spelled expression which is not intended to be a field reference being parsed as if it were a field reference because the parser does not recognize it.
Correct the syntax of the expression and redeploy the message flow.
Thanks for your help.
Karen |
|
Back to top |
|
 |
kolban |
Posted: Mon Apr 15, 2002 8:12 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
Spotted something immediately that causes me concern and can't see past this until we address it ... your statement
DECLARE MSGNM REFERENCE TO OutputLocalEnvironment.Variables.TOT.*[];
Says that you want to create a variable called MSGNM which points to the MULTIPLE ELEMENTS beneath TOT in the OutputLocalEnvironmentTree ....
The .*[] should be read as "ALL CHILDREN BENEATH". But since a reference variable can only have one value ... i.e. point to one and only one node in the tree, there is no semantic meaning to your statement. Suggest that you may want:
DECLARE MSGNM REFERENCE TO OutputLocalEnvironment.Variables.TOT.*[1];
But take care and understand what is meant.
See also http://www.kolban.com/mq/using_new_ESQL.htm |
|
Back to top |
|
 |
kwelch |
Posted: Mon Apr 15, 2002 8:20 am Post subject: |
|
|
 Master
Joined: 16 May 2001 Posts: 255
|
Kolban,
I agree, that was a typo on my part when creating this example. This does not change the error on the deploy.
Karen
[ This Message was edited by: kwelch on 2002-04-15 09:22 ] |
|
Back to top |
|
 |
kolban |
Posted: Mon Apr 15, 2002 8:43 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2001 Posts: 1072 Location: Fort Worth, TX, USA
|
Looking at the code ...
IF InputBody.TOT.MSG[1].LAST = 'WELCH' THEN
SET OutputLocalEnvironment.Variables.TOT.*[] = InputBody.TOT.*[];
DECLARE MSGNM REFERENCE TO OutputLocalEnvironment.Variables.TOT.*[];
END IF;
SET MSGNM.MSG[1].LAST = 'KAREN';
SET MSGNM.MSG[1].FIRST = 'WELCH';
If the "IF" statement evaluates to false then MSGNM will never be declared. If this is "possible", then the subsequent assignment statements will throw an error since "MSGNM" will be an unknown variable.... I kinda think it was smart of the deploy to catch this one  |
|
Back to top |
|
 |
kwelch |
Posted: Mon Apr 15, 2002 8:55 am Post subject: |
|
|
 Master
Joined: 16 May 2001 Posts: 255
|
Kolban,
Striving for simplicity is killing me!!!! We also had an IF THEN ELSE scenario so that either way something will get assigned and declared and it still gets the deploy error. I guess the bottom line is the DECLARE must be done outside of an IF THEN ELSE?
Thanks,
Karen |
|
Back to top |
|
 |
kirani |
Posted: Mon Apr 15, 2002 9:08 am Post subject: |
|
|
Jedi Knight
Joined: 05 Sep 2001 Posts: 3779 Location: Torrance, CA, USA
|
Karen,
I think it is a programming language feature. If you define a variable in a loop then its scope is restricted to that loop only. You cannot refer to it out of the loop. I think ESQL follows the same principles as any other programming language do.
_________________ Kiran
IBM Cert. Solution Designer & System Administrator - WBIMB V5
IBM Cert. Solutions Expert - WMQI
IBM Cert. Specialist - WMQI, MQSeries
IBM Cert. Developer - MQSeries
|
|
Back to top |
|
 |
kwelch |
Posted: Mon Apr 15, 2002 9:21 am Post subject: |
|
|
 Master
Joined: 16 May 2001 Posts: 255
|
oh ok! I did not realize that about defining the variable in the loop. I guess it does make sense from that perspective then! Thanks for going round and round with me on this one!
Karen |
|
Back to top |
|
 |
|