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: 

Incorrect KONV-KBETR calculation.

kethanuppalapati
Explorer
0 Kudos

Hello all,

I have to calculate the KBETR value and send it to an external system. The value is being calculated in two place, once in user exit and other in custom program.

DATA: l_discount_pct TYPE P LENGTH 9 DECIMALS 3,

              lt_komv type table of komv.

The code written in the user exit is:

lt_xkomv[] = xkomv[].

   LOOP AT lt_tab.

     READ TABLE lt_xkomv WITH KEY kschl = lt_tab-zfield.

     IF sy-subrc = 0.

         l_discount_pct = ( lt_xkomv-kbetr * -1 ).

       ENDIF.

       EXIT.

     ENDIF.

   ENDLOOP.

In the above code the value of lt_xkomv-kbetr is -150.00 and it is getting converted to 15.000 which is correct.

The code written in custom program is:

CALL FUNCTION 'RV_KONV_SELECT'

     EXPORTING

       comm_head_i  = ls_komk

       general_read = 'X'

     TABLES

       tkomv        = lt_komv.

LOOP AT lt_komv INTO ls_komv.

  l_discount_pct = ( ls_komv-kbetr * -1 ).

ENDLOOP.


In konv table the value is stored as 150.00 which is standard SAP Conversion.

In the above code the value of lt_xkomv-kbetr is -150.00 and it is getting converted to 150.00.The conversion did not take place like in user exit.

The issue is that kbetr value is calculated correctly in user exit and the same code is returning the different value in the custom program. Initially, I thought it may be a data type issue, However all the data types used in the both the places are same. Does SAP behave differently while converting values in user exits and custom program. Please provide your inputs on this.

Thank You!

Kethan.

1 ACCEPTED SOLUTION

christian102094
Participant
0 Kudos

I guess it is because the program property "Floating point Arithmetic" is activated in one, but not in the other.

3 REPLIES 3

christian102094
Participant
0 Kudos

I guess it is because the program property "Floating point Arithmetic" is activated in one, but not in the other.

thanga_prakash
Active Contributor
0 Kudos

Hello Kethan,

Christian is correct, it is because of the "Fixed Point Arithmetic" in the attributes of the program.

below is the SAP standard documentation for the field "Fixed point arithmetic"

------------------------------------------------------------------------------------------------------------------------------------------

If you mark this checkbox, all calculations in the program will use fixed point arithmetic.

If you do not, packed numbers (ABAP/4 type P, Dictionary types CURR, DEC or QUAN) will be treated as integers when they are used in assignments, comparisons, and calculations, irrespective of the number of decimal places defined. Intermediate results in arithmetic calculations will also be rounded to the next whole number. The number of decimal places defined is only taken into account when you output the answer using the WRITE statement.

------------------------------------------------------------------------------------------------------------------------------------------


Regards,

Thanga

former_member289261
Active Contributor
0 Kudos

Hi,

You need to divide it by 10 in custom code. SAP stores percentages multiplied by 10 to maintain the precision. While fetching it manually you need to undo that through code i.e divide by 10.