Application Development and Automation 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: 
Read only

FM for Units Conversion

Former Member
0 Likes
6,072

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 ?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,774

Hi!

Use FM UNIT_CONVERSION_SIMPLE.

Regards,

Maxim.

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 ?

4 REPLIES 4
Read only

Former Member
0 Likes
3,775

Hi!

Use FM UNIT_CONVERSION_SIMPLE.

Regards,

Maxim.

Read only

Former Member
0 Likes
3,774

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.

Read only

Former Member
0 Likes
3,774

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

Read only

Former Member
0 Likes
3,774

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.