cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Loops

Former Member
0 Kudos

Hello all.

I am currently attempting to develop a scenario that takes a CSV file and maps it to an XML file.

I have defined two XML structures, one is a very simple flat one, used for the CSV import in cooperation with the plan2xml adapter module. The second is a more complex XML structure that will be the target message.

The source file has 5 fields that are multidimensional. So for example, there is a field called WEIGHT in which the value of the field may be:

5.800,7.400,4.200,1.606

The target XML structure has an unbounded element, consisting of several subelements. Looks similar to this:

-UnboundedElement

-element1

-element2

-element3

-element4

I would like to loop the unbounded element, so that for each multidimensional field in the source message, I can store that data in the unbounded element. So, more simply, it should look something like this:

Start Loop:

-First iteration:

copy 5.800 to element1 of unboundedelement

-Second iteration

copy 7.400 to element1 of unboundedelement

etc.

(1) First I need to know how to create that loop.

(2) Second, what is the best way to map this? It seems to me that there should be a way to combine existing functions to make this possible. But do you think I would have to create a user defined function to do this?

Thanks in advance. I hope I explained this clearly enough.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I'm not sure if i'm right... but as far i understand you have a source structure with the WEIGHT value.

like:

<weight>5800</weight>

<weight>7400</weight>

<weight>4200</weight>

...

and you want a target structure like:

<unboundedelement>

<element1>5800<element1>

<element1>7400<element1>

<element1>4200<element1>

<element2/>

<element3/>

<element4/>

</unboundedelement>

For this ist looks very easy just map the Weightelement in Kontext of the hole message or some higher level tag to your element1 in the target structure.

And now you can tell me where i understand you wrong

And i will try again.

Regards,

Robin

Former Member
0 Kudos

Close, but a little bit different.

Source message WEIGHT field looks like this:

5800,7400,4200

...

And the target structure should look like this:

<unboundedelement>

<element1>5800<element1>

<element2/>

<element3/>

<element4/>

</unboundedelement>

<unboundedelement>

<element1>7400<element1>

<element2/>

<element3/>

<element4/>

</unboundedelement>

<unboundedelement>

<element1>4200<element1>

<element2/>

<element3/>

<element4/>

</unboundedelement>

I have decided to avoid the requirements for the loop by simply changing the data type of the target message to have 4 instances of <b>unboundedelement</b>. However, I still have to split that value in WEIGHT up into multiple target fields. I believe I can use the <b>substring</b> function, in cooperation with a conditional statement to verify that something exists in that location. I'm going to try this out, and I'll let you all know if I am still stuck.

Former Member
0 Kudos

Hi,

I guess it difficult to change the context with a substring function.

try to put the value into a user-function.

There you can split the value in a loop with substring.

And in the loop you will set the value and change to context on the target structure:

result.addValue(ActualValue);
result.addContextChange();

Regards,

Robin

Former Member
0 Kudos

How does the looping work in a user defined function? Is there any examples of code that I can look at?

Former Member
0 Kudos

Hi,

You have to set your user-function as Queue with your input parameter for example "weight".

And than you have to do something like this:


for ( int ii = 0; ii < weight.length; ii++ ){
result.addValue(weight[ii]);
result.addContextChange();
}

Regards,

Robin

Former Member
0 Kudos

Hi,

Assuming your input as:

111,222,333

you would need to remove the delimiter "," first

Try this out:

String[] x = a.split(",");

for(int j=0;j<x.length;j++)

{

result.addValue(x[j]);

result.addContextChange();

}

where a is the input String.

Regards,

Smitha.

Message was edited by:

smitha rao

Former Member
0 Kudos

I created a function that looks like that. It will run without an error but it doesn't actually create the contexts' and put the values in them.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Harrison:

(1) First I need to know how to create that loop.

--> In your integration repository goto software component SAP BASIS.

There are examples (See multi-mapping)!

Regards Mario

Former Member
0 Kudos

Which one would be a good example of this? Are there any links to documentation you could provide?

Former Member
0 Kudos

Name: MultipleFlightBookingCoordination

Namespace: http://sap.com/xi/XI/Demo/Agency

Software Component: SAP BASIS 6.40

--> Split of a multiple booking order and merge of single confirmations

Regards Mario

Former Member
0 Kudos

I have been reading that it's impossible to do a loop without a user defined function. Is this the case?

Former Member
0 Kudos

Hi Harrison,

sorry, my approach was wrong.

The kind of LOOP you require is different.

Regards Mario

Former Member
0 Kudos

Does anyone have any advice?