FPE3 | Beleg anzeigen |
FPL9 | Konto Anzeigen |
FBL3N | offene Posten für Sachkonten |
FS00 | Kontenplan anlegen |
Tag: FI
[FI] CALCULATE_TAX_FROM_GROSSAMOUNT
DATA lt_mwdat TYPE TABLE OF RTAX1U15.
CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
EXPORTING
i_bukrs = lv_bukrs
i_mwskz = lv_mwskz
* I_TXJCD = ' '
i_waers = lv_waers
i_wrbtr = lv_wrbtr
* IMPORTING
* E_FWNAV =
* E_FWNVV =
* E_FWSTE =
* E_FWAST =
TABLES
t_mwdat = lt_mwdat
EXCEPTIONS
bukrs_not_found = 1
country_not_found = 2
mwskz_not_defined = 3
mwskz_not_valid = 4
account_not_found = 5
different_discount_base = 6
different_tax_base = 7
txjcd_not_valid = 8
not_found = 9
ktosl_not_found = 10
kalsm_not_found = 11
parameter_error = 12
knumh_not_found = 13
kschl_not_found = 14
unknown_error = 15
OTHERS = 16.
IF sy-subrc <> 0 OR lt_mwdat IS INITIAL.
RAISE EXCEPTION TYPE zcx_xxx
EXPORTING
textid = zcx_xxx=>zcx_xxx
msgv1 = SWITCH #( sy-subrc
WHEN 1 THEN 'BUKRS_NOT_FOUND '
WHEN 2 THEN 'COUNTRY_NOT_FOUND'
WHEN 3 THEN 'MWSKZ_NOT_DEFINED'
WHEN 4 THEN 'MWSKZ_NOT_VALID'
WHEN 5 THEN 'ACCOUNT_NOT_FOUND'
WHEN 6 THEN 'DIFFERENT_DISCOUNT_BASE'
WHEN 7 THEN 'DIFFERENT_TAX_BASE'
WHEN 8 THEN 'TXJCD_NOT_VALID'
WHEN 9 THEN 'NOT_FOUND'
WHEN 10 THEN 'KTOSL_NOT_FOUND'
WHEN 11 THEN 'KALSM_NOT_FOUND'
WHEN 12 THEN 'PARAMETER_ERROR'
WHEN 13 THEN 'KNUMH_NOT_FOUND'
WHEN 14 THEN 'KSCHL_NOT_FOUND'
WHEN 15 THEN 'UNKNOWN_ERROR' )
mtype = 'E'.
ENDIF.
[ABAP] BAPI_ACC_DOCUMENT_POST
How to handle BAPI_ACC_DOCUMENT_POST with a document split at position 980. The method create_document fills the necessary tables and calls post_document, if it reaches position 980, to post the current document. Then the method create_document calls itself recursiv for the next positions.
METHOD create_document.
DATA: lt_pos TYPE TABLE OF bapiacgl09,
lt_pos_amt TYPE TABLE OF bapiaccr09.
gr_listlog->append_log_entry( iv_type = gr_listlog->gc_log_type_info
iv_text = |Beginne Belegerstellung|
iv_alog = abap_true ).
"Belegkopf
DATA(ls_documentheader) = VALUE bapiache09( comp_code = gs_sel-p_bukrs
header_txt = |header text|
pstng_date = sy-datum
doc_date = sy-datum
fisc_year = sy-datum(4)
fis_period = sy-datum+4(2)
doc_type = gs_sel-p_blart
username = sy-uname ).
"Fülle Positionen
LOOP AT it_xxx ASSIGNING FIELD-SYMBOL(<ls_xxx>).
APPEND VALUE #( itemno_acc = lines( lt_pos ) + 1
gl_account = <ls_xxx>-hkont
stat_con = abap_false
acct_type = 'S' "Sachkonto
bus_area = '0030'
fis_period = sy-datum+4(2)
fisc_year = sy-datum(4)
pstng_date = sy-datum
value_date = sy-datum
item_text = |item text|
alloc_nmbr = <ls_xxx>-zuonr
doc_type = <ls_xxx>-blart
comp_code = <ls_xxx>-bukrs
func_area = '0030'
costcenter = <ls_xxx>-kostl
tax_code = <ls_xxx>-mwskz ) TO lt_pos.
APPEND VALUE #( itemno_acc = lines( lt_pos_amt ) + 1
curr_type = '00' "Belegwährung
currency = |EUR|
amt_doccur = <ls_xxx>-betrg ) TO lt_pos_amt.
"Belegsplit notwendig?
IF lines( lt_pos ) = 980.
gr_listlog->append_log_entry( iv_type = gr_listlog->gc_log_type_statistic
iv_text = |Belegsplit notwendig!|
iv_alog = abap_true ).
"Verbuche die aktuellen Positionen
post_document( is_documentheader = ls_documentheader
it_pos = lt_pos
it_pos_amt = lt_pos_amt ).
"Rekursiver Aufruf der Methode! Nur mit den Sätzen die noch nicht verarbeitet wurden
create_document( it_xxx = FILTER #( it_xxx USING KEY sort_key WHERE xxx = xxx ) ).
"Verlasse bei Rekursion hier
RETURN.
ENDIF.
ENDLOOP.
"Wenn alle Positionen hinzugefügt, lege den Beleg an
post_document( is_documentheader = ls_documentheader
it_pos = lt_pos
it_pos_amt = lt_pos_amt ).
ENDMETHOD.
Calling the BAPI:
METHOD post_document.
DATA lt_return TYPE STANDARD TABLE OF bapiret2.
IF gs_sel-p_test = abap_true.
gr_listlog->append_log_entry( iv_type = gr_listlog->gc_log_type_info
iv_text = |Testlauf: Keine Belegbuchung|
iv_alog = abap_true ).
RETURN. "Im Testlauf hier verlassen
ENDIF.
SET UPDATE TASK LOCAL.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = is_documentheader
TABLES
accountgl = it_pos
currencyamount = it_pos_amt
return = lt_return.
"Protokollzeilen mit BAPI Meldungen hinzufügen
LOOP AT lt_return ASSIGNING FIELD-SYMBOL(<ls_return>).
gr_listlog->append_log_entry( iv_type = <ls_return>-type
iv_text = CONV #( <ls_return>-message )
iv_alog = abap_true ).
ENDLOOP.
"Prüfen, ob eine Fehlermeldung vorliegt
IF line_exists( lt_return[ type = 'A' ] ) OR line_exists( lt_return[ type = 'E' ] ).
"Rollback
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
"Alles gut -> commit
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
"Protokollzeile mit der Erzeugten Belegnummer nochmal explizit ins Log
DATA(lv_documentnumber) = lt_return[ 1 ]-message_v2(10). "hier steht laut Doku die Belegnummer drin
gr_listlog->append_log_entry( iv_type = gr_listlog->gc_log_type_success
iv_text = |Belegnummer: { lv_documentnumber }|
iv_alog = abap_true ).
ENDIF.
ENDMETHOD.