有時候在訂單或出貨單指定撿貨位置的時候
如果該物料在物料主檔中的儲存位置沒維護的話可是會顯示錯誤的
這個時候除的透過mm01->去設定一個儲存位置以外
還可以透過bapi的方式去做建立,可以直接寫在訂單或出貨單的UserExit中來做即時判斷建立
以下是先檢查table:mard 有沒有這個物料的儲存位置,沒有的話就直接建立
SELECT SINGLE * FROM MARD WHERE MATNR = Y_MATNR
AND WERKS = y_werks
AND LGORT = y_lgort.
IF SY-SUBRC <> 0.
TABLES:bapimathead.
DATA: RET2 LIKE BAPIRET2.
DATA: STORAG LIKE BAPI_MARD OCCURS 0 WITH HEADER LINE.
DATA: STORAGX LIKE BAPI_MARDX OCCURS 0 WITH HEADER LINE.
bapimathead-material = Y_MATNR.
bapimathead-storage_view = 'X'.
STORAG-plant = y_werks.
STORAG-stge_loc = y_lgort.
STORAGX-plant = y_werks.
STORAGX-stge_loc = y_lgort.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = bapimathead
storagelocationdata = STORAG
storagelocationdatax = STORAGX
IMPORTING
return = RET2.
ENDIF.
IF RET2-TYPE <> 'S'.
*== 訊息類型︰S 成功,E 錯誤, W 警告﹐I 資訊﹐A 取消
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = RET2-id
msgnr = RET2-NUMBER
msgv1 = RET2-MESSAGE_V1
msgv2 = RET2-MESSAGE_V2
msgv3 = RET2-MESSAGE_V3
msgv4 = RET2-MESSAGE_V4
IMPORTING
message_text_output = return.
ENDIF.
留言列表