Code: Alles auswählen.
TYPES: BEGIN OF type_wip8,
bldat TYPE bsis-bldat,
blart TYPE bsis-blart,
bukrs TYPE bsis-bukrs,
date LIKE bsis-budat,
waers type bsis-waers,
wptxt LIKE bsis-sgtxt,
wptext like bsis-sgtxt,
bschl LIKE bsis-bschl,
konto LIKE bsis-hkont,
bwert(15) type c,
deduction TYPE p DECIMALS 2,
kst TYPE i,
aufnr TYPE afko-aufnr,
sgtxt TYPE bsis-sgtxt,
END OF type_wip8.
Folgende Benutzer bedankten sich beim Autor jensschladitz für den Beitrag:
SAP-Thomas
Code: Alles auswählen.
*&---------------------------------------------------------------------*
*& Report ZTEST_SR
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
report ztest_sr.
data: bukrs type bukrs value '1000', "Buchungskreis
hkonts type hkont value '0000047011', "Konto Soll
hkonth type hkont value '0000047012', "Konto Haben
waers type waers value 'EUR', "Belegwährung
wrbtr type wrbtr value 100, "Betrag
sgtxt type sgtxt value 'Test', "Belegpos.text
kostl type kostl value '0000001000', "Kostenstelle
zuonr type dzuonr value '23456', "Zuordnung
docnum type belnr_d. "Belegnummer
* 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,
* Sachkontenpositionen
l_accountgl type table of bapiacgl09 with header line,
* Steuerzeilen (in vorliegendem Bsp. nicht relevant)
l_accounttax type table of bapiactx09 with header line,
* Betragsinformationen
l_currencyamount type table of bapiaccr09 with header line,
* Meldungen des BAPI's
l_return type table of bapiret2 with header line.
data:
l_t001 type t001,
l_itemno type posnr_acc.
constants:
lc_doctype type blart value 'SA'. "<<<< ggf. anpassen
*-----------------------------------------------------------------------
* Initialisierung
*-----------------------------------------------------------------------
refresh: l_accountgl,
l_accounttax,
l_currencyamount,
l_return.
*-----------------------------------------------------------------------
* Positionsnummer (fängt bei 1 an und wird pro Belegpos. um 1 inkr.)
* Hinweis: Es können auch 10er Schritte verwendet werden, wichtig ist
* nur eins: Die Einträge der Tabellen l_accountgl und
* l_currencyamount finden über den jeweiligen Inhalt des Felds
* itemno_acc 'zueinander', d.h. anders ausgedrückt:
* Für jede Belegposition muss jeweils ein Eintrag in den
* genannten Tabellen mit identischer itemno_acc aufgenommen
* werden.
*-----------------------------------------------------------------------
l_itemno = 1.
*-----------------------------------------------------------------------
* Belegkopf
*-----------------------------------------------------------------------
clear l_documentheader.
l_documentheader-bus_act = 'RFBU'. "Vorgang (fix)
l_documentheader-username = sy-uname. "Belegerfasser
l_documentheader-comp_code = bukrs. "Buchungskreis
l_documentheader-doc_date = sy-datum. "Belegdatum
l_documentheader-pstng_date = sy-datum. "Buchungsdatum
l_documentheader-ref_doc_no = 'REFERENZ'. "Referenznummer
l_documentheader-doc_type = lc_doctype. "Belegart
*-----------------------------------------------------------------------
* 1. Belegposition (Soll)
*-----------------------------------------------------------------------
clear: l_accountgl, l_currencyamount.
l_accountgl-itemno_acc = l_itemno. "Positionsidentifier
l_accountgl-gl_account = hkonts. "Sachkonto (Soll)
l_accountgl-item_text = sgtxt. "Belegtext
l_accountgl-costcenter = kostl. "Kostenstelle
l_accountgl-alloc_nmbr = zuonr. "Zuordnung
* Betragssegment zur Sachkontenposition 1 mit identischem Identifier:
l_currencyamount-itemno_acc = l_accountgl-itemno_acc.
l_currencyamount-currency = waers.
l_currencyamount-amt_doccur = wrbtr.
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.
l_accountgl-alloc_nmbr = zuonr.
* Betragssegment zur Sachkontenposition 2 mit identischem Identifier:
l_currencyamount-itemno_acc = l_accountgl-itemno_acc.
l_currencyamount-currency = waers.
l_currencyamount-amt_doccur = wrbtr * -1. "Haben --> Minus
append: l_accountgl, 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.
* systemseitig vergebene Belegnummer kommt zurück!
docnum = l_obj_key(10).
Folgende Benutzer bedankten sich beim Autor MrBojangles für den Beitrag:
SAP-Thomas