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

Decimal Calculation Problem

Former Member
0 Likes
4,601

Hi All,

I am a newbie of ABAP programming. I have create a new routine for condition value by VOFM.

FORM FRM_KONDI_WERT_908.

*{   INSERT     

   DATA: p_value(7)   TYPE p DECIMALS 4.

   p_value = komp-brtwr * konp-kbetr / 10000.

   xkomv-kbetr = konp-kbetr / 10.

   xkwert = p_value.


*}   INSERT

ENDFORM.


It is very strange that if p_value = 1.2340, xkwert will equal to 123.40 but not 1.23. It seems like the number format is right-justified.


Please kindly help on this issue....I have hold on this for a few days...Thanks~~!!

1 ACCEPTED SOLUTION
Read only

Juwin
Active Contributor
0 Likes
2,554

This is because "Fixed point arithmetic" checkbox is not checked for the main program SAPLV61A.

For this reason, it is always better to declare your own function group, and function module inside it, with the required calculation and just call the function module from the routine. Don't do calculations directly inside the routine.

Thanks,

Juwin

7 REPLIES 7
Read only

Former Member
0 Likes
2,554

hello Chan,

what kind of data type you have declared for variable xkwert ?

Read only

0 Likes
2,554

Hello Sujatha,

xkwert is type kwert (P(7) DECIMALS 2), thanks~~

Read only

0 Likes
2,554

Hi Chan,

what value you are getting at the run time in xkwert ?

as per the data declaration by you , the result of xkwert shouldbe 1.23 itself.

Regards,

Sujatha Arsid.

Read only

Former Member
0 Likes
2,554

Hi,

Change declaration p_value and check

   DATA: p_value(7)   TYPE p DECIMALS 2.


Thanks and Regards,

Chandra

Read only

Juwin
Active Contributor
0 Likes
2,555

This is because "Fixed point arithmetic" checkbox is not checked for the main program SAPLV61A.

For this reason, it is always better to declare your own function group, and function module inside it, with the required calculation and just call the function module from the routine. Don't do calculations directly inside the routine.

Thanks,

Juwin

Read only

Former Member
0 Likes
2,554

Hi Ka Wai Chan,

I second Juwin.. He is right. SAPLV61A does not hv Fixed Point Arithmetic checked. Create a FM with Fixed Point Arithmetic checked (Attribute menu)

Take a look of a example of FM with Fixed Point Arithmetic checked and unchecked.

1. Both Program and FM with Fixed Point Arithmetic UNCHECKED.

Expect output is 1.235, but 12.35 is wrongly displayed.

2. Program with Fixed Point Arithmetic UNCHECKED and FM with Fixed Point Arithmetic CHECKED (exact your scenario). Output is 1.24


More explanation at: Do all ABAPers know Fixed Point Arithmetic? | SAP Yard

Regards,

Raju

Read only

Former Member
0 Likes
2,554

Dear All,

     Problem fixed, it is caused by Fixed Point Arithmetic~~~~

     I created a function then it works normally.

     thank you very much~~~!!

God Bless,

Dan