cancel
Showing results for 
Search instead for 
Did you mean: 

removing duplicate values from a queu in graphical mapping

Former Member
0 Kudos

Hi,

Can i remove duplicate values from a queu, but still keep the existing context changes?

Is it possible with graphical mapping (node functions) to go from this queue


<null>
[aaaa]
[aaaa]
[aaaa]
[aaaa]
[bbbb]
[bbbb]
[bbbb]
[contextchange]
[cccc]
[cccc]
[dddd]
[dddd]
[dddd]
[dddd]
[contextchange]
[eeee]
[eeee]
END OF QUEUE

to this queu:


<null>
[aaaa]
[bbbb]
[contextchange]
[cccc]
[dddd]
[contextchange]
[eeee]
END OF QUEUE

The number of times that a value occurs is variable, as is the number of values within a context, as is the number of context changes in the queue.

So, once more, question is how to remove the duplicates while keeping the context changes as they are.

Thx for advice

Kr

Robert

Accepted Solutions (1)

Accepted Solutions (1)

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

It'll be little difficult removing duplicates and keeping the context as it is with exixting standard functions. Removing duplicates irrespective of context changes, we can do with available functions. Please try with this UDF code which may help you...

source>sort>UDF-->Target

execution type of UDF is Allvalues of a context.

public void UDF(String[] var1, ResultList result, Container container) throws StreamTransformationException{

ArrayList aList = new ArrayList();

aList.add(var1(0));

result.addValue(var1(0));

for(int i=1; i<var1.length; i++){

if(aList.contains(var1(i)))

continue;

else{

aList.add(var1(i));

result.addValue(var1(i));

}

}

}

Regards,

Priyanka

Former Member
0 Kudos

Hi Priyanka,

I get some errors on your UDF:

com/sap/xi/tf/_Sender_2_Receiver_.java[165] cannot find symbol symbol : method var1(int) location: class com.sap.xi.tf._Sender_2_Receiver_ aList.add(var1(0));

this error appears 5 times.

kr

Robert

PriyankaAnagani
Active Contributor
0 Kudos

Hi,

After var1..it should be square brackets...change it in all 5 places

aList.add(var1[0]);

Regards,

Priyanka

former_member223322
Active Participant
0 Kudos

Try this.

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

String b = "";

b = a[0];

result.addValue(a[0]);

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

if(a(i).equals(b))

continue;

else{

b = a(i);

result.addValue(a(i));

}

}

}

Replace a(i) with square brackets.

Edited by: VaasPal on Dec 21, 2011 2:44 PM

Answers (3)

Answers (3)

Former Member
0 Kudos

use HashSet ..as it contains only unique values...

execution type: All values of a context..

Input will be var1


// duplicate values will get deleted
        Set hashSet = new HashSet(Arrays.asList(var1));
        String[] var2 = (String[]) hashSet.toArray(new String[hashSet.size()]);
        Arrays.sort(var2);
         for (int i = 0; i < var2.length; i++) 
         result.addValue(var2<i>);

http://forums.sdn.sap.com/thread.jspa?threadID=2009591&tstart=0

Former Member
0 Kudos

Hi Amitsri, Vaaspal, Priyanka,

Thx guys.

I tried all three solutions and they all do the job.

Kr

Robert

Former Member
0 Kudos

Hi.

just one observation about Amitsri solution .

Becareful with HashSet implementation because as said on java documentation :

+ It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.+

http://docs.oracle.com/javase/6/docs/api/java/util/HashSet.html

Regards.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>So, once more, question is how to remove the duplicates while keeping the context changes as they are.

Use standard node function splitbyvalue (value change).

http://help.sap.com/saphelp_dimp50/helpdata/en/21/3bb8c495125e4eb5969f0377885fe0/content.htm

Former Member
0 Kudos

Hi,

@bhavanisankar:

your solution gave the following queue


<null>
[aaaa]
[contextchange]
[bbbb]
[contextchange]
[cccc]
[contextchange]
[dddd]
[contextchange]
[eeee]
[end of queue]

@baskar:

your solution doesn't remove the duplicate values from the queue, it only adds contextchanges after a change in value.

kr

RObert

Former Member
0 Kudos

hi ,

question is how to remove the duplicates while keeping the context changes as they are.

try this below logic

Source field -> remove context -> sort-> split by value (value change) -> colapsecontext -> split by value (each value) -> target field

thanks,