Code: Alles auswählen.
FUNCTION z_fi_test.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(BUKRS) TYPE BUKRS
*" VALUE(GUTNR) TYPE DZUONR OPTIONAL
*" VALUE(FILIALE) TYPE WERKS_D OPTIONAL
*" VALUE(KOSTL) TYPE KOSTL OPTIONAL
*" VALUE(PERSNR) TYPE PERNR_D OPTIONAL
*" VALUE(HKONTS) TYPE HKONT
*" VALUE(HKONTH) TYPE HKONT
*" VALUE(WRBTR) TYPE WRBTR
*" VALUE(WAERS) TYPE WAERS
*" VALUE(SGTXT) TYPE SGTXT OPTIONAL
*" EXPORTING
*" VALUE(DOCNUM) TYPE BELNR_D
*" TABLES
*" RETURN STRUCTURE BAPIRET2 OPTIONAL
*" EXCEPTIONS
*" TAX_ERROR
*" ERRORS_OCCURED
*"----------------------------------------------------------------------
* Schnittstellendaten für Verbuchungs-BAPI
DATA:
l_documentheader TYPE bapiache09,
l_obj_type TYPE bapiache09-obj_type,
l_obj_key TYPE bapiache09-obj_key,
l_obj_sys TYPE bapiache09-obj_sys,
l_accountgl TYPE TABLE OF bapiacgl09 WITH HEADER LINE,
l_accounttax TYPE TABLE OF bapiactx09 WITH HEADER LINE,
l_currencyamount TYPE TABLE OF bapiaccr09 WITH HEADER LINE,
l_return TYPE TABLE OF bapiret2.
DATA:
l_t001 TYPE t001,
l_itemno TYPE posnr_acc,
l_xkostl,
lt_mwdat TYPE TABLE OF rtax1u15 WITH HEADER LINE.
CONSTANTS:
lc_doctype TYPE blart VALUE 'SA', "<<<< ggf. anpassen
lc_taxcode TYPE mwskz VALUE 'VA'. "<<<< ggf. anpassen
*-----------------------------------------------------------------------
* Initialisierung
*-----------------------------------------------------------------------
REFRESH: l_accountgl,
l_accounttax,
l_currencyamount,
l_return.
l_itemno = 1.
* Steuerinformationen versorgen
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
i_bukrs = bukrs
i_mwskz = lc_taxcode
i_waers = waers
i_wrbtr = wrbtr
TABLES
t_mwdat = lt_mwdat
EXCEPTIONS
OTHERS = 16.
IF sy-subrc NE 0.
RAISE tax_error.
ELSE.
READ TABLE lt_mwdat INDEX 1.
ENDIF.
*-----------------------------------------------------------------------
* Belegkopf
*-----------------------------------------------------------------------
CLEAR l_documentheader.
l_documentheader-bus_act = 'RFBU'.
l_documentheader-username = sy-uname.
l_documentheader-comp_code = bukrs.
l_documentheader-doc_date = sy-datum.
l_documentheader-pstng_date = sy-datum.
l_documentheader-ref_doc_no = 'RFC'.
l_documentheader-doc_type = lc_doctype.
*-----------------------------------------------------------------------
* 1. Belegposition (Soll)
*-----------------------------------------------------------------------
CLEAR: l_accountgl, l_currencyamount.
l_accountgl-itemno_acc = l_itemno.
l_accountgl-gl_account = hkonts.
l_accountgl-item_text = sgtxt.
l_accountgl-tax_code = lc_taxcode.
perform check_kostl_needed using bukrs
hkonts
changing l_xkostl.
if l_xkostl = 'X'.
l_accountgl-costcenter = kostl.
endif.
l_accountgl-alloc_nmbr = gutnr.
l_currencyamount-itemno_acc = l_accountgl-itemno_acc.
l_currencyamount-currency = waers.
l_currencyamount-amt_doccur = lt_mwdat-kawrt. "NETTO-BETRAG !!!
APPEND: l_accountgl, l_currencyamount.
*-----------------------------------------------------------------------
* 2. Belegposition (Haben)
*-----------------------------------------------------------------------
ADD 1 TO l_itemno.
CLEAR: l_accountgl, l_currencyamount.
l_accountgl-itemno_acc = l_itemno.
l_accountgl-gl_account = hkonth.
l_accountgl-item_text = sgtxt.
perform check_kostl_needed using bukrs
hkonth
changing l_xkostl.
if l_xkostl = 'X'.
l_accountgl-costcenter = kostl.
endif.
l_accountgl-alloc_nmbr = gutnr.
l_currencyamount-itemno_acc = l_accountgl-itemno_acc.
l_currencyamount-currency = waers.
l_currencyamount-amt_doccur = wrbtr * -1.
APPEND: l_accountgl, l_currencyamount.
*-----------------------------------------------------------------------
* Steuerzeile
*-----------------------------------------------------------------------
ADD 1 TO l_itemno.
CLEAR: l_accounttax, l_currencyamount.
l_accounttax-itemno_acc = l_itemno.
l_accounttax-tax_code = lc_taxcode.
l_accounttax-tax_rate = lt_mwdat-msatz.
l_currencyamount-itemno_acc = l_accounttax-itemno_acc.
l_currencyamount-currency = waers.
l_currencyamount-amt_doccur = lt_mwdat-wmwst.
l_currencyamount-amt_base = wrbtr.
APPEND: l_accounttax, l_currencyamount.
*-----------------------------------------------------------------------
* BAPI-Aufruf
*-----------------------------------------------------------------------
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = l_documentheader
IMPORTING
obj_type = l_obj_type
obj_key = l_obj_key
obj_sys = l_obj_sys
TABLES
accountgl = l_accountgl
* ACCOUNTRECEIVABLE =
* ACCOUNTPAYABLE =
accounttax = l_accounttax
currencyamount = l_currencyamount
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =
return = return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
COMMIT WORK.
* Abort oder Error-Meldung zurückgekommen?
LOOP AT return WHERE type = 'E'
OR type = 'A'.
RAISE errors_occured.
ENDLOOP.
docnum = l_obj_key(10).
ENDFUNCTION.