Author |
Message
|
Gideon |
Posted: Fri Apr 29, 2011 11:58 am Post subject: ESQL question |
|
|
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 |
|
 |
fjb_saper |
Posted: Fri Apr 29, 2011 12:23 pm Post subject: |
|
|
 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 |
|
 |
Vitor |
Posted: Fri Apr 29, 2011 12:24 pm Post subject: Re: ESQL question |
|
|
 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 |
|
 |
kimbert |
Posted: Fri Apr 29, 2011 12:27 pm Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
|
Back to top |
|
 |
Gideon |
Posted: Tue May 03, 2011 12:24 pm Post subject: |
|
|
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 |
|
 |
Vitor |
Posted: Tue May 03, 2011 12:39 pm Post subject: |
|
|
 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 |
|
 |
kimbert |
Posted: Tue May 03, 2011 12:53 pm Post subject: |
|
|
 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 |
|
 |
Vitor |
Posted: Tue May 03, 2011 1:02 pm Post subject: |
|
|
 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 |
|
 |
|