ABAP-获得商品可用库存BAPI
2019-02-15 本文已影响0人
IAmZenos
获得商品可用库存 BAPI_MATERIAL_AVAILABILITY
业务场景:零售业务,POS系统发起请货单,SAP执行对应的配货逻辑
以下代码为程序在的一个perform,仅供参考:
DATA:ls_wmdvex LIKE bapiwmdve, "可用库存获取函数变量
lt_wmdvsx LIKE STANDARD TABLE OF bapiwmdvs,
lt_wmdvex LIKE STANDARD TABLE OF bapiwmdve.
DATA:BEGIN OF lt_kykc OCCURS 0,
bukrs TYPE t001-bukrs,
werks TYPE ztmm_gy_allot-werks,
lgort TYPE ztmm_gy_allot-lgort,
matnr TYPE mara-matnr,
meins TYPE mara-meins,
zkxkc TYPE bapiwmdve-com_qty, "可销库存
END OF lt_kykc.
FORM fm_get_stockdata .
"获取可用库存
MOVE-CORRESPONDING gt_alv_data[] TO lt_kykc[].
SORT lt_kykc BY bukrs matnr werks lgort.
DELETE ADJACENT DUPLICATES FROM lt_kykc
COMPARING bukrs matnr werks lgort .
LOOP AT lt_kykc.
SELECT SINGLE meins FROM mara
INTO lt_kykc-meins
WHERE matnr = lt_kykc-matnr.
REFRESH:lt_wmdvex,lt_wmdvsx.
CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
EXPORTING
plant = lt_kykc-werks "'9050/9051/9052'
material = lt_kykc-matnr
unit = lt_kykc-meins
stge_loc = lt_kykc-lgort "'1000'
TABLES
wmdvsx = lt_wmdvsx
wmdvex = lt_wmdvex.
lt_kykc-zkxkc = 0.
LOOP AT lt_wmdvex INTO ls_wmdvex.
lt_kykc-zkxkc = lt_kykc-zkxkc + ls_wmdvex-com_qty."总可用库存
ENDLOOP.
MODIFY lt_kykc.
ENDLOOP.
ENDFORM.```