Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results forĀ 
Search instead forĀ 
Did you mean:Ā 
Read only

negative values subtraction

former_member188791
Participant
0 Likes
1,809

Hi Group,

Hi ,

its regarding ABAP arithmetic,In my input file I am getting 3 currency fields  name LM,PM, CM every time

I need to check the condition PM = LM - CM ,if it is not true needs to raise error message.

this is all working fine , but when I am getting negative values in the file my calculation going wrong ,instead of subtraction it is doing addition.I am getting the below scenarios:

LM +

PM +

CM -

LM -

PM -

CM +

Can any body suggest how I can handle this in ABAP.

7 REPLIES 7
Read only

DominikKraemer
Active Participant
0 Likes
1,249

Hi Rajiv,

this is normal mathematic behaviour LM - (-CM) is the same as LM + CM...

If this behaviour is unwanted, check if the value is below 0 and then multiplicate with -1

Regards,

Dominik

Read only

0 Likes
1,249

Hi Rajiv,

If you do not want to consider the sign of each currency you can use the abs(variable) mathematical function.

Thanks & Regards,

Vijeta Galani.

Read only

Former Member
0 Likes
1,249

Hi,

PM = LM - CM is same as LM = PM + CM. This will solve the - sign problem.

Read only

Former Member
0 Likes
1,249

This message was moderated.

Read only

matt
Active Contributor
0 Likes
1,249

Let's say:

LM = 5

CM = -3

LM-CM = 8. So PM must be 8.

LM  = -5

CM = 3

LM-CM = -2. So PM must be -2.

Why do you expect anything else? What are you actually trying to do? What is the business scenario.

Read only

Former Member
0 Likes
1,249

I guess he wants to find difference of absolute values, ignoring sign.

Read only

matt
Active Contributor
0 Likes
1,249

You mean another basic programming problem?