Application Development 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: 

how do you find the percentage in sap abap?

aravindcsebe
Explorer
0 Kudos

i have num1 and num2 i want to find percentage in sap abap.

5 REPLIES 5

FredericGirod
Active Contributor
data(percentage) = cond #( when num2 ne 0 
then ( num1 / num2 ) * 100
else 0 ).

DominikTylczyn
Active Contributor

Primary school mathematics. Returning 0 when num2 = 0 could be discussed. Mathematically percentage is not 0 then. It is undefined, it approaches infinity when num2 approaches 0. I guess for practical purposes 0 or 100 will do.

FredericGirod
Active Contributor

I should add a raise exception, but ... too early in the morning 😉

Sandra_Rossi
Active Contributor

Not ABAP, mathematics. You are not clear in your question: do you want to know how much num1 represents in num2, or vice versa? A number between 0 and 100? With any number of decimals?

Berinath
Participant
0 Kudos

Hi aravindcsebe,

PARAMETERS: num1(6) type n,
num2(6) type n.
data:
val(3) type n,
val2(3) TYPE n.
val = ( ( num1 ) / ( num1 + num2 ) ) * 100.
val2 = 100 - val.
write:/ val, val2.

this is the report for find percentage of two numbers.

I hope you understand,

If it helps, please accept this answer.

Regards,

Berinath Ulisi.