LOOP AT it_mard INTO wa_mard.
MOVE-CORRESPONDING wa_mard TO wa_result.
CALL FUNCTION 'ZFG_LOCAL_3'
EXPORTING
i_matnr = wa_mard-matnr
i_werks = wa_mard-werks
TABLES
lt_atpdsx = lt_atpdsx.
LOOP AT lt_atpdsx INTO ls_atpdsx WHERE atpnr+6(4) = wa_mard-lgort.
IF ls_atpdsx-delkz = 'VJ' OR ls_atpdsx-delkz = 'VC'. "订单、交货单
wa_result-kbmeng = wa_result-kbmeng + ls_atpdsx-qty_o. "订单、交货单占用 (计划数量为负值)
ENDIF.
CLEAR:ls_atpdsx.
ENDLOOP.
LOOP AT lt_atpdsx INTO ls_atpdsx WHERE delkz = 'U1'. "UB转储单占用
wa_ekpo-ebeln = ls_atpdsx-delnr.
wa_ekpo-matnr = wa_mard-matnr.
SELECT SINGLE reswk FROM ekko INTO wa_ekpo-werks
WHERE ebeln = wa_ekpo-ebeln.
wa_ekpo-menge = ls_atpdsx-qty_o.
APPEND wa_ekpo TO it_ekpo.
CLEAR: ls_atpdsx, wa_ekpo.
ENDLOOP.
APPEND wa_result TO it_result.
CLEAR:wa_mard,wa_result.
ENDLOOP.
FUNCTION zfg_local_3.
*"-----------------------------------