on 03-03-2009 2:25 PM
Hi Experts,
I need a great help from you all...I will get the source strcuture like following formats...
1. 123,456,789.98
2. 123.456.789,98
3. 123 456 789.98
But i need only one format in the target that is : 123456789.98...(however it is, i need only " . " in decimals nothing else)
How do I get like this format? Help is needed...
Thanks-
Ramesh.
Hi,
You may use this UDF:
UDF type is of value type:
argument is input
String adec = input.substring(input.length()-3, input.length());
String bdec = input.substring(1,input.length()-3);
if (bdec.indexOf(" ")>-1){bdec = bdec.replaceAll(" ","");}
else if (bdec.indexOf(",")>-1){bdec = bdec.replaceAll(",","");}
else bdec.replaceAll(".","");
System.out.println(bdec+adec);
Hope this helps,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Thanks for your UDF....
I have used your UDF but it is not working fine: please check following input and output from your UDF..
input: 12,446.67
output: 12,446.67
both are same...
but i need output like: 12446.67
and also if the input is like this: 12.446,67 then output must be 12446.67....
Thanks once again...but it doesn't work for my requirement...
Ramesh.
udf is:
String adec = input.substring(input.length()-3, input.length());
String bdec = input.substring(1,input.length()-3);
if (bdec.indexOf(" ")>-1)
{
bdec = bdec.replaceAll(" ","");
}
else if (bdec.indexOf(",")>-1)
{
bdec = bdec.replaceAll(",","");
}
else bdec.replaceAll(".","");
return bdec+adec;
Hi,
I modified the UDF, it should now be able to handle the special character ..
UDF is of value type,
argument is input
int c[] = null;int cnt=0, cnt1 =0;
StringBuffer e = new StringBuffer();
String adec = input.substring(input.length()-2, input.length());
String bdec = input.substring(0,input.length()-3);
if (bdec.indexOf(" ")>-1){bdec = bdec.replaceAll(" ","");return(bdec+"."+adec);}
else if (bdec.indexOf(",")>-1){bdec = bdec.replaceAll(",","");return(bdec+"."+adec);}
else {
for (int a=0; a<bdec.length();a++){if (bdec.indexOf(".",a)>a){cnt++;a=bdec.indexOf(".",a);}}
c = new int [cnt];cnt1=cnt;cnt=0;
for (int a=0;a<bdec.length();a++){if (bdec.indexOf(".",a)>a){a=bdec.indexOf(".",a);c[cnt]=a;cnt++;}}
cnt = 0;
for (int a=0;a<c.length;a++){e= e.append(bdec.substring(cnt,c[a]));cnt=c[a]+1;}
return(e.toString()+bdec.substring(cnt,bdec.length())+"."+adec);}
Let me know if this works,
Regards
Edited by: Mark Dihiansan on Mar 4, 2009 6:49 AM
Hi,
Just add these 3 lines in your udf.
public String removeComma(String a,Container container){
//write your code here
String b = "";
b = a.replaceAll(",", "");
return b;
}
you will get your desired result.
Thats all.
Regards
Aashish Sinha
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ramesh,
you can achieve that with standard function FormatNum. See [Standard Functions|http://help.sap.com/saphelp_nw2004s/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm]
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Udo,
I have tried FormatNum function but it is throwing a javaexception, and its not working...
"RuntimeException in Message-Mapping transformation: Exception:[java.lang.NumberFormatException: For input string: "80,008.80"] in class com.sap.aii.mappingtool.flib3.Arithm method formatNumber[ 80,008.80, com.sap.aii.mappingtool.tf3.rt.Context@3a7f684c"
Please help me to resolve this issue.
Thanks-
Ramesh.
Hi
Ramesh now i understand , keeping in mind that i shud remove i wrote a small UDF any ways
as shown above use replace function in between and do slight modifications
public class JavaCommaRem {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
JavaCommaRem obj = new JavaCommaRem();
String out=obj.TestB("12,3456,789.98");
System.out.println("Output"+" "+out);
} //12,345,6789.98
String TestB (String num)
{
String in = num;
int count = in.length();
int index1 = in.indexOf(",");
System.out.println("index1"+" "+index1);
if (index1 == -1)
{
return in;
}
else
{
String str1 = in.substring(0,index1);
System.out.println("Str1"+" "+str1);
String StrRem1 = in.substring(index1+1,count);
System.out.println("StrRem1 "+" "+StrRem1);
//Second Trun
int count1 = StrRem1.length();
int index2 = StrRem1.indexOf(",");
System.out.println("index2 "+" "+index2);
if (index2==-1)
{
System.out.println("Inside lop");
return str1+StrRem1;
}
else
{
String str2 = StrRem1.substring(0,index2);
System.out.println("str2"+" "+str2);
String StrRem2 = StrRem1.substring(index2+1,count1);
System.out.println("StrRem2 "+" "+StrRem2 );
return str1+str2+StrRem2;
}
}
}
}
thx
srini
I can give some idea for proceeding as i dont have exact classes to write udf
String no = new String("123,456,789.98");
int count =0;
count = no.indexOf(",");
System.out.println("count"+count);
if(count!=0)
no = no.replaceAll(",", "");
System.out.println("no"+no);
You can go like the above findout if there are commas,dots ,... and then replace them with null
this will solve your problem hope
Rajesh
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
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.