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

false calculation result

Former Member
0 Likes
1,157

Hello expert,

                   I make an enhancement in PO when i make some calculation the result get zero as the example below

SELECT SINGLE NETWR

   FROM ESSR

   INTO EKKO_VAL

   WHERE EBELN = WA-EBELN

     AND EBELP = WA-EBELP.

   SELECT SINGLE BRTWR

   FROM EKPO

   INTO EKPO_VAL

   WHERE EBELN = WA-EBELN

     AND EBELP = WA-EBELP.

EKKO_VAL = 15000,00


EKPO_VAL = 50000,00

BALANCE = EKKO_VAL / EKPO_VAL .

BALANCE must be 0.03 but it is coming zero ,any body can help ,thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,126

Hi Ahmed,

Please mention the type declaration used for EKKO_VAL , EKPO_VAL and BALANCE in the program.

8 REPLIES 8
Read only

Former Member
0 Likes
1,127

Hi Ahmed,

Please mention the type declaration used for EKKO_VAL , EKPO_VAL and BALANCE in the program.

Read only

0 Likes
1,126

the type of this three variables is  P DECIMALS 2

Read only

0 Likes
1,126

If the enhancement belongs to a program with the flag "fixed point arithmetic" switched off, you will get 0. If it is switched on, you will get 0.30.

In older ABAP programs, find the "fixed point arithmetic" flag switched off. In more recent programs, and when creating new programs, the flag will be switched on by default.

If "fixed point arithmetic" is switched off, all decimal points will be ignored, and all intermediate results will be rounded to integers.


data: x type p length 7 decimals 2,

         y type p length 7 decimals 2,

         z type p length 7 decimals 2.

   x = '15000.00'.

   y = '50000.00'.

   z = x / y.

write z. " --> 0.30 with fixed point arithmetic, 0.00 without fixed point arithmetic

Regards,

Rüdiger

Read only

0 Likes
1,126

Thanks rudiger for your replay,

but it is include program where can I find the flag of  'fixed point arithmetic' because the result still coming zero

Read only

0 Likes
1,126

Hi Ahmed, an include program is included in a main program. It is the flag of the main program that counts.

But for old SAP programs, you'll mess them up by changing that flag, so changing the flag to 'X' would be no solution. If you're in an exit, you have two options:

  • Extract the logic from the exit into an own function module or class method, and call that function module or class method from within the exit. In your own program, leave the "fixed point arithmetic = 'X'"
  • OR (not-so-good option): Compute by multiplying with the correct power of ten. So in your case, if numerator and denominator both have 2 decimals, multiply by 100 before doing the division.

Regards,

Rüdiger

Read only

0 Likes
1,126

thanks guru I change the "fixed point arthimetic" in the main program and now it is working correctly.

Read only

0 Likes
1,126

That's what I said you better NOT do! 🙂 As I said in my last reply, in old programs you will mess up all the other (old) computations of the standard when changing their fixed point arithmetic flag!!!

Read only

0 Likes
1,126

yes yes i just test it but i create new function and assigned it to the include program and working.