cancel
Showing results for 
Search instead for 
Did you mean: 

UDF

Former Member
0 Kudos

Hi,

I need one udf to add quantities of material.

Input is:

BELNR QUANTITY

1001 100

1004 300

1001 50

1002 40

1001 50

1002 100

1007 500

Output should be:

1001 200

1004 300

1002 140

1007 500

Required UDF to get the above result.

Regards,

Rams.

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

I have done this for another purpose. You need two UDFs, one for the BELNR, one for the QUANTITY.

In my samples the parameters are named different, but I hope the principle is clear. You can just change the parameter names to your needs.

first: input parameter = taxCode

Vector taxCodeVector = new Vector();
for (int i = 0; i < taxCode.length; i++ ){
   if (!taxCodeVector.contains(taxCode<i>)){
      taxCodeVector.addElement(taxCode<i>);
      result.addValue(taxCode<i>);
   }  
}

second: input parameter = taxCode, amount

Vector taxCodeVector = new Vector();
Vector amountVector = new Vector();
// create vector from input array
for (int i = 0; i < taxCode.length; i++ ){
  int vectorIndex = taxCodeVector.indexOf(taxCode<i>);
// if tax code not in vector so far
   if (vectorIndex == -1){
// add tax code and amount to vecors
      taxCodeVector.addElement(taxCode<i>);
      amountVector.addElement(new BigDecimal(amount<i>));
   }  else {
// add the amount to the vector element corresponding to tax code
     BigDecimal currentAmount = (BigDecimal) amountVector.get(vectorIndex);
     amountVector.set(vectorIndex,currentAmount.add(new BigDecimal(amount<i>)));
   }
}
// output amount values
for (int i = 0; i < amountVector.size(); i++ ){
  result.addValue( ((BigDecimal) amountVector.get(i)).toString());
}

the UDFs are of type "value of a context", but you have to set the context if the incoming parameters to the highest level, so there is only one context.

Edited by: Stefan Grube on May 12, 2010 9:39 AM

Former Member
0 Kudos

Thanks Stefen,

Should I need to import any packages in UDF?? becuase it gives syntax errors in second UDF...

cannot find symbol symbol : class BigDecimal location: class com.sap.xi.tf._test_

amount.addElement(new BigDecimal(wmeng<i>));

cannot find symbol symbol : class BigDecimal location: class com.sap.xi.tf._test_

BigDecimal currentAmount = (BigDecimal) amount.get(vectorIndex);

help needed...

Rams

stefan_grube
Active Contributor
0 Kudos

yes, you need:

java.math.BigDecimal

sorry for not mentioning this.

Former Member
0 Kudos

Thank You Stefan for the solution...

Answers (0)