Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZTEST_SR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztest_sr.
data: bukrs type bukrs value '1000',
hkonts type hkont value '0000415000',
hkonth type hkont value '0000100000',
waers type waers value 'EUR',
wrbtr type wrbtr value 100,
sgtxt type sgtxt value 'Test',
kostl type kostl value '0000001000',
gutnr type dzuonr value '23456',
docnum type belnr_d.
* 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 with header line.
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 'XX'. "<<<< 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 + lt_mwdat-wmwst.
l_currencyamount-amt_base = lt_mwdat-kawrt.
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 = lt_mwdat-kawrt.
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 = l_return
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
* ACCOUNTWT =
.
commit work.
loop at l_return .
write: / l_return-type,
l_return-id,
l_return-number,
l_return-message,
l_return-message_v1,
l_return-message_v2,
l_return-message_v3,
l_return-message_v4.
endloop.
docnum = l_obj_key(10).
*
*&---------------------------------------------------------------------*
*& Form check_kostl_needed
*&---------------------------------------------------------------------*
* Prüft, ob das Sachkonto eine Kostenart ist und ob darum
* ggf. eine Kostenstelle mitkontiert werden muss
*----------------------------------------------------------------------*
* -->P_BUKRS Buchungskreis
* -->P_hkont Sachkonto
* <--P_XKOSTL SPACE = keine Kostenstelle, X = Kostenst. nötig
*----------------------------------------------------------------------*
form check_kostl_needed using p_bukrs type bukrs
p_hkont type hkont
changing p_xkostl.
data: l_kokrs type kokrs,
l_hkont type hkont,
l_numko(10) type n.
if p_hkont co '0123456789 '.
l_hkont = l_numko = p_hkont.
else.
l_hkont = p_hkont.
endif.
call function 'KOKRS_GET_FROM_BUKRS'
exporting
i_bukrs = p_bukrs
importing
e_kokrs = l_kokrs.
call function 'RK_KSTAR_READ'
exporting
datum = sy-datum
kokrs = l_kokrs
kstar = l_hkont
exceptions
kstar_not_found = 1
others = 2.
if sy-subrc = 0.
p_xkostl = 'X'.
else.
p_xkostl = space.
endif.
endform. " check_kostl_needed