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 » Loop through all fields for all parents?

Post new topic  Reply to topic
 Loop through all fields for all parents? « View previous topic :: View next topic » 
Author Message
klabran
PostPosted: Tue Mar 02, 2004 4:46 pm    Post subject: Loop through all fields for all parents? Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

I am trying to change the CHARGE_ROW element to a CHARGE element but my below code is not working. I am getting a subscript error. How do I loop through all fields for each and every CHARGE_ROW. I am using MQSI 2.1 CDS06.

<Citations>
<Citation>
<CHARGES>
<CHARGE_ROW>
<COUNT/>
<ARSCODE/>
</CHARGE_ROW>
</CHARGES>
</Citation>
</Citations>

DECLARE C INTEGER;
SET C = 1;
WHILE C <= (SELECT COUNT(*) FROM InputBody.Citations.Citation[I].CHARGES.CHARGES_ROW[] AS CHGNUM) DO
SET A = 1;
WHILE A <= CARDINALITY(InputBody.Citations.Citation[I].CHARGES.CHARGES_ROW[C].*[]) DO
SET OutputRoot.XML.Citation.CHARGES.CHARGE[C].*[A] = InputBody.Citations.Citation[I].CHARGES.CHARGES_ROW[C].*[A];
SET A = A + 1;
END WHILE;
SET C = C + 1;
--Remove charge_row
SET OutputRoot.XML.Citation.CHARGES.CHARGES_ROW[C] = NULL;
END WHILE;


Kevin
Back to top
View user's profile Send private message Visit poster's website
klabran
PostPosted: Wed Mar 03, 2004 7:57 am    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

Found out what is happening....

The parents are on a stack....

SET OutputRoot.XML.Citation.CHARGES.CHARGES_ROW[C] = NULL;

The above removes the Charges_row. However, because this is a stack the subscript error was occuring because the "Popping" of the stack to remove the element changes the subscripts of every other element left. I.E. - All element subscripts are now one less than before the "Pop".

To fix this I used another loop going from the last row to the first removing. I.E. - 5 to 1 not 1 to 5.

Learning esql by fire is exciting!

Kevin
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Wed Mar 03, 2004 8:10 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

It's not a "stack", it's a tree. The sooner you get a handle on this concept, the quicker you'll get a good idea of how ESQL works.

You're accessing childnodes by "nth child from the right" when you use Root.Element[n]. So if you change the number of children, you're going to get out of whack unless you're paying attention to what you're doing.

You can avoid this issue by using references instead of indexes. There are examples in the ESQL Reference manual and in the WBIMB help for how to navigate trees using anonymous references.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
klabran
PostPosted: Wed Mar 03, 2004 8:26 am    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

Thanks Jeff for the clarification.

I was just getting my info from the ESQL Reference on repeating fields. It uses the word "stack". (pg. 25 ESQL Reference 2.1)

Tree and stack to me could be used interchangibly in this instance.

I do agree on the getting used to working with "trees". The faster I get a grip on this the better I'll be.

Thanks!

Kevin
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Wed Mar 03, 2004 10:14 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

klabran wrote:
It uses the word "stack". (pg. 25 ESQL Reference 2.1)


Eiuuw.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
klabran
PostPosted: Wed Mar 03, 2004 12:40 pm    Post subject: Reply with quote

Master

Joined: 19 Feb 2004
Posts: 259
Location: Flagstaff AZ

I found an easier way to do it...

SET OutputRoot.XML.Citation.Charges.Charge[]=(SELECT R.ChargePrefix,R.ChargeCode FROM InputBody.Citations.Citation[I].Charges.Charges_ROW[] AS R);

The below statement removes the Charges_ROW tree altogether by returning null since I am using a bogus InputBody Tree (DoesNotExist)...

SET OutputRoot.XML.Citation.Charges.Charges_ROW[] = (SELECT R.* FROM InputBody.DoesNotExist[] AS R);

For some reason the below didn't work...? (Error - can't assign non list to list)
SET OutputRoot.XML.Citation.Charges.Charges_ROW[] = NULL;

Kevin
Back to top
View user's profile Send private message Visit poster's website
jefflowrey
PostPosted: Thu Mar 04, 2004 7:34 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

I think generally, select doesn't like working with multiple indexes.

You might get what you were doing to work if you use a reference for the FROM clause.

Something like (untested code)
Code:

declare thisRef REFERENCE to InputBody.Citations.Citations[i].Charges;
set OutputRoot.XML.Citation.Charges.Charge[]  (Select R.* from ThisRef.Charges_ROW[] as R);


Or maybe use "Charges_ROW.*" instead of "Charges_ROW[]", or even "Charges_ROW[].*".
_________________
I am *not* the model of the modern major general.
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 » Loop through all fields for all parents?
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.