2009 May 04 9:59 AM
Hi,
I have a problem in dividing the values, say example i want to divid n by n1.
n = 1339.80
n1 =1914
n2 = n/n1
but i am getting the output value as 1 and i tried the DIVIDE statement as well, but still i am facing the same proble.
Please help to solve this problem
or
Let me know the FM to calculate the percentage value.
Regards,
Vijay
Hi,
I have a problem in dividing the values, say example i want to divid n by n1.
n = 1339.80
n1 =1914
n2 = n/n1
but i am getting the output value as 1 and i tried the DIVIDE statement as well, but still i am facing the same proble.
Please help to solve this problem
or
Let me know the FM to calculate the percentage value.
Regards,
Vijay
2009 May 04 10:03 AM
try declaring all the three variables as type P (Packed decimals) and perform the division.
2009 May 04 10:09 AM
the problem may be that the variable n2 is int type.
if you want an answer in decimal format then just make this variable of type p(packed decimal) and i you want an integer output then in sap 5/10 is 1 not 0.
use ceil or other similar commands.
2009 May 04 10:44 AM
Hi,
I try using the one you suggested as well and all other ways. but i am not getting the solution.
Is there any FM to calculate the percentage.
Regards,
Vijay
2009 May 04 10:48 AM
Try this.
Data: n type p decimals 5,
n1 type p decimals 5,
n2 type p decimals 5.
n = '1339.80'.
n1 = 1914.
n2 = n / n1.
write: n2.
2009 May 04 10:54 AM
It gives percentage value
data: n1 type p decimals 2,
n2 type p decimals 2,
n3 type p decimals 2.
n1 = '1339.80'.
n2 = 1914.
n3 = n1 / n2 * 100.
write:/ n3.And what's the error your getting.
thanks\
Mahesh
2009 May 04 10:05 AM
2009 May 04 10:05 AM
2009 May 04 10:05 AM
2009 May 04 10:06 AM
Check this:
data: n1 type p decimals 2,
n2 type p decimals 2,
n3 type p decimals 2.
n1 = '1339.80'.
n2 = '1914.00'.
n3 = n1 / n2.
write:/ n3.thanks\
Mahesh
2009 May 04 10:07 AM
hi,
Declare it of type p and after division you can store in the data type of your choice.
2009 May 04 10:21 AM
Hi,
Please check the following code, it is working fine.
PARAMETERS:n type p decimals 2 DEFAULT '1339.80',
n1 type p decimals 2 default '1914',
n2 TYPE p DECIMALS 2 .
n2 = n / n1.
WRITE n2.
2009 May 04 11:46 AM
Hi all,
When i try hard code the value with the solution given is working. but the problem in my case is
DATA: n TYPE p DECIMALS 2,
n1 TYPE p DECIMALS 2,
n2 TYPE p DECIMALS 2,
n3(10) type c value '1339.80',
n4(15) type numc valu '1914'.
Note for n3 and n4 is hardcode for examplet, but in real time , the value will be passed from the field directly.
n = n3 .
n1 = n4.
n2 = n/ n1.
write n2.
Please check and let me know the solution for this case.
Regards,
Vijay
2009 May 04 11:54 AM
Hi,
I have tested the code and it is giving the output as 0.70.(i.e. N2 hold 0.70 value)
2009 May 04 1:48 PM
Hi,
Yes its coming correct if you pass the value without decimal for n4 and the field type CURR.Please find the logic below
DATA: n TYPE p DECIMALS 2,
n1 TYPE p DECIMALS 2,
n2 TYPE p DECIMALS 2,
n3(10) type c value '1339.80',
n4 type netwr value '1914.50'.
Note for n3 and n4 is hardcode for examplet, but in real time , the value will be passed from the field directly.
n = n3 .
n1 = n4.
n2 = n/ n1.
write n2.
Kindly check and help me out to solve this.
Regards,
vijay
2009 May 07 7:41 AM
Hi all,
Here is the solution
data: n1 type p decimals 2,
n2 type p decimals 2,
n3 type p decimals 2.
n1 = '1339.80'.
n2 = '1914.50'.
n2 = n2 * 10.
n2 = n2 /1000.
n3 = n1 / n2.
write:/ n3.
then it will work correct in the case of the field has different type like CURR,CHAR,INTE,etc.
Any way thanks a lot for all.
Vijay
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |