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

Wrong arithmetic calculations

ged_hurst
Participant
0 Likes
592

HI all,

I've got this piece of coding:


DATA ls_static_attributes TYPE ztype.
DATA lv_amount TYPE BPREI.

ls_static_attributes-netpr = '123'.
ls_static_attributes-menge = '1'.
ls_static_attributes-bpumn = '1'.
 lv_amount =   ls_static_attributes-netpr * ls_static_attributes-menge .

well the value of lv_amount is different when the code above is inserted in a report rather than in a method of a class.

In particular, in a report it correctly contains '123,00' whilst in a class I'm getting '123.000,00'.

I tried to debug and I've seen that after the assignment:


ls_static_attributes-menge = '1'.

the variable ls_static_attributes-menge contains (1.000) in a report whilst in a class it contains (0.001).

Could anybody shed more light on this?

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
530

Hi,

I think this is due to a different "fixed-point arithmetic" program attribute. It is set by default, which means decimals of packed fields are taken into account. When unchecked, system considers every packed field as an integer (except when it is output). More info: [SAP Library: ABAP - business calculations|http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb333d358411d1829f0000e829fbfe/frameset.htm]

BR

Sandra

4 REPLIES 4
Read only

Sandra_Rossi
Active Contributor
0 Likes
531

Hi,

I think this is due to a different "fixed-point arithmetic" program attribute. It is set by default, which means decimals of packed fields are taken into account. When unchecked, system considers every packed field as an integer (except when it is output). More info: [SAP Library: ABAP - business calculations|http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb333d358411d1829f0000e829fbfe/frameset.htm]

BR

Sandra

Read only

Clemenss
Active Contributor
0 Likes
530

Hi Themis,

probably the ztype has amount or qauntity field which are by default connected to a currency key or unit field. Check the respective currency key or unit fields.

I don't think the code behaves different in class an report context, check also Sandra's suggestion about fixed-point arithmetic flag - actually I don't know any reason to change that default.

Regards,

Clemens

Read only

0 Likes
530

Hi Clemens,

probably the ztype has amount or qauntity field which are by default connected to a currency key or unit field. Check the respective currency key or unit fields.

quantities and units are only used for output, not for internal calculations, it's why I think the fixed-point arithmetic is the only possibility. Usually people don't change it but some standard programs are provided without this option checked, developers are usually getting screwed when they implement the "userexit" subroutines of these programs.

Sandra

Read only

0 Likes
530

Thank you Sandra,

I've given you full points, you've solved my problem.

Regards