Skip to Content

Incorrect KONV-KBETR calculation.

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Oct 26, 2015 at 08:12 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 27, 2015 at 06:48 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 27, 2015 at 07:34 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded