1. 程式人生 > >交貨單可用性檢查,庫存+批次可用

交貨單可用性檢查,庫存+批次可用

可用性檢查函式函式
FUNCTION zsdfm001_60.
*"----------------------------------------------------------------------
*"*"本地介面:
*"  IMPORTING
*"     VALUE(I_MATNR) TYPE  MATNR OPTIONAL
*"     VALUE(I_CHARG) TYPE  CHARG_D OPTIONAL
*"     VALUE(I_VBELN) TYPE  VBELN
*"  EXPORTING
*"     VALUE(E_ITEM) TYPE  ZSDS086
*"----------------------------------------------------------------------
DATA: i_return LIKE bapiwmdve OCCURS 0 WITH HEADER LINE.
DATA: i_WMDVSX LIKE BAPIWMDVS OCCURS 0 WITH HEADER LINE.




*    批次庫存
DATA:BEGIN OF i_lips OCCURS 0,
      matnr LIKE lips-matnr,
      charg LIKE lips-charg,
      werks LIKE lips-werks,
      lgort LIKE lips-lgort,
      meins LIKE lips-meins,
      END OF i_lips.
      SELECT
      matnr
      charg
      werks
      lgort
      VRKME
      INTO TABLE i_lips
      FROM lips
      WHERE vbeln = i_vbeln.


      IF i_matnr IS NOT INITIAL."說明查詢的是沒有批次的庫存
                 READ TABLE i_lips WITH KEY matnr = i_matnr.


                SELECT SINGLE
                mard~matnr
                mard~labst
                mara~meins
                INTO (e_item-matnr,e_item-menge,e_item-meins )
                FROM mard
                INNER JOIN mara ON mara~matnr = mard~matnr
                WHERE  mard~werks = i_lips-werks AND mard~lgort = i_lips-lgort AND mard~matnr = i_matnr .




ELSEIF i_charg IS NOT INITIAL."查詢單個批次


      SELECT "SINGLE
      mchb~matnr
      mchb~charg
      mchb~clabs
      INTO  (e_item-matnr,e_item-charg,e_item-chnum )
      FROM mchb
      FOR ALL ENTRIES IN i_lips
      WHERE  mchb~werks = i_lips-werks AND mchb~lgort = i_lips-lgort and matnr = i_lips-matnr AND mchb~charg = i_charg .
     ENDSELECT.


      SELECT "SINGLE
      mard~matnr
      mard~labst
      mara~meins
      INTO (e_item-matnr,e_item-menge,e_item-meins )
      FROM mard
      INNER JOIN mara ON mara~matnr = mard~matnr
      FOR ALL ENTRIES IN i_lips
      WHERE  mard~werks = i_lips-werks AND mard~lgort = i_lips-lgort AND mard~matnr = e_item-matnr .
     ENDSELECT.


*          *批次可用庫存
      READ TABLE i_lips WITH KEY matnr = e_item-matnr.


      CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
      EXPORTING
        plant      = i_lips-werks
        material   = e_item-matnr
        UNIT       = i_lips-meins
        check_rule = 'B'
        stge_loc   = i_lips-lgort
        batch      = e_item-charg
      TABLES
        WMDVSX = I_WMDVSX
        wmdvex     = i_return.
        READ TABLE i_return INDEX 1.
        e_item-chnum_k = i_return-COM_QTY.
        REFRESH i_return.
  ENDIF.


*            *庫位可用庫存
refresh i_return.
  CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
  EXPORTING
    plant      = i_lips-werks
    material   = e_item-matnr
    UNIT       = i_lips-meins
    check_rule = 'B'
    stge_loc   = i_lips-lgort
  TABLES
    WMDVSX = I_WMDVSX
    wmdvex     = i_return.


  READ TABLE i_return INDEX 1.
  e_item-menge_k = i_return-COM_QTY.


*單位換算
  CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
  INPUT   = e_item-menge      "clabs--基本計量單位下庫存數量,為傳入引數
  kzmeinh = ' '
  matnr   = e_item-matnr
  meinh   = i_lips-meins
IMPORTING
  OUTPUT  = e_item-menge.      "輸出值賦值給zkcsl--公斤計庫存數量


  CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
  INPUT   = e_item-chnum      "clabs--基本計量單位下庫存數量,為傳入引數
  kzmeinh = ' '
  matnr   = e_item-matnr
  meinh   = i_lips-meins
IMPORTING
  OUTPUT  = e_item-chnum.      "輸出值賦值給zkcsl--公斤計庫存數量


E_ITEM-meins = I_LIPS-meins.
  ENDFUNCTION