Dear SCN Users,
In continuation to http://scn.sap.com/community/pi-and-soa-middleware/blog/2015/03/16/useful-udfs, adding some more UDFs.
11. UDF tostrip Left Zero
Code:
if(str == null)
{
return null;
}
int i;
char[] chars = str.toCharArray();
for(i = 0; i < str.length(); i++)
{
if(chars[i] != '0')
{
break;
}
}
return(i == 0) ? str : str.substring(i);
Output:
12. UDF to add Values in Queue/Context:
Code:
String output = "";
double total = 0.0;
for(int i=0;i<var1.length;i++)
total=total+Double.valueOf(var1[i].trim()).doubleValue();
output=total+"";
result.addValue(output);
Output:
13. UDF to remove duplicate/repeated entries in Context/queue
Code:
int i;
String val = new String();
for ( i = 0 ; i < input.length ; i++)
{
if ( input[i].equals(ResultList.CC))
{
result.addValue(ResultList.CC);
val = "";
continue;
}
if ( val.equals(input[i] ));
else
{
result.addValue(input[i]);
val = input[i];
}
}
Output:
NOTE: Sort the values before inputing the UDF
14. UDF to make 2 digits after the decimal point
After the decimal point if there is one digit in the input value, then this udf is used to add zero at the end to make 2 digits after the decimal. Example: if the input values is 1.1, then this udf used to display 1.10.
Code:
int len = value.indexOf(".") ;
int tot_len = value.length();
String result = "";
if (len > -1)
{
if((tot_len - len) == 2)
{
result = value.substring(0,len);
String temp1 = value.substring(len,tot_len);
return result + temp1 + "0";
}
if((tot_len - len) == 3)
{
return value ;
}
return value ;
}
else
return value ;
Output:
15. UDF To change Supress to empty value
Code:
for (int i=0;i<value.length;i++)
{
if(value[i].equals(ResultList.SUPPRESS))
result.addValue("");
else
result.addValue(value[i]);
}
Output:
Will be adding more UDFs soon.









