cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic duplication of subtree

Former Member
0 Kudos

Hi,

I have one scenario where in the source structure I have one field in a node which

has some comma separated values and I need to map it to the target field and

the target node has to be repeated as many times as the comma separated values.

It will be like

Source Structure

<SNode>

<SField>1,2,3,4</SField>

</SNode>

Expected Target Structure

<TNode>

<TField>1</TField>

</TNode>

<TNode>

<TField>2</TField>

</TNode>

<TNode>

<TField>3</TField>

</TNode>

<TNode>

<TField>4</TField>

</TNode>

I can duplicate subtree in the target structure and extract each comma separetd values from the source filed and map it to the target using UDF.

But the problem is In the runtime I dont know how many comma separated values will be coming. So I need to dynamically create subtrees in the mapping?

Do you know what can be done in such cases?

Regards,

Accepted Solutions (1)

Accepted Solutions (1)

former_member190313
Active Participant
0 Kudos

hi

you can go for JAVA mapping . It will be very easy to do by java mapping

if you want i can mail you the code

Regards

Sheetal

Former Member
0 Kudos

Hi Sheetal,

Thanks for your reply. Yes. That can be done with ABAP mapping as well with DOM. Do you know any other way.

Thanks,

justin_santhanam
Active Contributor
0 Kudos

Praveen,

Please find the logic in the below URL.

TNode -http://www.flickr.com/photo_zoom.gne?id=1800802352&size=o

TField -http://www.flickr.com/photo_zoom.gne?id=1800802366&size=o

UDF -http://www.flickr.com/photo_zoom.gne?id=1800802368&size=o

Results:

http://www.flickr.com/photo_zoom.gne?id=1800802372&size=o

http://www.flickr.com/photo_zoom.gne?id=1800802384&size=o

raj.

Former Member
0 Kudos

It worked. Thanks.

Answers (1)

Answers (1)

0 Kudos

Hi,

with 2 UDFs you can reach your goal.

SNode->nodeSeparate->TNode

SField->valueSeparate->TField

UDFs:

public void nodeSeparate(String[] a,ResultList result,Container container){

String strValue = a[0];

String[] astrSingleValues = strValue.split(",");

for (int i = 0; i < astrSingleValues.length; i++)

{

result.addValue(astrSingleValues<i>);

}

}

public void valueSeparate(String[] a,ResultList result,Container container){

//write your code here

String strValue = a[0];

String[] astrSingleValues = strValue.split(",");

for (int i = 0; i < astrSingleValues.length; i++)

{

result.addValue(astrSingleValues<i>);

result.addContextChange();

}

}

regards

Bin

Former Member
0 Kudos

Hi Bin,

Thanks for your reply. I tried it but its not working. Have you check this thing in your system?

Thanks,