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 » ESQL question

Post new topic  Reply to topic
 ESQL question « View previous topic :: View next topic » 
Author Message
Gideon
PostPosted: Fri Apr 29, 2011 11:58 am    Post subject: ESQL question Reply with quote

Chevalier

Joined: 18 Aug 2009
Posts: 403

I am reading about reference pointers in this doc:

http://www.ibm.com/developerworks/websphere/library/techarticles/0608_piper/0608_piper.html

In this doc it references the following code:

Code:
DECLARE total FLOAT;
DECLARE count INTEGER 1;
DECLARE innercount INTEGER 1;
DECLARE i INTEGER 1;
DECLARE saleListRef REFERENCE TO InputBody.Parent.SaleList[1];
CREATE FIELD OutputRoot.XML.Parent;   
DECLARE outref REFERENCE TO OutputRoot.XML.Parent;

WHILE LASTMOVE(saleListRef) DO
   DECLARE invoiceRef REFERENCE TO saleListRef.Invoice[1];
   WHILE LASTMOVE(invoiceRef) DO
           IF (invoiceRef.Surname <> 'Shop') THEN     
               SET outref.SaleList[i].Statement[count].Customer.Initials =
                            invoiceRef.Initial[1] || COALESCE(invoiceRef.Initial[2],'');     
               SET outref.SaleList[i].Statement[count].Customer.Name = invoiceRef.Surname;     
               SET outref.SaleList[i].Statement[count].Customer.Balance = invoiceRef.Balance;           
               DECLARE ref2 REFERENCE to invoiceRef.Item[1];   
               SET total = 0;     
               SET innercount = 1;           
               WHILE (LASTMOVE(ref2) = TRUE) DO     
                  IF (ref2.Price > 0.0) THEN       
                    SET outref.SaleList[i].Statement[count].Purchases.Article[innercount].Desc =   
                                  ref2.Description;       
                        SET outref.SaleList[i].Statement[count].Purchases.Article[innercount].Cost =   
                                  CAST(ref2.Price AS FLOAT) * 1.6;       
                        SET outref.SaleList[i].Statement[count].Purchases.Article[innercount].Qty =       
                                  ref2.Quantity;       
                        SET total =
                                  total + (CAST(ref2.Price AS FLOAT) * CAST(ref2.Quantity AS FLOAT) * 1.6);             
                        SET innercount = innercount + 1;             
                  END IF;                     
               MOVE ref2 NEXTSIBLING REPEAT NAME;           
               END WHILE;             
             SET outref.SaleList[i].Statement[count].Amount = total;     
                SET outref.SaleList[i].Statement[count].Amount.Currency = invoiceRef.Currency;     
                SET outref.SaleList[i].Statement[count].Type ='Monthly';     
                SET outref.SaleList[i].Statement[count].Style = 'Full';     
                SET count = count + 1;       
             END IF;
             MOVE invoiceRef NEXTSIBLING NAME 'Invoice';
   END WHILE;
   SET i = i + 1;
   SET count = 1;
   MOVE saleListRef NEXTSIBLING NAME 'SaleList';
END WHILE;


There are some things I dont understand here, never having used reference pointers before.


I do not understand the context of the REPEAT statement in the following:

Code:
MOVE ref2 NEXTSIBLING REPEAT NAME;


I looked up REPEAT and it says to repeat the previous commands until the condition is true. I do not understand NAME and in what dondition it is true.

Could I simply write the line as follows to go to the next item in the list:
Code:

MOVE ref2 NEXTSIBLING;
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Fri Apr 29, 2011 12:23 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

No that would not work the same .

The Repeat name clause just means that when you move to the next sibling the name of the tag needs to be the same. If the name of the tag is different on the next sibling you will get a lastmove(ref) = false.

You could equal it to
Code:
SET myname = fieldname(myref);
MOVE myref NEXT SIBLING NAME myname;


Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Fri Apr 29, 2011 12:24 pm    Post subject: Re: ESQL question Reply with quote

Grand High Poobah

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

Gideon wrote:
Could I simply write the line as follows to go to the next item in the list:
Code:

MOVE ref2 NEXTSIBLING;


You could, and it would find the next item in the list. If you code the NAME clause, it would find the next item in the list with the same name rather than just the next one.

Depends what you actually want to do. Both methods are valid in different circumstances.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Apr 29, 2011 12:27 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

That is an unusually clear statement of the problem. Thank you for taking the time to give all of the required information in your first post.

The 'REPEAT' keyword is used in two contexts.
1. As the REPEAT statement, as documented here: http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/topic/com.ibm.etools.mft.doc/ak05120_.htm
2. As a sub-clause in the MOVE statement, as documented here: http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/topic/com.ibm.etools.mft.doc/ak05090_.htm

In the code snippet that you quoted, the usage is 2.
When you MOVE a reference from one element to another, you can ask it to move to another 'similar' element. You can define 'similar' in three ways:
- REPEAT NAME means 'move to the next element with the same name'
- REPEAT TYPE means 'move to the next element with the same field type'
- REPEAT TYPE NAME means 'move to the next element with the same name and field type'
Back to top
View user's profile Send private message
Gideon
PostPosted: Tue May 03, 2011 12:24 pm    Post subject: Reply with quote

Chevalier

Joined: 18 Aug 2009
Posts: 403

(using the structure referenced in the link of my original post)

If I understand your posts correctly, will the following code:

Code:
DECLARE i      INTEFGER 1;
DECLARE ref    REFERENCE TO InputBody.Parent.SaleList[1];
CREATE  FIELD  OutputRoot.XML.Parent;   
DECLARE outref REFERENCE TO OutputRoot.XML.Parent;

WHILE LASTMOVE(ref) DO
   DECLARE invRef REFERENCE TO invRef.Invoice[1];
   WHILE LASTMOVE(invRef) DO

      DECLARE itemRef REFERENCE to invRef.Item[1];       
         
      WHILE (LASTMOVE(itemRef) = TRUE) DO     
         SET outref.Quantity[i] = itemRef.Quantity;       
         SET i = i + 1;
         MOVE itemRef NEXTSIBLING NAME 'Item';       
      END WHILE;             

      MOVE invRef NEXTSIBLING NAME 'Invoice';
   END WHILE;
   MOVE ref NEXTSIBLING NAME 'SaleList';
END WHILE;


produce the following output ???

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Parent>
    <Quantity>01</Quantity>
    <Quantity>01</Quantity>
</Parent>
Back to top
View user's profile Send private message Send e-mail
Vitor
PostPosted: Tue May 03, 2011 12:39 pm    Post subject: Reply with quote

Grand High Poobah

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

Gideon wrote:
(using the structure referenced in the link of my original post)

If I understand your posts correctly, will the following code:

Code:
DECLARE i      INTEFGER 1;
DECLARE ref    REFERENCE TO InputBody.Parent.SaleList[1];
CREATE  FIELD  OutputRoot.XML.Parent;   
DECLARE outref REFERENCE TO OutputRoot.XML.Parent;

WHILE LASTMOVE(ref) DO
   DECLARE invRef REFERENCE TO invRef.Invoice[1];
   WHILE LASTMOVE(invRef) DO

      DECLARE itemRef REFERENCE to invRef.Item[1];       
         
      WHILE (LASTMOVE(itemRef) = TRUE) DO     
         SET outref.Quantity[i] = itemRef.Quantity;       
         SET i = i + 1;
         MOVE itemRef NEXTSIBLING NAME 'Item';       
      END WHILE;             

      MOVE invRef NEXTSIBLING NAME 'Invoice';
   END WHILE;
   MOVE ref NEXTSIBLING NAME 'SaleList';
END WHILE;


produce the following output ???

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Parent>
    <Quantity>01</Quantity>
    <Quantity>01</Quantity>
</Parent>


Well strictly no, because nothing in that code produces the XML declaration!

As to what you really mean, I'll leave it to better minds than mine (or someone with time to try it) to determine if the construction:

Code:
   DECLARE invRef REFERENCE TO invRef.Invoice[1];


counts as a move for the LASTMOVE command. Certainly the itemRef & invRef will do as you expect.

As much for the benefit of future readers as you:

- Saying LASTMOVE(itemRef) = TRUE is tautological. Just say LASTMOVE or NOT LASTMOVE

- Remember that CREATE ..... AS sets the reference to the created field, saving you a line

- Consider CREATE LASTCHILD OF outref NAME 'Quantity' rather than SET outref.Quantity[i] for much the same reason
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kimbert
PostPosted: Tue May 03, 2011 12:53 pm    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Two points, both important
1. Don't ask us whether it will work. Try it and see. If it doesn't work, use the standard diagnostic facilities in the product ( debugger, Trace nodes, user trace ) and tell us what you found out.
2. Don't use the XML domain in new message flows. Use XMLNSC.
Back to top
View user's profile Send private message
Vitor
PostPosted: Tue May 03, 2011 1:02 pm    Post subject: Reply with quote

Grand High Poobah

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

kimbert wrote:
2. Don't use the XML domain in new message flows. Use XMLNSC.





_________________
Honesty is the best policy.
Insanity is the best defence.
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 » ESQL question
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.