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

Issues with Decimals

Former Member
0 Likes
1,564

I have an issue with decimals in calculation : -

Data : G_SUM TYPE p DECIMALS 2.

   KOMV-KBETR = 2.00  (KBETR TYPE IS P(6) Decimal 2)
   
   WG_A650-ZZBILL_QUNT = 10.00 (ZZBILL_QUNT Type is P(7) Decimal 3)


        Loop at I_A650 into WG_A650.
             G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ).
        Endloop.


           XKWERT = G_SUM. (XKWERT Type is P(7) Decimal 2)

 Form the above calculation : - G_SUM should be 20.00
         But the result is : -  20000.00
 
To aviod this i changed the declartion of G_SUM as below : - 

Data : G_SUM TYPE p DECIMALS 5.

 Now it is calculating correctly but i need to assign this value to a another field. 
      Its data type is (TYPE p DECIMALS 2)

Now the result is again changed to 20000.00

Any sugesstion to fix this issue will be apprecaiated.

Regards,

Kittu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,412

Hi,

You cant declare like this.

KBETR TYPE IS P(6) Decimal 2.

How did you declared?

Thanks.

10 REPLIES 10
Read only

Former Member
0 Likes
1,412

erm no, please read your code again. You assign 10 to your workarea field, and THEN you do a loop of a internal table into workarea.

So what you have done in is not existant anymore.

1. your desired value would be 200 and not 20, if your "set"-coding would have any effect.

2. we dont know what is in your internal table, so we dont knwo how often this line (G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ).) will get processed.

as well as we dont know the value of WG_A650-ZZBILL_QUNT.

so with this information we cant tell too much.

Read only

0 Likes
1,412

Hi Florian Kemmer,

Thank you for your quick response!

It is my mistake, i could have explained in more efficient manner.

The below values are from Internal table only and it has only 1 record.

KOMV-KBETR = 2.00

WG_A650-ZZBILL_QUNT = 10.00

(G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ).)

After the above formula is executed it shoudl display the value as 20.00

Due to issues with the decimals it is displaying as 20000.00

And the declaration is not exactly done as described...It is just for understanding.

KBETR --> is of type P(6) Decimal 2.

Any suggestion will be appreciated

Regards,

Kittu

Edited by: Kittu on Mar 29, 2010 12:34 PM

Read only

0 Likes
1,412

ah ok i see what is happening here, tho yeah i also would really like to understand it.

sorry i cant help you too much, this is once again a case where i hate it to calculate with SAP. human logic cant really follow this, at least not an intuitive one.

declaring your field with 5 decimals solves it, and i probably would have to something like

(G_SUM = G_SUM + ( KOMV-KBETR * WG_A650-ZZBILL_QUNT /1000), which would get us to the same.

but yeah your question is still unanswered sorry.

Read only

0 Likes
1,412

Kittu,

I tested with a piece of code and its working fine.

please check the below code and the result is 20.00.

data : KBETR TYPE P LENGTH 6 Decimals 2 value '2.00',
       ZZBILL_QUNT Type P LENGTH 7 Decimals 3 value '10.00'.

Data : G_SUM TYPE p DECIMALS 2." VALUE '20'.

G_SUM = G_SUM + ( KBETR * ZZBILL_QUNT ).

write : g_sum.

Check your inputs.

Thanks.

Read only

0 Likes
1,412

This is because you don't have fixed point arithmethic turned on.

Go to programs attributes-> check fixed point arith . You will get 20.00.

Regards

Marcin

Read only

0 Likes
1,412

Kittu,

Yes. Marcin Got the issue.

Its bcoz of Fixed point arithmetic.

Thanks.

Read only

0 Likes
1,412

Check whether fixed point arithmatic check is checked or not in the program attibutes. If not checked, check it and test it.

Read only

0 Likes
1,412

great now i get it. OMG that simple. Thanks a LOT.

BTW if you cannot turn on fixed poiint arithmetic for this program, you could make a new FM turn it on there and do your calculations in your new FM then.

Read only

Former Member
0 Likes
1,413

Hi,

You cant declare like this.

KBETR TYPE IS P(6) Decimal 2.

How did you declared?

Thanks.

Read only

Former Member
0 Likes
1,412

Hi Florian Kemmer,

Thank you all for your response!

The issue is fixed.

Loop at I_A650 into WG_A650.

XKWERT = XKWERT + ( ( KOMV-KBETR * WG_A650-ZZBILL_QUNT ) / 1000 )." 2 dec X 3 dec

" - This logic is written to adjust the decimals

Endloop.

/1000...did the magic .

Regards,

Kittu

Edited by: Kittu on Mar 29, 2010 3:27 PM