sap转换成基本订单单位


sap转换成基本订单单位_第1张图片

源码:

  function zcf_ut_unit_conversion.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(MATNR_IMP) LIKE  MARA-MATNR DEFAULT SPACE
*"     VALUE(MEINS_IMP) LIKE  MARA-MEINS DEFAULT SPACE
*"     VALUE(UNIT_NEW_IMP) LIKE  T006-MSEHI
*"     VALUE(UNIT_OLD_IMP) LIKE  T006-MSEHI
*"     VALUE(VALUE_OLD_IMP) TYPE  MENGE_D
*"  EXPORTING
*"     VALUE(VALUE_NEW_EXP) TYPE  MENGE_D
*"  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.

endfunction.

   form frm_changeunit  changing value(p_1) value(p_2) value(p_3) .
  data : ls_mgvgw type menge_d."plfh-mgvgw.
  data : ls_meins type mara-meins.
  data : ls_value_new_exp type menge_d."LIKE plfh-mgvgw.
  clear : ls_meins,ls_value_new_exp.
  select single meins
  into ls_meins
  from mara
  where matnr = p_1.
  ls_mgvgw = p_2.
  call function 'ZCF_UT_UNIT_CONVERSION'
    exporting
      matnr_imp     = p_1
      meins_imp     = ls_meins
      unit_new_imp  = ls_meins
      unit_old_imp  = p_3
      value_old_imp = ls_mgvgw
    importing
      value_new_exp = ls_value_new_exp
    exceptions
      overflow      = 1
      others        = 2.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
    with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
  if not ls_value_new_exp is initial.
    p_2 = ls_value_new_exp.
  endif.
  p_3 = ls_meins.
endform.

 

   perform frm_changeunit changing wa_mseg-matnr wa_mseg-menge wa_mseg-meins .


你可能感兴趣的:(sap转换成基本订单单位)