Skip to Content
avatar image
Former Member

removing duplicate values from a queu in graphical mapping

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    Dec 21, 2011 at 01:13 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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

  • avatar image
    Former Member
    Dec 21, 2011 at 12:50 PM

    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,

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 21, 2011 at 12:57 PM

    >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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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

  • Dec 21, 2011 at 01:57 PM

    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

    Add comment
    10|10000 characters needed characters exceeded