Application Development 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: 

SAP - bad math student...

Juwin
Active Contributor
0 Kudos

Write this simple program and execute it:


report  zreport no standard page heading.
data: l type f, k type f, j type f.
l = 252 / 864.
write / l.

k = ( 864 - 252 ) / 864.
write / k.

j = l + k.
write / j.

j = k - l.
write / j.

The report output in our system says:


 2.9166666666666669E-01
 7.0833333333333337E-01
 1.0000000000000000E+00
 4.1666666666666669E-01

I used http://keisan.casio.com/has10/Free.cgi, to check the results:

252 / 864 = 0.2916666666666666666667 and not 2.9166666666666669E-01 as calculated by SAP

( 864 - 252 ) / 864 = 0.7083333333333333333333 and not 7.0833333333333337E-01 as calculated by SAP

7.0833333333333337E-01 + 2.9166666666666669E-01 = 1.00000000000000006 and not 1 as calculated by SAP (even though 252 / 864 + ( 864 - 252 ) / 864 is 1).

7.0833333333333337E-01 - 2.9166666666666669E-01 = 0.41666666666666668 and not 4.1666666666666669E-01 as calculated by SAP

Why is this happening? Evenif SAP is not capable of going beyond a particular digit, it should have atleast rounded off the numbers correctly.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos

Hi,

Computers store floating point numbers using base 2 so the rounding may appear bizarre when converted to decimal base.

And ABAP uses floating point numbers with 52 bits for mantissa, it's why it does have only about 16 significant digits (roughly 252 ~= 1016)

In 7.1, SAP has introduced decimal floating point numbers (stored in base 10) with a precision of 34 digits (decfloat34).

SAP softwares (traditionally accounting and so on) usually don't need so high precision.

Sandra

Edited by: Sandra Rossi, 3 minutes later:

reference: http://help.sap.com/abapdocu_702/en/index.htm?url=abennumber_types.htm

8 REPLIES 8

Former Member
0 Kudos

Hi Juwin,

First know the capabilities of SAP Before posting.

And Search SDN forum before posting, there are "N" number of posts like that of yours.

Anyways why don't you use TYPE p with DECIMALS?.

BR

Dep

Juwin
Active Contributor
0 Kudos

As you can see, the forum search didn't get me any posts related to Float calculation error: http://imageshack.us/f/854/capturekao.jpg/

I wish I had the capability to change the field type to P. The error is happening in standard program, which is used for capacity availability check, and it took us days to figure out this calculation error was causing all the problems.

We had to finally change the data, to avoid this calculation error.

I didn't know SAP was not "capable" of correctly "rounding-off" a calculation. I thought that should be a minimum "capability" of any system used to do calculations. My fault.... If it is not much of a trouble, can you post a link to any such documentation, explaining the capabilities?

Would it be incorrect for me to say that, it is statements like "its been posted a million times, why don't you go an check first", that prevent people from posting questions? If 10 people ask same questions that you know answer for, and you reply to all of them, all of them are happy and awards you points, aren't you the one who is benefitting out of it?

0 Kudos

If the problem is in a standard SAP program and SAP arithmetic is not behaving as you expect, then why didn't you raise an OSS message rather than posting in the forum?

Rob

Juwin
Active Contributor
0 Kudos

@Rob: Since changing the data, solved the problem, we didn't want to engage SAP. But, personally I wanted to know why this is happening, hence this question.

Thanks,

Juwin.

0 Kudos

Hi Juwin,

First things first,

You never said that you faced the issue in STANDARD PROGRAM.

You cannot go by assuming "minimum capabilities" of ANY SYSTEM.

Refer to link [http://help.sap.com/saphelp_47x200/helpdata/EN/fc/eb33f3358411d1829f0000e829fbfe/frameset.htm] for documentation & capabilities.

BR

Dep

Edited by: DeepakNandikanti on Aug 16, 2011 8:19 PM

matt
Active Contributor
0 Kudos

@Rob: Since changing the data, solved the problem, we didn't want to engage SAP. But, personally I wanted to know why this is happening, hence this question.

>

> Thanks,

> Juwin.

Still you shoud raise it. Years ago, on 31H, there was a bug I found with conversion of units. The standard function module used 5 decimal places, which wasn't sufficient for the conversion factors we'd set up. I informed SAP how to fix it - they fixed it. Everyone benefits... that fix is probably still in your system.

matt
Active Contributor
0 Kudos

> Would it be incorrect for me to say that, it is statements like "its been posted a million times, why don't you go an check first", that prevent people from posting questions? If 10 people ask same questions that you know answer for, and you reply to all of them, all of them are happy and awards you points, aren't you the one who is benefitting out of it?

Yes, it would be incorrect, because it is against the rules.

Asking Frequently Asked Questions is banned on most internet forums, as you end up with 90% of the forum database being the same set of questions. The Rules of Engagement of this forum are quite clear - search first, post second. And if your question is found to be a FAQ, then it risks deletion/rejection or moving to the Beginners' Corner.

Sandra_Rossi
Active Contributor
0 Kudos

Hi,

Computers store floating point numbers using base 2 so the rounding may appear bizarre when converted to decimal base.

And ABAP uses floating point numbers with 52 bits for mantissa, it's why it does have only about 16 significant digits (roughly 252 ~= 1016)

In 7.1, SAP has introduced decimal floating point numbers (stored in base 10) with a precision of 34 digits (decfloat34).

SAP softwares (traditionally accounting and so on) usually don't need so high precision.

Sandra

Edited by: Sandra Rossi, 3 minutes later:

reference: http://help.sap.com/abapdocu_702/en/index.htm?url=abennumber_types.htm