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

Unit conversion

former_member582701
Contributor
0 Likes
1,446

Hi people,

I am using a standard function to convert units in a Stock control report.

I have had two problems.

First, value old import is a quantum of (9,3) and export was a quantum of (15,3) (VEPO-VEMNG). I have had to convert vemng into a quantum (9,3).

DATA: l_vemng LIKE PLFH-MGVGW,

v_vemng LIKE PLFH-MGVGW.

IF p_i_almacenmm_vemeh <> 'ZCJ'.

l_vemng = p_i_almacenmm_vemng.

CALL FUNCTION 'CF_UT_UNIT_CONVERSION'

EXPORTING

  • MATNR_IMP = ' '

  • MEINS_IMP = ' '

unit_new_imp = 'ZCJ'

unit_old_imp = p_i_almacenmm_vemeh

value_old_imp = l_vemng

IMPORTING

VALUE_NEW_EXP = v_vemng

EXCEPTIONS

OVERFLOW = 1.

ENDIF.

p_v_unid_cuar = TRUNC( v_vemng ).

The second and the unresolved problem is that the return parameter v_vemng is always 0. I have tried with unit type ZTQ to ZCJ.

Do you have any idea?

Thx in advance

Manel

5 REPLIES 5
Read only

Former Member
0 Likes
1,019

There are Several Function Module...

Check out there functionality as per your requirement...

· CONVERSION_FACTOR_GET

With this function module, you determine the conversion factors for the conversion of a measurement unit into another using the measurement units table. This does not apply to measurement units within a dimension.

The module also returns the number of decimal places to which the values in the unit UNIT_OUT are to be rounded. This also applies to units with no dimension.

The following formula applies for the conversion:

(value in the unit UNIT_OUT) = (value in the unit UNIT_IN) * numerator/denominator + additive constant.

· ROUND

With this function module, you round a value to the specified number of decimal places. You can choose between three rounding types:

- Rounding up

- Rounding down

- Commercial rounding

The rounding is performed internally with the same field type as that of the field passed.

Rounding errors can thus occur when rounding a FLOAT value. If you want a high degree of accuracy, the passed field should have the type P.

· SI_UNIT_GET

You pass either a unit or a dimension to this function module to get the SI unit. If you pass both a unit and a dimension, the SI unit for the dimension is returned.

· UNIT_CONVERSION_WITH_FACTOR

With this function module, you convert a value according to the factor passed.

· UNIT_CORRESPONDENCE_CHECK

With this function module, you can check whether the two units passed belong to the same dimension.

· UNIT_GET

With this function module, you get the appropriate measurement unit for the specified dimension and conversion factor.

· UNIT_CONVERSION_SIMPLE

With this function module, you convert a value using the measurement unit table, and round it, if appropriate.

You can also perform the rounding without conversion.

Conversion with this function module requires that the measurement unit table is maintained for both units, and that both units belong to the same dimension, i.e. also that they have dimensions.

The rounding can, however, also be performed for units which have no dimension.

CONVERT_TO_LOCAL_CURRENCY - Conversion of currency

HRCM_AMOUNT_TO_STRING_CONVERT - Convert amount to string

HRCM_STRING_TO_AMOUNT_CONVERT - Convert amount from string

CLOI_PUT_SIGN_IN_FRONT Move the negative sign from the left hand side of a number, to the right hand side of the number. Note that The result will be left justified (like all

character fields), not right justifed as numbers normally are.

CONVERT_TO_FOREIGN_CURRENCY Convert local currency to foreign currency.

CONVERT_TO_LOCAL_CURRENCY Convert from foreign currency to local currency

Do Reward Points to replies if found useful...

Regards,

Vasanth

Read only

Former Member
0 Likes
1,019

I see that the material MATNR and material base UOM MEINS fields are not input in the function interface. If the units that you want to convert are UOMs for the material then you need to pass them too for conversion between the alternate UOMs.

Read only

former_member194669
Active Contributor
0 Likes
1,019

Hi,

Try to use fm

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

I think you need to pass material number and alternative UOM

aRs

Read only

former_member582701
Contributor
0 Likes
1,019

I am testing thins last function but output are always same that input.

CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'

EXPORTING

INPUT = l_aux_p_verme

  • KZMEINH = ' '

matnr = p_i_almacenwm_matnr

meinh = 'ZCJ'

MEINS = p_i_almacenwm_meins

  • EXTENDED_CONV = ' '

  • TYPE_UMR = ' '

  • NO_OUTPUT = ' '

  • CHARGE =

  • CHARG_CUOBJ =

  • WERKS =

IMPORTING

  • ADDKO =

  • MEINS =

OUTPUT = l_verme

  • UMREN =

  • UMREZ =

  • BATCH_CONVERSION_ERROR =

  • KZWSO =

Do you see something? Otherwise is better this function because input and output are frees and i have not to do the conversion of verme to long 15 to 9.

But why output is the same that input? p_i_almacenwm_meins is 'ZTQ'.

Thx

Read only

former_member194669
Active Contributor
0 Likes
1,019

Hi,

This function module converts a quantity from one unit of measurement to another. A requirement for this is that the units of measurement relate to a material. One of them must be the base unit of measure of the material, while the other must be defined as an alternative unit of measure for the material or be capable of being converted to an alternative unit of measure as per table T006.

You are recommended declaring the transfer parameters for the quantities and the conversion factors as type F fields since the runtime required for conversion is substantially less than with type P or type I fields and also because the exception OVERFLOW cannot then occur.

If the transfer parameters for the conversion factors are of type P (packed number), the system assumes that you require conversion with 5-digit accuracy. If they are of type I (integer), the system assumes that you require conversion with 10-digit accuracy. (See also the documentation on transfer parameter TYPE_UMR.)

aRs