[ABAP Function] Function Module Examples Code - Unit Conversion

Objective

Knowledge using SAP Standard Function Module for unit material

Support

Contributor

Albertus Reinandang ( reinandang@yahoo.com )

1.UNIT_CONVERSION_SIMPLE : Convert the quantity without knowing the material

Example :

REPORT ztest_fm201 NO STANDARD PAGE HEADING LINE-SIZE 1023.

PARAMETERS : pa_new LIKE t006-msehi OBLIGATORY,
pa_old LIKE t006-msehi OBLIGATORY,
pa_value LIKE plfh-mgvgw DEFAULT 10 OBLIGATORY.

START-OF-SELECTION.

DATA : lv_value_new LIKE plfh-mgvgw.
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
input = pa_value
round_sign = 'X'
unit_in = pa_old
unit_out = pa_new
IMPORTING
output = lv_value_new.

WRITE : / lv_value_new.

2.CF_UT_UNIT_CONVERSION : Convert the quantity of a material.

Example :

REPORT ztest_fm20 NO STANDARD PAGE HEADING LINE-SIZE 1023.

PARAMETERS : pa_matnr LIKE mara-matnr OBLIGATORY,

pa_meins LIKE mara-meins,
pa_new LIKE t006-msehi OBLIGATORY,
pa_old LIKE t006-msehi OBLIGATORY,
pa_value LIKE plfh-mgvgw DEFAULT 10 OBLIGATORY.

START-OF-SELECTION.

DATA : lv_value_new LIKE plfh-mgvgw.

CALL FUNCTION 'CF_UT_UNIT_CONVERSION'
EXPORTING
matnr_imp = pa_matnr

meins_imp = pa_meins
unit_new_imp = pa_new
unit_old_imp = pa_old
value_old_imp = pa_value
IMPORTING
value_new_exp = lv_value_new
.

WRITE : / lv_value_new.

3.MATERIAL_UNIT_CONVERSION : Convert the quantity of a material with a two-step process and support for the quantity in a very large number.

Example :
REPORT ztest_fm203 NO STANDARD PAGE HEADING LINE-SIZE 1023.

PARAMETERS : pa_matnr LIKE mara-matnr OBLIGATORY,
pa_meins LIKE mara-meins OBLIGATORY,
pa_new LIKE t006-msehi OBLIGATORY,
pa_old LIKE t006-msehi OBLIGATORY,
pa_value LIKE plfh-mgvgw DEFAULT 10 OBLIGATORY.

START-OF-SELECTION.

DATA : lv_value_tmp LIKE plfh-mgvgw,
lv_value_new LIKE plfh-mgvgw.

"Step 1
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
matnr = pa_matnr
input = pa_value
meinh = pa_old
kzmeinh = 'X'
meins = pa_meins
IMPORTING
output = lv_value_tmp
EXCEPTIONS
conversion_not_found = 01
input_invalid = 02
material_not_found = 03
meinh_not_found = 04
meins_missing = 05
no_meinh = 06
output_invalid = 07
overflow = 08.
IF sy-subrc = 8.
RAISE overflow.
ENDIF.

"Step 2
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
matnr = pa_matnr
input = lv_value_tmp
meinh = pa_new
kzmeinh = space
meins = pa_meins
IMPORTING
output = lv_value_new
EXCEPTIONS
conversion_not_found = 01
input_invalid = 02
material_not_found = 03
meinh_not_found = 04
meins_missing = 05
no_meinh = 06
output_invalid = 07
overflow = 08.
IF sy-subrc = 8.
RAISE overflow.
ENDIF.

WRITE : / lv_value_new.

Comments