Author |
Message
|
ydeonia |
Posted: Sat May 11, 2013 4:16 pm Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
hello all
the below code gives me output
Code: |
CREATE PROCEDURE ExtractTyreCodes() BEGIN
DECLARE rOutput REFERENCE TO OutputRoot;
DECLARE rResource REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster;
CREATE FIELD OutputRoot.XMLNSC.root AS rOutput;
IF LASTMOVE(rResource) THEN
SET rOutput.row[] = SELECT
THE(SELECT C.*:Codes.*:Code AS TyreBrand
FROM T.*:Classification[] AS C
WHERE C.(XMLNSC.Attribute)Type = 'BRAND') AS product_Info
FROM rResource.*:ItemMasterHeader[] AS T;
END IF;
END; |
output
Code: |
<root>
<row>
<product_Info>
<TyreBrand>002</TyreBrand>
</product_Info>
</row> |
But I dont know how can I add more values in the tag product_Info like this
The above code will make seperate tags in product_Info but I want to fetcj more values in the product_Info without making seperate tag for product_Inf. Like if want to fetch another attribute Type' LP' it shouldny come like
Code: |
<root>
<row>
<product_Info>
<TyreBrand>002</TyreBrand>
</product_Info>
<product_Info>
<TyreBrand>LP</TyreBrand>
</product_Info>
</row> |
BUt it should come like
Code: |
<root>
<row>
<product_Info>
<TyreBrand>002</TyreBrand>
<TyreBrand>LP</TyreBrand>
</product_Info>
</row> |
How can I achieve this
Thanks |
|
Back to top |
|
 |
mqjeff |
Posted: Sun May 12, 2013 6:41 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Code: |
SET rOutput.row[] = SELECT
THE(SELECT C.*:Codes.*:Code AS TyreBrand
FROM T.*:Classification[] AS C
WHERE C.(XMLNSC.Attribute)Type = 'BRAND') AS product_Info
FROM rResource.*:ItemMasterHeader[] AS T;
FOR thisRow AS rOutput.row[] DO
-- do some work
END FOR; |
|
|
Back to top |
|
 |
RAJASHEKAR REDDY |
Posted: Sun May 12, 2013 10:56 pm Post subject: HI,,,,USE THIS CODE |
|
|
Novice
Joined: 09 May 2013 Posts: 13
|
Hi ,
USE THIS CODE.....it will work
CREATE COMPUTE MODULE WMB_9D1_PROD_SUB00_001
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
--CALL CopyEntireMessage();
DECLARE itemMaster REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster;
-- Construct Final Response XML
DECLARE rowCnt INTEGER 0;
DECLARE LineCount INTEGER 1;
DECLARE temp ROW;
----- DECLARE myref REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster.*:ItemMasterHeader;
SET rowCnt = rowCnt+1;
SET OutputRoot.XMLNSC.root.(XMLNSC.Attribute)name='Product';
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.ProductCd = THE (SELECT ITEM FIELDVALUE(T) FROM itemMaster.*:ItemMasterHeader.*:ItemID.*:VariationID AS T where FIELDVALUE(T.(XMLNSC.Attribute)SchemeName)='CAI');
---- MOVE myref FIRSTCHILD NAME 'Classification';
FOR refClassification AS itemMaster.*:ItemMasterHeader.*:Classification[] DO
IF refClassification.(XMLNSC.Attribute)Type = 'BRAND' THEN
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = refClassification.Codes.Code;
END IF;
SET LineCount = LineCount + 1;
------------ MOVE myref NEXTSIBLING;
END FOR;
RETURN TRUE;
END; |
|
Back to top |
|
 |
Esa |
Posted: Sun May 12, 2013 11:05 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
@RAJASHEKAR REDDY:
somebody wrote: |
You clearly don't understand references clearly yet. You are using them "offshore style" like people who have been told to use references. They declare a reference but still do the actual coding with their beloved loop counters and array indexes. |
 |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 2:37 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Esa wrote: |
@RAJASHEKAR REDDY:
somebody wrote: |
You clearly don't understand references clearly yet. You are using them "offshore style" like people who have been told to use references. They declare a reference but still do the actual coding with their beloved loop counters and array indexes. |
 |
Here y not working
Code: |
CREATE COMPUTE MODULE WMB_9D1_PROD_SUB00_001
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
--CALL CopyEntireMessage();
DECLARE rowCnt INTEGER 0;
DECLARE myref REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster.*:ItemMasterHeader;
SET rowCnt = rowCnt+1;
MOVE myref FIRSTCHILD NAME 'Classification';
WHILE LASTMOVE(myref)= TRUE DO
IF myref.Type = 'BRAND' THEN
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = myref.*:Codes.*:Code;
END IF;
MOVE myref NEXTSIBLING;
END WHILE; |
|
|
Back to top |
|
 |
Esa |
Posted: Mon May 13, 2013 2:53 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
Shouldn't you increment the row counter within the while loop?
Code: |
MOVE myref NEXTSIBLING REPEAT NAME; |
|
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 3:50 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Esa wrote: |
Shouldn't you increment the row counter within the while loop?
Code: |
MOVE myref NEXTSIBLING REPEAT NAME; |
|
Thanks I will check that . Anyway nice signature in Hindi. |
|
Back to top |
|
 |
Esa |
Posted: Mon May 13, 2013 5:05 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
ydeonia wrote: |
Anyway nice signature in Hindi. |
Thank you very much. शुक्रिया |
|
Back to top |
|
 |
ydeonia |
Posted: Mon May 13, 2013 8:03 pm Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
Esa wrote: |
Shouldn't you increment the row counter within the while loop?
Code: |
MOVE myref NEXTSIBLING REPEAT NAME; |
|
Not working
whats wrong the code. I am not getting the value
Code: |
CREATE COMPUTE MODULE WMB_9D1_PROD_SUB00_001
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
CALL CopyMessageHeaders();
DECLARE rowCnt INTEGER 0;
DECLARE myref REFERENCE TO InputRoot.XMLNSC.*:SyncItemMaster.*:DataArea.*:ItemMaster.*:ItemMasterHeader;
SET rowCnt = rowCnt+1;
SET OutputRoot.XMLNSC.root.(XMLNSC.Attribute)name='Product';
MOVE myref FIRSTCHILD NAME 'Classification';
WHILE LASTMOVE(myref)= TRUE DO
IF myref.Type = 'BRAND' THEN
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = myref.*:Codes.*:Code;
END IF;
MOVE myref NEXTSIBLING REPEAT NAME;
END WHILE;
END; |
|
|
Back to top |
|
 |
fjb_saper |
Posted: Mon May 13, 2013 8:10 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
It would help if you'd post again what the input XML looks like.
I believe what you need are 2 references.
- 1 reference at the "loop" level
- 1 reference somewhere below where you check the children for name and value. Within the upper loop you will always have to initialize the lower reference before starting the lower loop.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Esa |
Posted: Mon May 13, 2013 10:37 pm Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
[quote="ydeonia"]
Esa wrote: |
Shouldn't you increment the row counter within the while loop?
|
Means:
Code: |
...
WHILE LASTMOVE(myref)= TRUE DO
SET rowCnt = rowCnt+1;
IF myref.Type = 'BRAND' THEN
SET OutputRoot.XMLNSC.root.row[rowCnt].product_Info.TyreBrandCd = myref.*:Codes.*:Code;
END IF;
MOVE myref NEXTSIBLING REPEAT NAME;
END WHILE;
...
|
Otherwise you would be overriding the same element value each time. If the last value happens to be null you will get nothing.
Do you know how to debug? That's what people do when they don't get the results they expect. |
|
Back to top |
|
 |
ydeonia |
Posted: Tue May 14, 2013 5:56 am Post subject: |
|
|
Acolyte
Joined: 29 Oct 2012 Posts: 74
|
|
Back to top |
|
 |
|