cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping help required

Former Member
0 Kudos

Hi...

I am having structure like,

Source Structure

Root

Node1---(0unbounded)

Element1

Node2----(0unbounded)

Element2

Target Stucture

Root

Node--(0-unbounded)

Element3

The target Element3 should be Element1 * Element2------> Element3

My requirement should be

if Node1 is repeating and Node2 is occuring only once or

if Node 2 is repeating and Node1 is occuring only once

i need to get the output.

eg:

Node1

Element---2

Node 1

Element--4

Node2

Element ---3

Output should be like....

Node

Element----6

Node

Element----13

Can you please help in this maaping issue.

Regards

Leela

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

The below solution works fine


Node1-->exists----\
                or----->createif--->Node
Node2--->exists---/

Element1---\
           --->multiply(UDF)---->SplitByValue(Each Value)--->Element3
Element2---/

Change the context of Element1 to Node1 and Element2 to Node2.

udf

Use cache parameter context

public void multiply(String[] a,String[] b,ResultList result,Container container)
{
   //write your code here
int op ;
if(a.length < b.length)
{
for(int i = 0; i < a.length; i++)
{
for(int j = 0; j < b.length; j++)
{
   op = (Integer.parseInt(a<i>) * Integer.parseInt(b[j]));
   result.addValue(Integer.toString(op));
 }
}
}
else
{
for(int i = 0; i < b.length; i++)
{
for(int j = 0; j < a.length; j++)
{
   op = (Integer.parseInt(a[j]) * Integer.parseInt(b<i>));
   result.addValue(Integer.toString(op));
}
}
}
 }

Former Member
0 Kudos

Hi malini,

I have mapped like

Node1--Exists---

or----


Target Node.

Node2--Exists---

Element1------

UDF----split by value---Target Element3

Element2------

while executing i am getting the below error

/usr/sap/P70/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map6557e710c2bd11dda10f001d09112880/source/com/sap/xi/tf/_MM_Test_.java:75: illegal start of expression public void multiply(String[] a,String[] b,ResultList result,Container container) ^ /usr/sap/P70/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Map6557e710c2bd11dda10f001d09112880/source/com/sap/xi/tf/_MM_Test_.java:106: ';' expected ^ 2 errors

Can you please help where i have done wrong.

Regards,

Leela

Former Member
0 Kudos

Are you slecting Advanced User Defined Function while creating the UDF??

Former Member
0 Kudos

Hi leela,

It's working perfectly 4r me..

Hope u wud have missed the braces.

Check whether all the braces are closed propely or u wud have added an extra brace

Former Member
0 Kudos

Hi malini,

Below is the UDF code i am using.

public void multiply(String[] a,String[] b,ResultList result,Container container)

{

//write your code here

int op ;

if(a.length < b.length)

{

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

{

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

{

{

op = (Integer.parseInt(a<i>) * Integer.parseInt(b[j]));

}

result.addValue(Integer.toString(op));

}

}

}

else

{

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

{

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

{

{

op = (Integer.parseInt(a[j]) * Integer.parseInt(b<i>));

}

result.addValue(Integer.toString(op));

}

}

}

}

Can you please find any errors in that?

Former Member
0 Kudos

Ur code looks fine.

The error says as syntax midmatch in line 75

and ; missing in line 105

Check whether u have added anything extra int these lines..

Former Member
0 Kudos

Hi Leela

My requirement should be

if Node1 is repeating and Node2 is occuring only once or

if Node 2 is repeating and Node1 is occuring only once

i need to get the output.

I think this works without UDF as well

http://www.flickr.com/photos/32274480@N06/3085628230/

Thanks

Gaurav

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi friends,

Thanks for your replies. My query was solved.I have done the mapping what Gaurav has specified.

I have mapped like...

Node1--Exists----

or -


CreateIf -


TargetNode

Node2--Exists----

Element1(Context -Root)--


Multiply -


Split By Value -


Target Element.

Element2(Context -Root)--


Thanks,

Leela

Former Member
0 Kudos

Hey thanks alot for all your tip....

thanks..

Sidd.

Former Member
0 Kudos

i think there is problem with []...

SudhirT
Active Contributor
0 Kudos

Hi Siddhesh,

That is not the problem whenever you want Java code to look exactly as it is, you just select the code part and click on lessThan and greater than symbol in the reply pad.you will see it below Plain text and Preview tab in reply pad.

Thanks!

Former Member
0 Kudos

Hey sorry,

Just change the a to a<i>.

(a<i>*b[j])....

Former Member
0 Kudos

Hello Leela,

You can use the UDF,

select context and two input elements,

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

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

{

result.addValue((a<i>*b[j]));

}

}

let me know if this works or not.

Former Member
0 Kudos

Hi Siddhesh,

While testing with the YDF you have given i am getting the below error.

/usr/sap/P70/DVEBMGS00/j2ee/cluster/server0/./temp/classpath_resolver/Mapc8621bb0c2a811dd96a9001d09112880/source/com/sap/xi/tf/_MM_Test_.java:67: operator * cannot be applied to java.lang.String[],java.lang.String result.addValue((a*b[j])); ^ 1 error

Below is the source file i am having

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_In xmlns:ns0="http://Test">

<Node1>

<Element1>2</Element1>

<Element2/>

</Node1>

<Node2>

<Element3>3</Element3>

</Node2>

<Node2>

<Element3>4</Element3>

</Node2>

</ns0:MT_In>

Regards,

Leela

SudhirT
Active Contributor
0 Kudos

Hi,

this is because of

[]

converts to italic words use like this

for (int i=0; i<a.length; i++)
{ for (int j = 0; j< b.length; j++)
{ 

result.addValue((a<i>*b[j])); 
}
}

Thanks!

Former Member
0 Kudos

hi...

Can you please what will the source and the target for the UDF u have given.

Regards,

Leela

Former Member
0 Kudos

1 elements from node1 and 1 element from node 2.

SudhirT
Active Contributor
0 Kudos

Hi,

Source will be Element1 and Element2 and target will be Element3.

Thanks!

Former Member
0 Kudos

Hi Sekhar,

I have maaped in the same way u said, but i got the below error

Mapping object MM_Test incomplete. Unable to continue execution

Structure with min!=max without mapping

Regards,

Leela

SudhirT
Active Contributor
0 Kudos

Hi Leela,

Make sure that all your target fields are mapped with the occurence 1..1. If not map that with constant for time being.

thanks!

Former Member
0 Kudos

Node1,Node2 occurence shud be same According to the UDF, otherwise u get that error.

Check with equal occureance in each node.

Former Member
0 Kudos

Hi Sekhar,

Both the Nodes are having the same occurence.

Below is the source structure

<?xml version="1.0" encoding="UTF-8"?>

<ns0:MT_In xmlns:ns0="http://Test">

<Node1>

<Element1>2</Element1>

</Node1>

<Node2>

<Element3>3</Element3>

</Node2>

</ns0:MT_In>

Node1 and Node2 are 1--unbounded

Regards,

Leela

Former Member
0 Kudos

Hi Sudhir,

In target i am having only one element. That is mapped. For the Target Node it is 1---unbounded.

and the Element is 1.

what should i have to map to the target Node?

Regards,

Leela