MMSC 扩充物料库存地点

当涉及到物料的库存地点时,系统通常会做校验,该物料是否扩充了库存地点,没有扩充则报错。为了不使这样的错误干扰到程序逻辑,通常会在涉及时,先查询MARD表,判断是否存在对应的库存地点。如果没有存在,则直接先扩充库存地点,再执行程序逻辑

1、前台扩充

MMSC

输入库存地点,点击保存

 

2、BAPI实现

2.1、扩充多个物料

调用BAPI:BAPI_MATERIAL_SAVEREPLICA


"--------------------@斌将军--------------------
DATA:ls_return TYPE bapiret2,
     lt_head   TYPE TABLE OF bapie1matheader WITH HEADER LINE,
     lt_mard   TYPE TABLE OF bapie1mard WITH HEADER LINE,
     lt_mardx  TYPE TABLE OF bapie1mardx WITH HEADER LINE.

lt_head-function     = '009'.
lt_head-material     = 'HYM01'.
lt_head-storage_view = 'X'.
APPEND lt_head.
CLEAR lt_head.

lt_mard-function     = '009'.
lt_mard-material     =  'HYM01'.
lt_mard-plant        =  '1000'.
lt_mard-stge_loc     =  '1002'.
APPEND lt_mard.
CLEAR lt_mard.

lt_mardx-function     = '009'.
lt_mardx-material     =  'HYM01'.
lt_mardx-plant        =  '1000'.
lt_mardx-stge_loc     =  '1002'.
APPEND lt_mardx.
CLEAR lt_mardx.

CALL FUNCTION 'BAPI_MATERIAL_SAVEREPLICA'
  EXPORTING
    noappllog            = 'X'
    nochangedoc          = ''
    testrun              = ''
    inpfldcheck          = ''
  IMPORTING
    return               = ls_return
  TABLES
    headdata             = lt_head
    storagelocationdata  = lt_mard
    storagelocationdatax = lt_mardx.

IF ls_return-type <> 'E'.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
"--------------------@斌将军--------------------

2.2、扩充单个物料

调用BAPI:BAPI_MATERIAL_SAVEDATA

"--------------------@斌将军--------------------
DATA: ls_head   TYPE bapimathead,
      ls_stld   TYPE bapi_mard,
      ls_stldx  TYPE bapi_mardx,
      ls_return TYPE bapiret2.

CLEAR:ls_head,ls_stld,ls_stldx.

ls_head-material     = '000000000001100023'. " 物料编号
ls_head-storage_view = 'X'.          " 存储视图
"
ls_stld-plant    = 'P060'. " 工厂
ls_stld-stge_loc = '9201'. " 存储地点

ls_stldx-plant    = 'P060'. " 工厂
ls_stldx-stge_loc = '9201'. " 存储地点

CLEAR ls_return.
CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    headdata             = ls_head " 物料
    storagelocationdata  = ls_stld " 工厂&存储地点
    storagelocationdatax = ls_stldx " 工厂&存储地点
  IMPORTING
    return               = ls_return.

IF ls_return-type CA 'AEX'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
ENDIF.
"--------------------@斌将军--------------------

 

定期更文,欢迎关注

 
 
 
 
 
 
 
 
posted @ 2022-03-16 17:09  斌将军  阅读(480)  评论(0编辑  收藏  举报