[code]
Hello Experts,
Iam using the said BAPI for the first time and I am not sure if I filled up the
fields correctly. What I want to do is to post multiple debit entries(40) and a
special G/L entry for vendor(posting key 39). I also need to generate the tax and
withholding tax. So my entries will be like:
40 -->amount = 1,120(This value has a VAT included which is 12% or 120)
39 -->amount = 1,120(Special G/L for vendor)
For these 2 entries below, they must be generated automatically.
40 -->amount = 120(Tax)
50 -->amount = 20(This is the EWT or withholding tax)
Below is my code:
wa_documentheader-obj_type = 'BKPFF'.
CONCATENATE sy-sysid sy-mandt INTO wa_documentheader-obj_sys.
wa_documentheader-obj_key = '$'.
wa_documentheader-username = sy-uname.
wa_documentheader-comp_code = '1000'.
wa_documentheader-bus_act = 'RFBU'.
wa_documentheader-header_txt = 'AVH Testing...'.
wa_documentheader-fisc_year = '2007'.
wa_documentheader-doc_date = sy-datum.
wa_documentheader-pstng_date = sy-datum.
wa_documentheader-fis_period = '11'.
wa_documentheader-doc_type = 'S3'.
CLEAR wa_accountpayable.
wa_accountpayable-itemno_acc = 1.
wa_accountpayable-vendor_no = '2000000058'.
wa_accountpayable-sp_gl_ind = 'V'.
wa_accountpayable-tax_code = 'DI'.
APPEND wa_accountpayable TO it_accountpayable.
CLEAR: wa_accountgl.
wa_accountgl-itemno_acc = 2.
wa_accountgl-gl_account = '0060000061'.
wa_accountgl-item_text = 'Aris' .
wa_accountgl-DE_CRE_IND = 'S'.
wa_accountgl-tax_code = 'DI'.
wa_accountgl-comp_code = '1000'.
wa_accountgl-fisc_year = '2007'.
wa_accountgl-fis_period = '11'.
wa_accountgl-pstng_date = sy-datum.
wa_accountgl-doc_type = 'S3'.
INSERT wa_accountgl INTO TABLE it_accountgl.
CLEAR wa_accounttax.
wa_accounttax-itemno_acc = 3.
wa_accounttax-tax_code = 'DI'.
wa_accounttax-gl_account = '0010018291'.
wa_accounttax-acct_key = 'VST'.
APPEND wa_accounttax TO it_accounttax.
CLEAR: wa_currency.
wa_currency-itemno_acc = 1.
wa_currency-currency = 'PHP'.
wa_currency-curr_type = '00'.
wa_currency-amt_doccur = 1120.
wa_currency-amt_base = 1000.
wa_currency-exch_rate = 1.
APPEND wa_currency TO it_currency.
CLEAR: wa_currency.
wa_currency-itemno_acc = 2.
wa_currency-currency = 'PHP'.
wa_currency-curr_type = '00'.
wa_currency-amt_doccur = 1120.
wa_currency-amt_base = 1000.
wa_currency-exch_rate = 1.
APPEND wa_currency TO it_currency.
CLEAR: wa_currency.
wa_currency-itemno_acc = 3.
wa_currency-currency = 'PHP'.
wa_currency-curr_type = '00'.
wa_currency-amt_doccur = 120.
wa_currency-amt_base = 120.
wa_currency-exch_rate = 1.
APPEND wa_currency TO it_currency.
--------------------------------------------------------
Post
--------------------------------------------------------
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = it_accountgl
currencyamount = it_currency
return = it_return.
LOOP AT it_return INTO wa_return.
WRITE : /1 wa_return-message.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = wa_return3.
When I checked the return table there are 2 problems that says:
1. Error in document: BKPFF $ ED1CLNT140
2. Balance in transaction currency
Hope you can help me guys. Simple examples will be appreciated. Thank you and take care!
[/code]
<u>you can check the code.</u>
IF NOT wa_data-lifnr IS INITIAL.
ADD 1 TO g_lino.
x_vendoritem-itemno_acc = g_lino.
x_vendoritem-vendor_no = wa_data-lifnr.
IF wa_data-newbk IS INITIAL.
x_vendoritem-comp_code = wa_data-bukrs.
ELSE.
x_vendoritem-comp_code = wa_data-newbk.
ENDIF.
x_vendoritem-comp_code = t001-bukrs.
x_vendoritem-item_text = wa_data-csgtxt.
x_vendoritem-pmnttrms = wa_data-pyterm.
x_vendoritem-bline_date = wa_data-bldate.
x_vendoritem-pymt_meth = wa_data-zlsch.
x_vendoritem-alloc_nmbr = wa_data-zuonr.
x_vendoritem-tax_code = wa_data-mwskz.
x_vendoritem-taxjurcode = wa_data-txjcd.
APPEND x_vendoritem TO it_vendoritem.
x_currencyamount-itemno_acc = g_lino.
x_currencyamount-curr_type = c_ct1.
x_currencyamount-currency = t001-waers.
x_currencyamount-amt_doccur = wa_data-cwrbtr.
APPEND x_currencyamount TO it_currencyamount.
x_currencyamount-curr_type = c_ct2.
APPEND x_currencyamount TO it_currencyamount.
IF t001-land1 = c_lnd.
x_currencyamount-curr_type = c_ct3.
APPEND x_currencyamount TO it_currencyamount.
ENDIF.
ENDIF.
IF NOT wa_data-dsaknr IS INITIAL.
CLEAR:
x_accountgl,
x_currencyamount,
x_vendoritem.
ADD 1 TO g_lino.
x_accountgl-itemno_acc = g_lino.
x_accountgl-doc_type = x_doc_hdr-doc_type.
IF wa_data-newbk IS INITIAL.
x_accountgl-comp_code = wa_data-bukrs.
ELSE.
x_accountgl-comp_code = wa_data-newbk.
ENDIF.
x_accountgl-gl_account = wa_data-dsaknr.
x_accountgl-costcenter = wa_data-dkostl.
x_accountgl-item_text = wa_data-dsgtxt.
x_accountgl-orderid = wa_data-daufnr.
x_accountgl-wbs_element = wa_data-dwbs.
x_accountgl-pstng_date = p_pdate.
x_accountgl-vendor_no = wa_data-lifnr .
x_accountgl-alloc_nmbr = wa_data-zuonr.
x_accountgl-tax_code = wa_data-mwskz.
x_accountgl-taxjurcode = wa_data-txjcd.
APPEND x_accountgl TO it_accountgl.
x_currencyamount-itemno_acc = g_lino.
x_currencyamount-curr_type = c_ct1.
x_currencyamount-currency = t001-waers.
x_currencyamount-amt_doccur = - wa_data-dwrbtr.
APPEND x_currencyamount TO it_currencyamount.
x_currencyamount-curr_type = c_ct2.
APPEND x_currencyamount TO it_currencyamount.
IF t001-land1 = c_lnd.
x_currencyamount-curr_type = c_ct3.
APPEND x_currencyamount TO it_currencyamount.
ENDIF.
ENDIF.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = x_doc_hdr
TABLES
accountgl = it_accountgl
accountpayable = it_vendoritem
currencyamount = it_currencyamount
return = it_return.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
Reward if helpful.
Add a comment