'CF_UT_UNIT_CONVERSION'其实这个函数里面包括了很多大大小小不同的单位转换函数,就像我们小时候玩的43合一的游戏卡一样,如果这个转换不了单位那就是系统没配置了。
使用的时候注意:
新旧转换数量的格式一定要LIKE PLFH-MGVGW.
例程:
DATA : matcat LIKE cstmat,
value_old_imp LIKE plfh-mgvgw, (之前的数量字段)
value_new_exp LIKE plfh-mgvgw. (转换后的数量存放字段)
CLEAR value_new_exp.
CLEAR value_old_imp.
value_old_imp = gc_lfimg.
PERFORM f_add_zero USING et_print_001-matnr.
PERFORM unit_convert USING et_print_001-matnr(物料号) '' et_print_001-bemeh(需要转换的单位) et_print_001-gewei(之前数量的单位) value_old_imp CHANGING value_new_exp.
et_print_001-meng3(转换后数量存放的字段) = value_new_exp.
*&--------------------------------------------------------------------*
*& Form f_unit_change
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->VI_INPUT text
* -->VI_UNIT_IN text
* -->VI_UNIT_OUTtext
* -->VI_OUTPUT text
*---------------------------------------------------------------------*
FORM unit_convert USING matnr_imp meins_imp unit_new_imp unit_old_imp value_old_imp CHANGING value_new_exp.
CALL FUNCTION 'CF_UT_UNIT_CONVERSION'
EXPORTING
matnr_imp = matnr_imp
meins_imp = meins_imp
unit_new_imp = unit_new_imp
unit_old_imp = unit_old_imp
value_old_imp = value_old_imp
IMPORTING
value_new_exp = value_new_exp
EXCEPTIONS
overflow = 1
OTHERS = 2.
ENDFORM. "unit_convert
--------------------------------------------------------------------------------------
call function 'CF_UT_UNIT_CONVERSION'
exporting
matnr_imp = p_matnr "物料碼 (可選)
meins_imp = p_meins "物料基本單位(可選)
unit_new_imp = to_unit "目標單位
unit_old_imp = From_unit "原單位
value_old_imp = p_qty "轉換數量
importing
value_new_exp = out_pty. "目標單位數量
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.