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: 

Functions to convert unit.

ronaldo_aparecido
Contributor
0 Kudos

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

1 ACCEPTED SOLUTION

AbhishekSharma
Active Contributor
0 Kudos

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

2 REPLIES 2

AbhishekSharma
Active Contributor
0 Kudos

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 Kudos

thanks.