METHOD check_allow_cancel.
"获取发票对应的凭证是否存在清账凭证
SELECT SINGLE bseg~augbl,bkpf~belnr,bkpf~bukrs,bkpf~gjahr
FROM bkpf
INNER JOIN bseg ON ( bseg~belnr = bkpf~belnr AND bseg~bukrs = bkpf~bukrs AND bseg~gjahr = bkpf~gjahr
AND bseg~augbl IS NOT INITIAL AND bseg~koart = 'D' ) "augbl 清账凭证
WHERE bkpf~awtyp = 'VBRK'
AND bkpf~awkey = @iv_vbeln
INTO @DATA(ls_info).
IF sy-subrc = 0 AND ls_info IS NOT INITIAL.
"如果清账凭证不为空,则判断清账凭证是否已经冲销
SELECT SINGLE stblg
FROM bkpf WHERE belnr = @ls_info-augbl AND
bukrs = @ls_info-bukrs AND
gjahr = @ls_info-gjahr AND
stblg IS NOT INITIAL
INTO @DATA(lv_stblg).
IF sy-subrc = 0 AND lv_stblg IS INITIAL ."如果清账凭证未冲销,则不允许取消发票
RAISE EXCEPTION TYPE zcx_sd_invoice MESSAGE i138(vf) WITH |发票已核销,请先取消核销后,再取消本发票。& 处理凭证 { ls_info-belnr ALPHA = OUT } 期间出现数据不一致|.
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
标签:info,gjahr,bkpf,清账,bseg,冲销,ls,发票,SAP
From: https://www.cnblogs.com/Lingcc/p/16911393.html