1、传入和传出表结构都是一样的:
FUNCTION zmm_fm_po_invence.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" VALUE(IN_PO_ITEMS) TYPE ZMM_PO_ITEM OPTIONAL
*" EXPORTING
*" VALUE(OUT_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 in_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 in_po_items
WHERE r~ebeln = in_po_items-ebeln
AND r~ebelp = in_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