 Former Member

# Problem in Graphical message mapping.Need UDF to add array based on some co

Hi All,

I have been struck in message mapping.Below i am explaining it,

I have two input array,

one array lets call X 









other array is Y 







 .length of both the array will be same .

Now I want the output as: if there is any same value in first array i.e array X then corresponding value of second array should be added.i.e in array X if 24 is coming as twice (1st and 4th) then 1st and 4th value of array Y will be added.So here there will be only three output as Z





Please guide me if posiible .I tried to use the for loop but its not working as the value of X is repeating.

Regards,

Saurabh

10|10000 characters needed characters exceeded

### Related questions Former Member
Posted on Aug 01, 2008 at 09:26 AM

Hi Sentil,

My problem is at all not realted with BPM .Its simple mapping problem where ineed to write some UDF to achive the functionality .The problem is that it can't be achived by simple array so we might have to use Linked List or Set .

10|10000 characters needed characters exceeded
• Hi,

Tru this..

```public void test(String[] a,String[] b,ResultList result,Container container){
int flaga,flagb;
for(int i=0;i<a.length;i++)
{
flaga =0;
for(int j=i+1;j<a.length;j++)
{
int p =  Integer.parseInt(a<i>);
int q =  Integer.parseInt(a[j]);
if(p==q)
{
flaga =1;
int c = Integer.parseInt(b<i>)+Integer.parseInt(b[j]);
String d = new Integer(c).toString();
}

}
if (flaga ==0)
{
flagb=0;
for(int q =i-1; q>=0;q--)
{
if(Integer.parseInt(a<i>) == Integer.parseInt(a[q]))
flagb = 1;
}
}

}
}```

I have tested with the same input... it is working for me 😊

Thanks

SaNv...

• Former Member
Posted on Aug 01, 2008 at 09:05 AM

Hi,

use collect pattern method

/people/sravya.talanki2/blog/2005/08/24/do-you-like-to-understand-147correlation148-in-xi

http://help.sap.com/saphelp_nw2004s/helpdata/en/a5/64373f7853494fe10000000a114084/frameset.htm

BPM CollectPattern..

http://help.sap.com/saphelp_nw2004s/helpdata/en/08/16163ff8519a06e10000000a114084/frameset.htm

thanks,

sendil

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 01, 2008 at 09:24 AM

Hi Saurabh,

This is fairly simple and you can do it without UDF.

Here is the solution :

1. Sort first array ( make sure that all the values are in single context )

2. Sort second array by key and the key will be sorted first array. ( here alos all values of second array should be in a single context )

3. apply split by value function with parameter value change on first array.

4. apply format by example function on second array with first argument to that format by example will be your second array and second argument will be output of step 3

5. then use sum function and you will get the desired output.

Try this and check the queues at each step.

• Reward points if it helps you

Regards,

Shri

10|10000 characters needed characters exceeded
• Posted on Aug 01, 2008 at 09:24 AM

Hi,

Try this UDF

```public void test(String[] a,String[] b,ResultList result,Container container) {
for(int i=0;i<a.length;i++)
{
for(int j=i+1;j<a.length;j++)
{
if(a<i>==a[j])
{
int c = Integer.parseInt(b<i>)+Integer.parseInt(b[j]);
String d = new Integer(c).toString();
}
}
}
}```

Thanks

SaNv...

10|10000 characters needed characters exceeded
• Former Member
Posted on Aug 01, 2008 at 09:41 AM

Hi Santosh,

your UDF solution is the right approch in beginning I have also tried the same approch .But it has one major problem. The array X values are repeating so once you Used the value then you have to delete the value from the firs array otherwise it will be get duplicated.

For Ex in first foo loop at first it will search for 24 now at second time again it may find 24 in that case it will be problem .It might be the all the value of Array X is same then iwant only one output as some of all.but with the uDf you have written it will produce more than one output.Please ask if you have any confusion

10|10000 characters needed characters exceeded
• Former Member

take 2 inputs as 2 arrays, adjust the context so that all values will come

```for(i=0;i<a.length;i++)
{
temp=a<i>;
for(j=i+1;j<a.length-j;j++)  // j< a.length-j
{
if(temp==a[j]){
sum = b<i>+b<i>;
flag =1;
}
} //end for j
if(flag != 1){