cancel
Showing results for 
Search instead for 
Did you mean: 

Is this possible with formatNum

former_member187437
Contributor
0 Kudos

Hi All,

My source field is of the format N(13,3) , (A Numeric field of lenth 13, out of which last 3 are decimal places and no decimal point ). I need to insert decimal point and map it to the Target Field.

if the input is 1234567890123 then output should be 1234567890.123

if it is 12345 then 12.345

Is it possible with formatNum function? If so, pls tell the parameters to be given for the function.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Use this UDF and your porblem will be solved..

see the link for results

http://www.flickr.com/photos/23639237@N02/2920517443/

Under Imports: java.math.BigDecimal;

if( ! a.equals(""))
{
BigDecimal bigA = new BigDecimal(a);
BigDecimal result = bigA.movePointLeft(3);
return result.toString();
}
return "000";

Regards,

Sarvesh

Answers (6)

Answers (6)

former_member187437
Contributor
0 Kudos

Hi ,

I wondered wheter it might b possible with ### of formatNum function. I have used a UDF now.

Thanks for all your valuable responses.

Former Member
0 Kudos

Ya,Sarvesh is right.

Arithmetic function jst rounds when large numbers r given.

Better try the below udf

Use cache parameter as Value.

1.


public String div(String a,Container container)
{
//write your code here
 double b = Double.parseDouble(a);
double c = b / 1000;
String output = Double.toString(c);
return output;
}

or

2.


public String place_decimal(String a,Container container)
{
//write your code here
 String output = a.substring(0,(a.length()-3)) + "." + a.substring(a.length()-3);
return output;
}

Former Member
0 Kudos

Hi Malini,

Even with your UDF if you test 1234567890123 then you will get the result "1.234567890123E9" in exponential format.

So it will be good to go ahead with my UDF.

Regards,

Sarvesh

Former Member
0 Kudos

Hi,

most of actual XI/PI systems should be XI 3.0 SP 18 or PI 7.0 SP 9. In this case it's possible to use the div function. Only necessary step is to set the parameter com.sap.aii.mappingtool.flib3.bigdecimalarithmetic in exchange profile to true like mentioned in the blog above. BTW this should be done anyway.

Regards

Patrick

Former Member
0 Kudos

Yes i never tried that option.

Wait i ll come up with a more better output.

Former Member
0 Kudos

Hi Patrick,

Thanks for this information. I have not yet done this in my system, but I will do.

Regards,

Sarvesh

Former Member
0 Kudos

Hi,

>Is it possible with formatNum function?

No! This is not possible

If you have for example 12345 your output will look like 12345.000

(maybe even with some leading zeroes).

Easiest solution is the one suggested by malini balasubramaniam to divide the input with 1000.

But you should do it this way if you yould be sure that your input is always numeric and you have at least XI 3.0 SP 18 or PI 7.0 SP 9.

Otherwise go for an UDF (then you could check for a numeric value).

Regards

Patrick

Edited by: Patrick Koehnen on Oct 7, 2008 9:46 AM

Former Member
0 Kudos

Hi,

Just to share with you all...

The biggest drawback in XI is it's Arithmetic function.. if you divide or multiply by 1000 or 100 to such a big string like 12345678901234 then you will never get the correct results..

so best way is to go for an UDF...

Regards,

Sarvesh

ParvathyS_SAP
Product and Topic Expert
Product and Topic Expert
0 Kudos

using UDF:

Input be A

Output be B

A1 = A.substring(0,(A.length()-3));

A2 = A.substring(A.length()-3);

B = A1 + "." + A2;

or through mapping :

input divide by 1000 = output

Former Member
0 Kudos

you can divide the number by 1000 to achieve this na.


src--------------------\
                         div--------->tgt
constant[1000]---/

Former Member
0 Kudos

write this simple UDF to achieve this

str1 is input parameter to be operated

str2 = str1.substring(str1.length()-3); // taking out last 2 for decimal places

str3 = str1.substring(0,(str1.length()-3)); // taking rest of the string

return str3 + "." + str2;

this can also be done using graphical mapping by combination of substring,cocat, etc