Author |
Message
|
smeunier |
Posted: Mon Nov 17, 2003 2:40 pm Post subject: Using an array in a REFERENCE statement |
|
|
 Partisan
Joined: 19 Aug 2002 Posts: 305 Location: Green Mountains of Vermont
|
I have been trying to use an dynamic array index in a REFERENCE statement within a loop, where the array index needs to reference the current value of the loop counter. I get no errors, but no data either. Does anyone know how to do this? Is there another approach?
Below is an example:
Code: |
DECLARE I INTEGER;
DECLARE C INTEGER;
DECLARE RefToOutputRoot REFERENCE TO OutputRoot.XML.(XML.Element)Z_SHIPMENT.Z1SHIPMENT_DATA[I];
SET C = 5;
SET I = 1;
WHILE I <= C DO
SET RefToOutputRoot.(XML.Attribute)SEGMENT= '1';
END WHILE;
The expect result would be:
<Z_SHIPMENT>
<Z1SHIPMENT_DATA SEGMENT='1'/>
<Z1SHIPMENT_DATA SEGMENT='1'/>
<Z1SHIPMENT_DATA SEGMENT='1'/>
<Z1SHIPMENT_DATA SEGMENT='1'/>
<Z1SHIPMENT_DATA SEGMENT='1'/>
</Z_SHIPMENT>
|
|
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Nov 17, 2003 2:59 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I don't think references work that way.
I'd try something like
Code: |
DECLARE I INTEGER;
DECLARE C INTEGER;
DECLARE RefToOutputRoot REFERENCE TO OutputRoot.XML.(XML.Element)Z_SHIPMENT.Z1SHIPMENT_DATA[1];
SET C = 5;
SET I = 1;
WHILE I <= C DO
 SET RefToOutputRoot.(XML.Attribute)SEGMENT= '1';
SET I = I + 1;
MOVE RefToOutputRoot NEXTSIBLING NAME 'Z1SHIPMENT_DATA';
END WHILE; |
But I have not tried this particular code, so it may need some tweaking to compile. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
dsim |
Posted: Mon Nov 17, 2003 8:36 pm Post subject: |
|
|
Acolyte
Joined: 11 Aug 2003 Posts: 67 Location: Toronto
|
Another try would be (also not compiled):
Code: |
DECLARE I INTEGER;
DECLARE C INTEGER;
SET C = 5;
SET I = 1;
WHILE I <= C DO
SET OutputRoot.XML.Z_SHIPMENT.Z1SHIPMENT_DATA[I].(XML.Attribute)SEGMENT= '1';
END WHILE; |
|
|
Back to top |
|
 |
Missam |
Posted: Thu Nov 20, 2003 12:39 pm Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Hi,
There is no need to reference you can directly do like this
DECLARE I INTEGER;
DECLARE C INTEGER;
SET C = 5;
SET I = 1;
WHILE I <= C DO
SET OutputRoot.XML.Z_SHIPMENT."Z1SHIPMENT_DATA"[I].(XML.Attribute)SEGMENT= '1';
SET I = I + 1;
END WHILE;
you can also do it using refereces
Thanx
Sam |
|
Back to top |
|
 |
dsim |
Posted: Thu Nov 20, 2003 2:26 pm Post subject: |
|
|
Acolyte
Joined: 11 Aug 2003 Posts: 67 Location: Toronto
|
IamSam,
Right, I have a missing
in the loop.
Thanks  |
|
Back to top |
|
 |
jefflowrey |
Posted: Thu Nov 20, 2003 5:25 pm Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
dsim wrote: |
IamSam,
Right, I have a missing
in the loop.
Thanks  |
So did the original poster.
And, for everyone's information, in this particular case, where you are only looping 5 times, it does not matter. But using Reference variables are much faster than using an array index. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|