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 » Accessing array element within an array

Post new topic  Reply to topic
 Accessing array element within an array « View previous topic :: View next topic » 
Author Message
newbeeMB
PostPosted: Mon Apr 27, 2015 11:45 pm    Post subject: Accessing array element within an array Reply with quote

Newbie

Joined: 27 Apr 2015
Posts: 7

Hello All,

I'm new to MB and im trying to do this:
Following is my XML message structure:

Code:
<EmployeeList>
     <Empl maxOccurs=unbounded>
         <Name>
         <ID>
         <Skills>
               <SkillName maxOccurs=unbounded>


Im trying to filter the employees who has java skills using the following ESQL:

Code:
FOR source as InputRoot.XMLNSC.EmployeeList.Empl[] DO
     FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName" AS I(I.SkillName='Java') DO
     SET OutputRoot.XMLNSC.EmployeeList.Empl[i]=
                SELECT I.Name, I.ID FROM          InputRoot.XMLNSC.EmployeeList.Empl[i] AS I;
  END FOR;


I get the following error on the FOR ANY statement:
Syntax error: Valid options include IDENTIFIER SIMPLE_FUNCTION.

I referred to the esql pdf example for FOR ANY.

Kindly assist.
Back to top
View user's profile Send private message
iibmate
PostPosted: Tue Apr 28, 2015 12:54 am    Post subject: Re: Accessing array element within an array Reply with quote

Apprentice

Joined: 17 Mar 2015
Posts: 38
Location: Perth, WA

newbeeMB wrote:


FOR source as InputRoot.XMLNSC.EmployeeList.Empl[] DO
FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName" AS I(I.SkillName='Java') DO
SET OutputRoot.XMLNSC.EmployeeList.Empl[i]=
SELECT I.Name, I.ID FROM InputRoot.XMLNSC.EmployeeList.Empl[i] AS I;
END FOR;



Please paste complete input message and esql code, for our analysis.

(1) please use outer loops reference in inner loop.

(2) SET OutputRoot.XMLNSC.EmployeeList.Empl[i]

Is the variable "i" initialized ? then with what value. Where is the incrementing statement for this variable ?
Back to top
View user's profile Send private message
newbeeMB
PostPosted: Tue Apr 28, 2015 9:07 am    Post subject: Reply with quote

Newbie

Joined: 27 Apr 2015
Posts: 7

Thank you for the prompt response. Here is the complete input message:

Code:
<?xml version="1.0" encoding="UTF-8"?><EmployeeList>
  <Empl>
    <Name>John</Name>
    <EmpID>2468</EmpID>
    <Skills>
      <SkillName>Java</SkillName>
      <SkillName>C++</SkillName>
    </Skills>
  </Empl>
  <Empl>
    <Name>Mark</Name>
    <EmpID>1456</EmpID>
    <Skills>
      <SkillName>C</SkillName>
      <SkillName>Android</SkillName>
    </Skills>
  </Empl>
</EmployeeList>


And here is the complete ESQL:

Code:
CREATE PROCEDURE CopyEntireMessage() BEGIN
   DECLARE i INTEGER 1;
   FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
      FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName"[] AS I (I.SkillName='Java') DO
         SET OutputRoot.XMLNSC.EmployeeList.Empl[i].Name=InputRoot.XMLNSC.EmployeeList.Empl[i].Name;
         SET OutputRoot.XMLNSC.EmployeeList.Empl[i].EmpID=InputRoot.XMLNSC.EmployeeList.Empl[i].EmpID;
      END FOR;
   SET i=i+1;      
   END FOR;
END;


Kindly assist.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue Apr 28, 2015 10:17 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

newbeeMB wrote:
And here is the complete ESQL:

Code:
CREATE PROCEDURE CopyEntireMessage() BEGIN
   DECLARE i INTEGER 1;
   FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
      FOR ANY InputRoot.XMLNSC.EmployeeList.Empl[i].Skills."SkillName"[] AS I (I.SkillName='Java') DO
         SET OutputRoot.XMLNSC.EmployeeList.Empl[i].Name=InputRoot.XMLNSC.EmployeeList.Empl[i].Name;
         SET OutputRoot.XMLNSC.EmployeeList.Empl[i].EmpID=InputRoot.XMLNSC.EmployeeList.Empl[i].EmpID;
      END FOR;
   SET i=i+1;      
   END FOR;
END;


Don't put user code in the generated procedures. If something causes the Toolkit to regenerate the procedure, your code will be lost. Put it in the main body after the call to that procedure.

The correct form of what you've tried to write is:
Code:

FOR source AS InputRoot.XMLNSC.EmployeeList.Empl[] DO
  FOR ANY source.Skills.SkillName[] AS I (I.SkillName='Java') DO
    CREATE LASTCHILD OF OutputRoot.XMLNSC.EmployeeList.Empl NAME "Name" VALUE source."Name";
    CREATE LASTCHILD OF OutputRoot.XMLNSC.EmployeeList.Empl NAME EmpID VALUE source.EmpId;
  END FOR;
END FOR;


Untested, E&OE and note the double quotes round the tag called "Name" as it's a reserved word in ESQL

You could get the same result with something like:
Code:

SET OutputRoot.XMLNSC.EmployeeList.Empl[] = SELECT I."Name", I.EmpID FROM InputRoot.XMLNSC.EmployeeList.Empl AS I WHERE I.Skils.SKillName = 'Java'


Other coding solutions which are variations or combinations of these two methods are possible and highly functional. This cat can be skinned in a variety of ways.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
iibmate
PostPosted: Tue Apr 28, 2015 5:34 pm    Post subject: Reply with quote

Apprentice

Joined: 17 Mar 2015
Posts: 38
Location: Perth, WA

No arrays in IIB, only lists.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Wed Apr 29, 2015 4:26 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

iibmate wrote:
No arrays in IIB, only lists.


Lists, and elements in a logical message tree.
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 » Accessing array element within an array
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.