Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Functions to convert unit.

Hi experts

do you know any function to convert KG to TON?

I find UNIT_CONVERSION_SIMPLE

but tis showed  message :Use a number field for the input value.

is correct?

I tried use the MATERIAL_CONVERT_QUANTITY but i don´t understand how input data in parameters .

somebody know about it.?

thanks

replied

Hi Ronaldo,

I tried below code and it is working for me. You need to change some data types.

DATA: lv_input TYPE /BCV/FND_QUANTITY,

       unit_in TYPE /BCV/FND_UNIT,

        unit_out TYPE /BCV/FND_TARGET_UNIT .

lv_input = 10.

unit_in = 'KG'.

unit_out = 'TON'.

CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

   EXPORTING

     input                      = lv_input

    NO_TYPE_CHECK              = 'X'

*   ROUND_SIGN                 = ' '

    UNIT_IN                    = unit_in

    UNIT_OUT                   = unit_out

  IMPORTING

*   ADD_CONST                  =

*   DECIMALS                   =

*   DENOMINATOR                =

*   NUMERATOR                  =

    OUTPUT                     = lv_input

  EXCEPTIONS

    CONVERSION_NOT_FOUND       = 1

    DIVISION_BY_ZERO           = 2

    INPUT_INVALID              = 3

    OUTPUT_INVALID             = 4

    OVERFLOW                   = 5

    TYPE_INVALID               = 6

    UNITS_MISSING              = 7

    UNIT_IN_NOT_FOUND          = 8

    UNIT_OUT_NOT_FOUND         = 9

    OTHERS                     = 10

           .

IF sy-subrc <> 0.

* Implement suitable error handling here

ELSE.

   write :/ lv_input.

ENDIF.


See output I converted 10 KG to TON.



Thanks-

Abhishek

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question