on 05-12-2010 8:15 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.