Skip to Content
author's profile photo
Former Member

FM for Units Conversion

Hi

I am searching for a FM that converts a number from one Unit to another, say from Ton to KG, G to KG, KG to LT etc. It should be generic. Any Help ?

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

4 Answers

  • Best Answer
    author's profile photo
    Former Member
    Oct 03, 2005 at 04:54 AM

    Hi!

    Use FM UNIT_CONVERSION_SIMPLE.

    Regards,

    Maxim.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 03, 2005 at 05:03 AM

    Hi

    I used this FM. I gave input 1000.UNIT_IN as KG

    UNIT_OUT as TO. It didnt give the output at all as 1 TO.

    Please let me know.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 03, 2005 at 05:47 AM

    this code help u to understand the logic of this fm....

    &----


    *

    *& Form z_unit_conversion_kg

    &----


    • This form is used to convert weight unit in 'LB'

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM z_unit_conversion_lb.

    i_ln_items-brgew_kg = i_ln_items-brgew.

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

    EXPORTING

    input = i_ln_items-brgew

    unit_in = c_kg

    unit_out = c_lb

    IMPORTING

    output = i_ln_items-brgew_lb.

    MODIFY i_ln_items TRANSPORTING brgew_kg brgew_lb.

    ENDFORM. " z_unit_conversion_lb

    &----


    *& Form z_unit_conversion_lb

    &----


    • This form is used to convert weight unit in 'KG'

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM z_unit_conversion_kg.

    i_ln_items-brgew_lb = i_ln_items-brgew.

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

    EXPORTING

    input = i_ln_items-brgew

    unit_in = c_lb

    unit_out = c_kg

    IMPORTING

    output = i_ln_items-brgew_kg.

    MODIFY i_ln_items TRANSPORTING brgew_lb brgew_kg.

    ENDFORM. " z_unit_conversion_kg

    &----


    *& Form z_unit_conversion_kg_lb

    &----


    • This form is used to convert weight unit in 'KG' and 'LB'

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM z_unit_conversion_kg_lb.

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

    EXPORTING

    input = i_ln_items-brgew

    unit_in = i_ln_items-gewei

    unit_out = c_kg

    IMPORTING

    output = i_ln_items-brgew_kg.

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

    EXPORTING

    input = i_ln_items-brgew_kg

    unit_in = c_kg

    unit_out = c_lb

    IMPORTING

    output = i_ln_items-brgew_lb.

    MODIFY i_ln_items TRANSPORTING brgew_kg brgew_lb.

    ENDFORM. " z_unit_conversion_kg_lb

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 03, 2005 at 06:25 AM

    Sample program.

    &----


    *& Report ZVTN_CONVERT *

    *& *

    &----


    *& *

    *& *

    &----


    REPORT ZVTN_CONVERT.

    data : inputval type i,

    outval type i.

    inputval = 69.

    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'

    EXPORTING

    INPUT = inputval

    NO_TYPE_CHECK = 'X'

    • ROUND_SIGN = ' '

    UNIT_IN = 'KG'

    UNIT_OUT = 'LB'

    IMPORTING

    • ADD_CONST =

    • DECIMALS =

    • DENOMINATOR =

    • NUMERATOR =

    OUTPUT = outval

    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.

    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    write outval.

    Add comment
    10|10000 characters needed characters exceeded