cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with basic "subtract" function

Former Member
0 Kudos

Hi Experts,

I have a strange error in mapping while using subtract function.

Field_A (20071001) - Constant (19000000) = Result (1071000)

The Result should be 1071001.

Check the screenshot of mapping.

http://docs.google.com/Doc?id=ddmc8m97_8gxczcgdt

Note:

--> I have tried the field as Integer, Float and String also, but same result.

--> It is not working for add function also, like

Field_A (20071001) + Constant (-19000000) = Result (1071000)

--> It is working fine for other values.

Please help me in this.

Regards,

Naveen Chamala

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Naveen!

Exactly! You're right! The function doesn't work properly.. I tried 3.06-3 and I got smth like 0.055555559 )

Well, I solved it with my own function:

double fa = Double.valueOf(a.trim()).doubleValue();

double fb = Double.valueOf(b.trim()).doubleValue();

return Float.toString((float)(fa-fb));

The problem in the "standard" function is probably in cast of values from one type to another.

Try some workaround with UDF.

Peter

Former Member
0 Kudos

Peter,

Thanks for your response. Is there any SAP note raised for this.

Regards,

Naveen

Former Member
0 Kudos

Peter,

Here i am using same type for source and target. Both are integers.

Regards,

Naveen

Former Member
0 Kudos

As I said - try to do it with UDF. If you are using integers, use other types in your function. All I know, there is a problem in standard function, so you need to create some workaround. Use my just like an example.

Peter

Former Member
0 Kudos

Peter,

I have never used UDFs. I am getting values as Strings(F1,F2). R = F1-F2

Can you send me the code for this.

Regards,

Naveen

Former Member
0 Kudos

Naveen,

create new UDF, enter its name and set up 2 input parameters a and b. The code is like following.

int aa = Integer.parseInt(a);

int bb = Integer.parseInt(b);

return Integer.toString(aa-bb);

Works fine for your numbers.

Peter

Former Member
0 Kudos

Hi Naveen,

If I understand your requirement correctly, then there is no need to go for UDF. I have a solution and it's working perfectly.

lemme summarize my understanding:

1) you have an integer/string of 8 digits

2) you will be subtracting with a constant 19000000

3) so u will generate 7 digit integer/string

4) the end system will add 19000000 and they will get the date

solution is as follows:

1) the normal subtract function

2) check the out put is ending with '0' (endWith)

3) If it ends with '0'

4) then repeat ur first subtract function and add function to that with a constant '1'

5) else your normal subtract function.

I dn't know how to upload the link... hence forwarding the screenshots to ur mail id.

Regards

Former Member
0 Kudos

Thanks Peter. It has solved my problem.

But most of the time we used to depend on std. functions. How can we work, if basic std. functions are not working properly.

Regards,

Naveen

Former Member
0 Kudos

Hi Naveen,

If we are willing to do a little work around with "standard functions" we can always achieve :-). this is my personal opinion.

Thanks & Regards

Former Member
0 Kudos

Hi vijaya,

I appreciate your effort in this mapping.

But everytime, whenever you require a sub. function simply u will use it. And it will work for your value.

Here It is not working for value (20071001). fortunately i have tested with this value.

As per basic mathmatics, 10-8=2, If XI says its not 8, it is 7 or something...do we need to use all these conditions for every no. ?

anyway, i am using the user defined function.

Regards,

Naveen

ik69
Participant
0 Kudos

Hi Naveen,

this is a common problem when working with big numbers. I am using UDF also for adding(summing) big numbers and negating them.

import java.math.BigDecimal;

public void sumBig(String[] list,ResultList result,Container container){

BigDecimal tmp;

BigDecimal sum;

sum = new BigDecimal("0");

tmp = new BigDecimal("0");

for (int i = 1; i <= list.length; i++)

{

tmp = new BigDecimal(list[i - 1]);

sum = sum.add( tmp );

}

result.addValue( sum.toString() );

}

public String negBig(String x,Container container){

BigDecimal tmp;

tmp = new BigDecimal( x );

tmp = tmp.multiply( new BigDecimal("-1") );

return tmp.toString();

}

Answers (2)

Answers (2)

Former Member
0 Kudos

All,

The problem with SAP arithmetic functions is fixed in the following SAP Note: 958486

Solutions for older versions of XI/PI can be found in the blog: /people/thorsten.nordholmsbirk/blog/2006/04/03/never-ever-use-xis-built-in-arithmetic-functions

Hope this helps,

Matt.

Former Member
0 Kudos

The screenshot has the value 2007100 instead of 20071001 !!

Former Member
0 Kudos

Priyanka,

It having correct values only. U can test the same in maping in ur mappings.

because of printScreen pixels, it is not clear. But i am sure about the value 20071001.

Regards,

Naveen