QQ群 :SAP干货铺, 群号:775662808
所有群管理严格,严格禁止一切外来链接、招聘、广告等垃圾信息!
PO
MIRO
或者不勾选计算税额,手动输入税额。
demo
*&---------------------------------------------------------------------*
*& Report ZLM_MIRO_2
*& SAP干货铺
*&---------------------------------------------------------------------*
*& 根据po创建贷项凭证
*&---------------------------------------------------------------------*
REPORT ZLM_MIRO_2.
TABLES EKKO.
TABLES EKPO.
PARAMETERS P_EBELN TYPE EKKO-EBELN DEFAULT '4690000030'.
PARAMETERS P_CA_TAX AS CHECKBOX DEFAULT 'X'."自动计算税费
DATA:LS_EKKO TYPE EKKO.
DATA:LT_EKPO TYPE TABLE OF EKPO.
DATA:LS_EKPO TYPE EKPO.
DATA:LT_MSEG TYPE TABLE OF MSEG.
DATA:LS_MSEG TYPE MSEG.
DATA:LS_HEADER TYPE BAPI_INCINV_CREATE_HEADER.
DATA:LT_TAXDATA TYPE TABLE OF BAPI_INCINV_CREATE_TAX.
DATA:LT_ITEM TYPE TABLE OF BAPI_INCINV_CREATE_ITEM.
DATA:LT_RETURN TYPE TABLE OF BAPIRET2.
DATA:LS_TAXDATA TYPE BAPI_INCINV_CREATE_TAX.
DATA:LS_ITEM TYPE BAPI_INCINV_CREATE_ITEM.
DATA:LS_RETURN TYPE BAPIRET2.
DATA:LV_DOC TYPE BAPI_INCINV_FLD-INV_DOC_NO.
START-OF-SELECTION.
SELECT SINGLE * FROM EKKO INTO LS_EKKO WHERE EBELN = P_EBELN.
SELECT * FROM EKPO INTO TABLE LT_EKPO WHERE EBELN = P_EBELN.
SELECT * FROM MSEG INTO TABLE LT_MSEG WHERE EBELN = P_EBELN.
CHECK SY-SUBRC = 0.
CLEAR LS_HEADER.
LS_HEADER-DOC_DATE = SY-DATUM.
LS_HEADER-PSTNG_DATE = SY-DATUM.
LS_HEADER-BLINE_DATE = SY-DATUM.
LS_HEADER-REF_DOC_NO = P_EBELN.
LS_HEADER-COMP_CODE = LS_EKKO-BUKRS.
LS_HEADER-DIFF_INV = LS_EKKO-LIFNR.
LS_HEADER-CURRENCY = LS_EKKO-WAERS.
*LS_HEADER-GROSS_AMOUNT = .
*LS_HEADER-HEADER_TXT = p_EBELN.
CLEAR LT_ITEM[].
CLEAR LT_TAXDATA[].
CLEAR LT_RETURN[].
CLEAR LS_ITEM.
LOOP AT LT_EKPO INTO LS_EKPO.
CLEAR LS_MSEG.
CLEAR LS_ITEM.
READ TABLE LT_MSEG INTO LS_MSEG
WITH KEY
EBELN = LS_EKPO-EBELN
EBELP = LS_EKPO-EBELP.
LS_ITEM-INVOICE_DOC_ITEM = SY-TABIX.
LS_ITEM-PO_NUMBER = LS_EKPO-EBELN.
LS_ITEM-PO_ITEM = LS_EKPO-EBELP.
LS_ITEM-REF_DOC = LS_MSEG-MBLNR.
LS_ITEM-REF_DOC_YEAR = LS_MSEG-MJAHR.
LS_ITEM-REF_DOC_IT = LS_MSEG-ZEILE.
LS_ITEM-TAX_CODE = LS_EKPO-MWSKZ.
LS_ITEM-ITEM_AMOUNT = LS_EKPO-NETWR.
LS_ITEM-QUANTITY = LS_EKPO-MENGE.
LS_ITEM-PO_UNIT = LS_EKPO-MEINS.
LS_HEADER-GROSS_AMOUNT = LS_HEADER-GROSS_AMOUNT + LS_EKPO-NETWR.
APPEND LS_ITEM TO LT_ITEM.
CLEAR LS_TAXDATA.
LS_TAXDATA-TAX_CODE = LS_EKPO-MWSKZ.
LS_TAXDATA-TAX_AMOUNT = LS_EKPO-NETWR * 17 / 100." demo 默认17%,
LS_TAXDATA-ITEMNO_TAX = LS_ITEM-INVOICE_DOC_ITEM.
LS_HEADER-GROSS_AMOUNT = LS_HEADER-GROSS_AMOUNT +
LS_TAXDATA-TAX_AMOUNT .
APPEND LS_TAXDATA TO LT_TAXDATA.
CLEAR LS_EKPO.
ENDLOOP.
IF P_CA_TAX IS NOT INITIAL.
LS_HEADER-CALC_TAX_IND = 'X'.
CLEAR LT_TAXDATA[].
ENDIF.
CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
EXPORTING
HEADERDATA = LS_HEADER
IMPORTING
INVOICEDOCNUMBER = LV_DOC
TABLES
ITEMDATA = LT_ITEM
TAXDATA = LT_TAXDATA
RETURN = LT_RETURN.
LOOP AT LT_RETURN INTO LS_RETURN WHERE TYPE = 'E'.
WRITE LS_RETURN-MESSAGE.
SKIP.
ENDLOOP.
WRITE LV_DOC.
ROLLBACK WORK.