Skip to Content

Merging Rows in a message


I have a file to idoc scenario. The incoming message has several rows, some of which have duplicate reference numbers, which indicate a VAT row

What I want to do is to create a single VAT node when 2 rows on the input file are encountered

EG  incoming message

Ref            Seqquence           Amount       

aaaa             0001                 10

aaaa             0002                   2

bbbb             0003                   17

cccc             0004                   90

dddd             0005                   20

dddd             0006                    4

This will create node EF1SET

   Ref              Sequence             Amount             tax amount 

   aaaa                0001                    10                       2

   dddd                0005                    20                       4

Is there a UDF which will allow this to be done

I was looking at this thread which allows only duplicates to be mapped

which is similar to my requirements, but I want to create a single output row when a duplicate is encounterd

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 22, 2012 at 04:27 PM

    Hi Hail,

    create two udf as same as define in thread  refer amit.srivastava8:

    create two udf one for amout field and 2nd for tax amount

    and use Following code

    in udf that you refer in thread.. for "amount"


       int a=var1.length; 

       if (a>1) 





    in udf that you refer in thread.. for "amount_tax"


       int a=var1.length; 

       if (a>1) 





    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 22, 2012 at 11:47 AM


    And you want to ignore single line references ? (bbbb and cccc in your example)



    Add comment
    10|10000 characters needed characters exceeded

    • Hi Geoff,

                       you can try this UDF of type "context"

      public void MergeValues(String[] Ref,String[] Seq,String[] amt,String[] targetType,ResultList result,Container container) throws StreamTransformationException{int i,j;boolean checked[]=new boolean[Ref.length];for(i=0;i<Ref.length;++i){               checked[i]=false;}for(i=0;i<Ref.length;++i){               checked[i]=true;               for(j=0;j<Ref.length;++j)               {                         if(checked[j])                         {                                   continue;                         }                         if(Ref[i].equals(Ref[j]))                         {                                   //got duplicate                                   if(targetType[0].equals("Ref"))                                   {                                             result.addValue(Ref[i]);                                   }                                   else if(targetType[0].equals("Seq"))                                   {                                             result.addValue(Seq[i]);                                   }                                   else if(targetType[0].equals("amt"))                                   {                                             result.addValue(amt[i]);                                   }                                   else if(targetType[0].equals("tax"))                                   {                                             result.addValue(amt[j]);                                   }                                   checked[j]=true;                         }//if          }//for }//outer for}//end

      The input to the UDF are 4 values "Ref","Seqquence","Amount " and a constant whose value might be one of these four values "Ref","Seq","amt" and "tax".

      The UDF has to be used once for each of the target and even for creating header node EF1SET. As shown below

      The above image shows the mapping to  create the header node which is parent of  the child nodes "Ref","Seq","amt" and "tax" .

      The above mapping shows the way to create the "tax" item. The same mapping step has to be replicated for "Ref","Seq" and "amt" fields in target. The only differing element is the constant term being supplied to "Mergevalues" UDF which will be "Ref", "Seq" and "amt" respectively (without quotes). The constant terms decide the kind of output as shown in above code in steps   20,24,28 and 32.

      Hope this resolves the problem.



      map4.png (16.4 kB)
      map3.png (14.0 kB)