01-20-2023 6:41 AM
01-20-2023 6:49 AM
data(percentage) = cond #( when num2 ne 0
then ( num1 / num2 ) * 100
else 0 ).
01-20-2023 7:08 AM
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.
01-20-2023 7:19 AM
I should add a raise exception, but ... too early in the morning 😉
01-20-2023 8:06 AM
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?
01-24-2023 6:24 PM
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.