
Header Data | ||||||
Document Date | Document Type | Company Code | Posting Date | Reference | Fiscal Year | Fiscal Period |
20230814 | DT | 1000 | 20230814 | Reference | 2023 | 5 |
Item Data | ||||||
Posting Key | Account | Amount | Tax Amount | Cost Center | Tax Code | Currency |
31 | 859634 | 192 | CCC | |||
40 | 6783521 | 160 | 32 | 576924 | VT | CCC |
DATA: it_item_gl TYPE TABLE OF bapiacgl09, "G/L Items
it_item_vi TYPE TABLE OF bapiacap09, "Vendor Items
it_item_currency TYPE TABLE OF bapiaccr09, "Currency items
it_item_tax TYPE TABLE OF bapiactx09, "TAX account items
it_return TYPE TABLE OF bapiret2. "Return messages
DATA: wa_item_gl TYPE bapiacgl09,
wa_item_vi TYPE bapiacap09,
wa_item_currency TYPE bapiaccr09,
wa_header TYPE bapiache09,
wa_item_tax TYPE bapiactx09.
DATA: d_belnr TYPE bseg-belnr,
wa_accchg TYPE accchg,
it_accchg TYPE fdm_t_accchg.
wa_header-username = sy-uname.
wa_header-doc_date = '20230814'.
wa_header-doc_type = 'DT'. " Document Type
wa_header-comp_code = '1000'. " Company code
wa_header-pstng_date = '20230814'.
wa_header-fisc_year = '2023' .
wa_header-fis_period = '05'.
wa_header-ref_doc_no = 'Reference'.
wa_item_vi-itemno_acc = 1.
wa_item_currency-itemno_acc = 1.
wa_item_currency-amt_doccur = '-192.00'. " Posting key 31
wa_item_vi-vendor_no = '0000859634'. " Vendor Account
wa_item_vi-pmnttrms = '*'. " Payment terms
wa_item_currency-currency_iso = 'CCC'.
APPEND: wa_item_vi TO it_item_vi,
wa_item_currency TO it_item_currency.
CLEAR wa_item_currency.
wa_item_gl-itemno_acc = 2.
wa_item_currency-itemno_acc = 2.
wa_item_gl-tax_code = 'VT'.
wa_item_gl-fisc_year = '2023' .
wa_item_gl-gl_account = '0000083521'. "G/L Account
wa_item_gl-costcenter = '0000576924'. "Cost Center
wa_item_currency-amt_doccur = '160.00'. "Posting Key 40
wa_item_currency-currency_iso = 'CCC'.
APPEND: wa_item_gl TO it_item_gl,
wa_item_currency TO it_item_currency.
CLEAR wa_item_currency.
wa_item_tax-tax_code = 'VT'.
wa_item_tax-itemno_acc = 3.
wa_item_currency-itemno_acc = 3.
wa_item_currency-amt_doccur = '32.00'. " Posting key 40
wa_item_currency-currency_iso = 'CCC'.
wa_item_currency-amt_base = '160'.
APPEND wa_item_tax TO it_item_tax.
APPEND wa_item_currency TO it_item_currency.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_header
TABLES
accountgl = it_item_gl
accountpayable = it_item_vi
currencyamount = it_item_currency
accounttax = it_item_tax
return = it_return.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IF sy-msgno = 605.
WRITE: 'Document ',sy-msgv2.
ENDIF.
ENDIF.
DATA: d_belnr TYPE bseg-belnr,
wa_accchg TYPE accchg,
it_accchg TYPE fdm_t_accchg.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
IF sy-msgno = 605.
MOVE sy-msgv2 TO d_belnr.
WRITE: 'Document ',sy-msgv2.
SELECT bukrs, belnr, gjahr, lifnr , zterm FROM bseg INTO @DATA(wa_bseg)
WHERE bukrs = @wa_header-comp_code
AND belnr = @d_belnr
AND gjahr = @wa_header-fisc_year
AND koart = 'K'.
ENDSELECT.
wa_accchg-fdname = 'ZTERM'.
wa_accchg-oldval = wa_bseg-zterm.
wa_accchg-newval = 'Z098'.
APPEND wa_accchg TO it_accchg.
CALL FUNCTION 'FI_DOCUMENT_CHANGE'
EXPORTING
i_lifnr = wa_bseg-lifnr
i_bukrs = wa_bseg-bukrs
i_belnr = wa_bseg-belnr
i_gjahr = wa_bseg-gjahr
TABLES
t_accchg = it_accchg
EXCEPTIONS
no_reference = 1
no_document = 2
many_documents = 3
wrong_input = 4
overwrite_creditcard = 5
OTHERS = 6.
IF sy-subrc = 0.
MESSAGE 'Document payment term is updated' TYPE 'I'.
ELSE.
MESSAGE 'Document payment is not updated' TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
After the execution of program, we can verify the payment term of document form the same T-code FB03 for vender line item. Payment term of our document is updated as below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |