FUNCTION zmm_fm_po_invence.
*"----------------------------------------------------------------------
*"*"本地接口:
*" TABLES
*" IT_PO_ITEMS TYPE ZMM_PO_ITEM
*"----------------------------------------------------------------------
TYPES:BEGIN OF typ_rseg,
belnr LIKE rseg-belnr,
gjahr LIKE rseg-gjahr,
buzei LIKE rseg-buzei,
ebeln LIKE rseg-ebeln,
ebelp LIKE rseg-ebelp,
wrbtr LIKE rseg-wrbtr,
shkzg LIKE rseg-shkzg,
mwskz LIKE rseg-mwskz,
lifnr LIKE rbkp-lifnr,
augbl LIKE bseg-augbl,
awkey LIKE bseg-awkey,
status TYPE c, "发票是否已过账
END OF typ_rseg.
TYPES:BEGIN OF typ_bseg,
belnr LIKE bseg-belnr,
gjahr LIKE bseg-gjahr,
awkey LIKE bseg-awkey,
augbl LIKE bseg-augbl,
END OF typ_bseg.
DATA:gt_rseg TYPE TABLE OF typ_rseg,
gs_rseg TYPE typ_rseg.
DATA:gt_bseg TYPE TABLE OF typ_bseg,
gs_bseg TYPE typ_bseg.
CHECK it_po_items IS NOT INITIAL.
SELECT
r~belnr
r~gjahr
r~buzei
r~ebeln
r~ebelp
r~wrbtr
r~shkzg
r~mwskz
rb~lifnr
INTO CORRESPONDING FIELDS OF TABLE gt_rseg
FROM rseg AS r
INNER JOIN rbkp AS rb
ON r~belnr = rb~belnr AND r~gjahr = rb~gjahr
FOR ALL ENTRIES IN it_po_items
WHERE r~ebeln = it_po_items-ebeln
AND r~ebelp = it_po_items-ebelp
AND rb~stblg = ''.
LOOP AT gt_rseg INTO gs_rseg.
gs_rseg-awkey = gs_rseg-belnr && gs_rseg-gjahr.
CONDENSE gs_rseg-awkey NO-GAPS.
MODIFY gt_rseg FROM gs_rseg TRANSPORTING awkey.
ENDLOOP.
SELECT
belnr
gjahr
awkey
augbl
INTO CORRESPONDING FIELDS OF TABLE gt_bseg
FROM bseg AS b
FOR ALL ENTRIES IN gt_rseg
WHERE b~awkey = gt_rseg-awkey
AND b~koart = 'K'.
SORT gt_bseg BY awkey.
SORT gt_rseg BY awkey.
LOOP AT gt_rseg INTO gs_rseg.
CLEAR gs_bseg.
READ TABLE gt_bseg INTO gs_bseg WITH KEY awkey = gs_rseg-awkey.
IF sy-subrc EQ 0.
gs_rseg-augbl = gs_bseg-augbl.
gs_rseg-status = 'X'."标识发票是否过账
ENDIF.
IF gs_rseg-shkzg EQ 'H'.
gs_rseg-wrbtr = gs_rseg-wrbtr * -1.
ENDIF.
IF gs_rseg-augbl IS NOT INITIAL.
gs_rseg-augbl = 'X'.
ENDIF.
MODIFY gt_rseg FROM gs_rseg.
ENDLOOP.
DATA:wa_po TYPE zmm_po_item_line.
DATA:it_po_hash TYPE