cancel
Showing results for 
Search instead for 
Did you mean: 

How to do Multi-Mapping based on one field?

Former Member
0 Kudos
55

Hi All,

I am now doing multi-mapping like this:

Source A:

<A>

<A1>

<A2>a</A2>

<A3>b</A3>

</A1>

<A1>

<A2>c</A2>

<A3>d</A3>

</A1>

<A1>

<A2>e</A2>

<A3>f</A3>

</A1>

</A>

Source B:

<B>

<B1>

<B2>e</B2>

<B3>x</B3>

</B1>

<B1>

<B2>a</B2>

<B3>y</B3>

</B1>

</B>

Target C's structure is the same as A.

What I want to do is: If the value of A2 equals the one value of B2s, mapping B2,B3 to C2,C3; else maping A2,A3 to C2,C3, like this:

<C>

<C1>

<C2>a</C2>

<C3>y</C3>

</C1>

<C1>

<C2>c</C2>

<C3>d</C3>

</C1>

<C1>

<C2>e</C2>

<C3>x</C3>

</C1>

</C>

What's more, all the B2 value set belongs to A2 value set.

Is it possible? Any comment or suggestion is grateful!

Regards,

Nick

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member187339
Active Contributor
0 Kudos

Hi

You have to create a UDF (context):

>>If the value of A2 equals the one value of B2s,

I suppose any one value of B2

<u>Input</u>

A2(Context A)

B2(Context B)

public void createTarget(String[] A2,String[] B2,ResultList result,Container container){

int j=0, flag=0,k=0;

for (k=0;k<A2.length;k++)

{

for (j=0;j<B2.length;j++)

{

if (A2[k].equals(B2[j]))

{

flag=1;

result.addValue(""+B2[j]);

}

}

if (flag == 0) result.addValue(""+A2[k]);

flag=0;

}

}

A2(context A)|-- createTarget -- Splitbyvalue -- C2

B2(context B)|--

Same goes for C3 (with all values in terms of 3).. You can use the same UDF.

Regards

Suraj

Message was edited by: S.R.Suraj

stefan_grube
Active Contributor
0 Kudos

Hi Suraj,

When b2 is equal a2, you take b2, otherwise a2.

You can always take a2

Here is my example for c3 (already tested):

public void myFunction(String[] a2,String[] b2,String[] a3,String[] b3,ResultList result,Container container){

for (int k=0;k<a2.length;k++)
if(a2[k].equals(ResultList.CC))
  result.addContextChange();
else{
  boolean found = false;
  String resultValue = a3[k];
  for(int l=0;l<b2.length;l++)
    if(a2[k].equals(b2[l])){
      resultValue = b3[l];
      break;
    }
  result.addValue(resultValue);
}

}

Regards

Stefan

former_member187339
Active Contributor
0 Kudos

Hi,

>>Same goes for C3 (with all values in terms of 3).. You can use the same UDF.

I think the same UDF can't be used:

You have to change the above UDF slightly

<b>public void createC3(String[] A2,String[] B2,String[] A3,String[] B3,ResultList result,Container container){

int j=0, flag=0,k=0;

for (k=0;k<A2.length;k++)

{

for (j=0;j<B2.length;j++)

{

if (A2[k].equals(B2[j]))

{

flag=1;

<i>result.addValue(""+B3[j]);</i>

}

}

if (flag == 0)

<i>result.addValue(""+A3[k]);</i>

flag=0;

}

}</b>

A2(Context A) |

B2(Context B) |---- createC3---Splitbyvalue --- C3

A3(Context A) |

B3(Context B) |

Regards

Suraj

Former Member
0 Kudos

Thanks Stefan,

This works!

Regards,

Nick

Former Member
0 Kudos

A1--->C1

A2----


...........then...\

A2-----\

-


|>StringEquals>if..............|-->c2

B2------/

B2----


...........ELSE...../

A3----


...........then...\

A2-----\

-


|>StringEquals>if..............|-->c3

B2------/

B3----


...........ELSE...../

Regards,

KNS Kumar.

stefan_grube
Active Contributor
0 Kudos

Hi KNS Kumar,

Your example works only if

- A2 and B2 have exactly the same number of values

- you compare only values at the same place in the source.

The original problem requires a look-up in B2 in all values. This is not possible with the standard functions.

Regards

Stefan

Former Member
0 Kudos

Thanks Kumar & Stefan,

Yes, that logic can not handle my issue, as B2 is less than A2, and they are not in sequence by value in my scenario.

Regards,

Nick

Former Member
0 Kudos

Hi Nick,

You can do this easily using the standard functions....to know how to implement the same....pls go through this link:

http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm

Pls see this link which explains a similar scenario with a screen shot.

http://help.sap.com/saphelp_nw04/helpdata/en/5d/db0e83e8e74202a5bff527055ab7e5/content.htm

Regards,

abhy

stefan_grube
Active Contributor
0 Kudos

Hi Nick,

When I understood the correct, then you want:

C2 = A2

C3 = (if A2 exists in B2: B3 else A3)

You can do this easily with a user defined function where you have A2, A3, B2 and B3 as input parameters and cache the whole queue. The result list of this function should look like follows:

y

ContextChange

d

ContextChange

X

Check out this blog for testing user defined functions in an Java environment:

/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio

Regards

Stefan