2007 Jan 19 2:22 AM
hii frnds
i am havng a problem regarding calculating percentage .
actualy when i calculte it by
perc = total / total 1 .
perc = perc * 100 .
so in this case i am getting whole figures .
but the i want the esact figure as we get it when we divide it by calculator .
cal any body help me with this issue ..
thanx
rohit
hii frnds
i am havng a problem regarding calculating percentage .
actualy when i calculte it by
perc = total / total 1 .
perc = perc * 100 .
so in this case i am getting whole figures .
but the i want the esact figure as we get it when we divide it by calculator .
cal any body help me with this issue ..
thanx
rohit
2007 Jan 19 2:30 AM
Can you give details of the data types you are using for the variables???
Regards
Eswar
2007 Jan 19 2:39 AM
i am using data type c for all the variables . should i use any other data type
2007 Jan 19 2:43 AM
You cannot use char data types to do numeric calculations... Instead use P (Packed) I (Integer) or F (Float) data types...
Refer below link for abap data types and then proceed..
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fcc358411d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb2fd9358411d1829f0000e829fbfe/content.htm
Thanks,
Santosh
2007 Jan 19 5:26 AM
Use the following notation in declaring the Variable for percentage.
DATA percentage TYPE P DECIMALS d.
Here d is an integer that specifies number of decimals after the period.
Effect
d specifies the number of decimal places for a number field (type I, P or F) in d. If this value is smaller than the number of decimal places in the number, the number is rounded. If the value is greater, the number is padded with zeros.
Since accuracy with floating point arithmetic is up to about 15 decimal places (see ABAP number types), up to 17 digits are output with floating point numbers (type F). (In some circumstances, 17 digits are needed to differentiate between two neighboring floating point numbers.) If the output length is not sufficient, as many decimal places as possible are output. Negative DECIMALS specifications are treated as DECIMALS 0.
Example:
DATA: i TYPE I,
j TYPE I,
perc TYPE P DECIMALS 2.
f TYPE F.
i = 123.
j = 246.
perc = i / j * 100.
f = i / j * 100.
WRITE: / 'Percentage = ', perc, 'F = ', f.
Fix as many decimals as your requirement....
PS: Please Award Points If I guided you in right direction
2007 Jan 19 3:46 AM
Hi Rohit ,
It all depends on the data type you are using , whether it supports decimals or not , so what i woluld suggest is use the varaible of type p with 2 or more decimal places to store your precentage value.
and e.g. is
Data : v_1 type p decimals 5. " So you can have 5 decimal places
v_1 = 13 / 3.
write v_1.Regards
Arun
2007 Jan 19 4:42 AM
HERE IN THE BELOW CODE I AM GETTING ACTUAL RESULT
DATA : TOT(5) TYPE C VALUE '13.00',
TOT1(5) TYPE C VALUE '3.00',
RES(5) TYPE C.
RES = TOT1 / TOT.
RES = RES * 100.
WRITE : / RES.
BUT IT IS NOT WORKING FOR YOU JUST CHECK IN ATTRIBUTES WHETHER FIXED POINT ARITHMETIC OPTION IS TICKED OR NOT.
OTHER WISE YOU CAN USE TYPE P VARIABLE.
REGARDS
SHIBA DUTTA
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |