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:it_po_hash TYPE HASHED TABLE OF zmm_po_item_line
WITH UNIQUE KEY ebeln ebelp lifnr.
DATA:t_t007s LIKE TABLE OF t007s WITH HEADER LINE.
DATA:l_str1(2) TYPE c,
l_str2(48) TYPE c.
DATA:shuilv TYPE int4.
LOOP AT gt_rseg INTO gs_rseg ."取出已开票过账的来统计总欠款和已清额
wa_po-ebeln = gs_rseg-ebeln.
wa_po-ebelp = gs_rseg-ebelp.
wa_po-lifnr = gs_rseg-lifnr.
CLEAR:t_t007s,t_t007s[].
CLEAR:l_str1,l_str2.
SELECT SINGLE *
INTO t_t007s
FROM t007s
WHERE spras = 1
AND kalsm = 'TAXCN'
AND mwskz = gs_rseg-mwskz.
SPLIT t_t007s-text1 AT '%' INTO l_str1 l_str2.
shuilv = l_str1.
gs_rseg-wrbtr = gs_rseg-wrbtr * ( 100 + shuilv ) / 100 .
wa_po-fp_sum = gs_rseg-wrbtr.
IF gs_rseg-augbl EQ 'X'.
wa_po-fp_yq = gs_rseg-wrbtr.
ENDIF.
COLLECT wa_po INTO it_po_hash.
CLEAR wa_po.
ENDLOOP.
CLEAR in_po_items.
out_po_items = it_po_hash[] .
ENDFUNCTION.