Function for Unit Conversion (Support Large Quantity)

*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(MATNR_IMP) LIKE MARA-MATNR
*" REFERENCE(MEINS_IMP) LIKE MARA-MEINS
*" REFERENCE(UNIT_NEW_IMP) LIKE T006-MSEHI
*" REFERENCE(UNIT_OLD_IMP) LIKE T006-MSEHI
*" REFERENCE(VALUE_OLD_IMP) LIKE LIPS-LFIMG
*" EXPORTING
*" REFERENCE(VALUE_NEW_EXP) LIKE LIPS-LFIMG
*" EXCEPTIONS
*" OVERFLOW
*"----------------------------------------------------------------------

* Lokale Vereinbarungen
DATA VALUE_MEINS_TMP TYPE F.

IF MATNR_IMP IS INITIAL.
CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
EXPORTING
INPUT = VALUE_OLD_IMP
ROUND_SIGN = 'X'
UNIT_IN = UNIT_OLD_IMP
UNIT_OUT = UNIT_NEW_IMP
IMPORTING
OUTPUT = VALUE_NEW_EXP
EXCEPTIONS
CONVERSION_NOT_FOUND = 01
DIVISION_BY_ZERO = 02
INPUT_INVALID = 03
OUTPUT_INVALID = 04
OVERFLOW = 05
TYPE_INVALID = 06
UNITS_MISSING = 07
UNIT_IN_NOT_FOUND = 08
UNIT_OUT_NOT_FOUND = 09.
IF SY-SUBRC = 5.
RAISE OVERFLOW.
ENDIF.
ELSE.
* Umrechnung in Basismenge
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
MATNR = MATNR_IMP
INPUT = VALUE_OLD_IMP
MEINH = UNIT_OLD_IMP
KZMEINH = 'X'
MEINS = MEINS_IMP
IMPORTING
OUTPUT = VALUE_MEINS_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.
* Umrechnung auf neue Alternativmengeneinheit
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
MATNR = MATNR_IMP
INPUT = VALUE_MEINS_TMP
MEINH = UNIT_NEW_IMP
KZMEINH = SPACE
MEINS = MEINS_IMP
IMPORTING
OUTPUT = VALUE_NEW_EXP
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.
ENDIF.

Comments