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 » Need help on ESQL code

Post new topic  Reply to topic
 Need help on ESQL code « View previous topic :: View next topic » 
Author Message
anilmekala
PostPosted: Wed Dec 02, 2015 5:10 am    Post subject: Need help on ESQL code Reply with quote

Acolyte

Joined: 19 Oct 2012
Posts: 63

Hi All,

As part of my requirement i am getting below xml as input

Code:
         <ReqBody>
            <EntityName>hhtb</EntityName>
                                                <RecordData>
               <Key>abcd</Key>
               <Value>
                <StringValue>1234</StringValue>
               </Value>
            </RecordData> 
         <RecordData>
               <Key>abcdWSD</Key>
               <Value>
                <StringValue>123464</StringValue>
               </Value>
            </RecordData>
                                                <RecordData>
               <Key>details</Key>
               <Value>
                  <Attributes>
                     <Key>name</Key>
                     <Value>kaz</Value>
                  </Attributes>
                  <Attributes>
                     <Key>id</Key>
                     <Value>321</Value>
                  </Attributes>
                  <Attributes>
                     <Key>date</Key>
                     <Value>354</Value>
                 </Attributes>
                  </Value>
             </RecordData>           
         </ReqBody>



and my expected output is :

Code:
<CreateRecord>
<CaseList>
<DynamicCase>
<Key>abcd</Key>
<Value>1234</Value>
<Key>abcdWSD</Key>
<Value>123464</Value>
<Key>details</Key>
<Value>
<DynamicCase>
   <Key>name</Key>
   <Value>kaz</Value>
   <Key>id</Key>
   <Value>321</Value>
   <Key>date</Key>   
   <Value>354</Value>
</DynamicCase>
</Value>
</DynamicCase>
</CaseList>
</CreateRecord>

ESQL code is:

Code:
DECLARE refToRecordData REFERENCE TO InputRoot.XMLNSC.ReqBody.RecordData;
      DECLARE count INTEGER 1;
      DECLARE attrCount INTEGER 1;
      DECLARE refToStrVal CHARACTER;
      
      WHILE LASTMOVE(refToRecordData) DO         
         SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Key[count] = refToRecordData.Key;
               
         IF FIELDNAME(refToRecordData.Value.StringValue)= 'StringValue' THEN            
            SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Value[count] = refToRecordData.Value.StringValue;            
         ELSE            
             IF FIELDNAME(refToRecordData.Value.Attributes)= 'Attributes' THEN                
                DECLARE refToAttributes REFERENCE TO refToRecordData.Value.Attributes;
                WHILE LASTMOVE(refToAttributes) DO
                   SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Value.DynamicCase.Key[attrCount] = refToAttributes.Key;
                   SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Value.DynamicCase.Value[attrCount] = refToAttributes.Value;                   
                   MOVE refToAttributes NEXTSIBLING REPEAT TYPE NAME;         
                  SET attrCount = attrCount +1;                
                END WHILE;                
             END IF;
         END IF;         
         MOVE refToRecordData NEXTSIBLING REPEAT TYPE NAME;      
         SET count = count +1;         
      END WHILE;



Am getting output as below :

Code:
<CreateRecord>
  <CaseList>
    <DynamicCase>
      <Key>abcd</Key>
      <Key>abcdWSD</Key>
      <Key>details</Key>
      <Value>1234
          <DynamicCase>
              <Key>name</Key>
              <Key>id</Key>
              <Key>date</Key>
              <Value>kaz</Value>
              <Value>321</Value>
              <Value>354</Value>
           </DynamicCase>
       </Value>
       <Value>123464</Value>
        </DynamicCase>
    </CaseList>
</CreateRecord>


Please help me where i have gone wrong.

Regards,

Anil.
Back to top
View user's profile Send private message
maurito
PostPosted: Wed Dec 02, 2015 5:21 am    Post subject: Re: Need help on ESQL code Reply with quote

Partisan

Joined: 17 Apr 2014
Posts: 358

anilmekala wrote:

SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Value.DynamicCase.Key[attrCount] = refToAttributes.Key;
SET OutputRoot.XMLNSC.CreateRecord.CaseList.DynamicCase.Value.DynamicCase.Value[attrCount] = refToAttributes.Value; il.

use CREATE STATEMENT instead of SET. Syntax in the knowledge centre.
and if you use the debugger, you can see how the message tree is being built in both cases, and what the difference between the two methods.

Having said that, you can also use a SELECT statement , which will be a lot more efficient.
Back to top
View user's profile Send private message
timber
PostPosted: Wed Dec 02, 2015 6:24 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

...and please put XML and code into [c o d e] tags. It's not hard - there is a little button just above the editing window.
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 » Need help on ESQL code
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.