on 04-24-2019 10:34 AM
Hi All,
How to use BAPI_ACC_DOCUMENT_POST to post FB41 entries.
Rgds,
Anusha
Hi An
here is the sample code for your reference of this entry do comment for ay clarifications.
DATA: gl_acc LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
ap_acc LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
returns LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
amt_in_cur LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
headerinfo LIKE bapiache09 OCCURS 0 WITH HEADER LINE,
tax_acc LIKE bapiactx09 OCCURS 0 WITH HEADER LINE,
obj_type LIKE bapiache09-obj_type,
obj_key LIKE bapiache09-obj_key,
obj_sys LIKE bapiache09-obj_sys,
pstng_date LIKE headerinfo-pstng_date,
doc_date LIKE headerinfo-doc_date,
counter TYPE i VALUE 0,
gv_vendor(10) TYPE c,
gv_gl_acc(10) TYPE c.
LOOP AT excel_source.
* First line of table is heading so don't do anything
IF excelayout IS INITIAL.
MOVE excel_source TO excelayout.
TRANSLATE excelayout TO UPPER CASE.
CONTINUE.
ENDIF.
output = excel_source.
CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor, gv_gl_acc.
* Setup the dates in correct format
CONCATENATE excel_source-col_c+6(4) excel_source-col_c(2) excel_source-col_c+3(2) INTO pstng_date.
CONCATENATE excel_source-col_b+6(4) excel_source-col_b(2) excel_source-col_b+3(2) INTO doc_date.
* Padding zeros, very important otherwise bunch of stuff is missing
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = excel_source-col_e
IMPORTING
output = gv_vendor.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = excel_source-col_j
IMPORTING
output = gv_gl_acc.
* Header
REFRESH headerinfo.
headerinfo-bus_act = 'RFBU'.
headerinfo-username = sy-uname.
headerinfo-header_txt = excel_source-col_h. " Invoice Text
headerinfo-comp_code = excel_source-col_a. " Company Code
headerinfo-doc_date = doc_date. " Invoice Date
headerinfo-pstng_date = pstng_date. " Posting Date
headerinfo-doc_type = 'KR'. " Return Order...?
headerinfo-ref_doc_no = excel_source-col_d. " Invoice Number
APPEND headerinfo.
* GL Account
REFRESH gl_acc.
gl_acc-itemno_acc = '1'.
gl_acc-gl_account = gv_gl_acc. " GL Account
gl_acc-item_text = excel_source-col_o. " Line Item Text
gl_acc-doc_type = 'KR'. " Return Order...?
gl_acc-comp_code = excel_source-col_a. " Company Code
gl_acc-pstng_date = pstng_date. " Posting Date
gl_acc-vendor_no = gv_vendor. " Vendor Number
gl_acc-costcenter = excel_source-col_k. " Cost Center
gl_acc-wbs_element = excel_source-col_q. " WBS Element
"gl_acc-tax_code = excel_source-col_m. " Tax Code
gl_acc-network = excel_source-col_p. " Internal Order
conv_s_amt = excel_source-col_f. " Invoice Amount
REPLACE ALL OCCURRENCES OF ',' IN conv_s_amt WITH ''.
IF conv_s_amt < 0.
gl_acc-de_cre_ind = 'H'. " H-Credit
conv_s_amt = - conv_s_amt.
ELSE.
gl_acc-de_cre_ind = 'S'. " S-Debit
ENDIF.
CONDENSE conv_s_amt.
APPEND gl_acc.
* AP Account
REFRESH ap_acc.
ap_acc-itemno_acc = '2'. " Invoice Number
ap_acc-vendor_no = gv_vendor. " Vendor Number
ap_acc-comp_code = excel_source-col_a. " Company Code
ap_acc-item_text = excel_source-col_o. " Line Item Text
APPEND ap_acc.
* Currancy
REFRESH amt_in_cur.
amt_in_cur-itemno_acc = '1'. " Invoice Number
amt_in_cur-curr_type = '00'.
amt_in_cur-currency = excel_source-col_g. " Currancy
amt_in_cur-amt_doccur = conv_s_amt. " Line Item Amount
APPEND amt_in_cur.
amt_in_cur-itemno_acc = '2'. " Invoice Number
amt_in_cur-curr_type = '00'.
amt_in_cur-currency = excel_source-col_g. " Currancy
amt_in_cur-amt_doccur = conv_s_amt * -1. " Line Item Amount
APPEND amt_in_cur.
REFRESH returns.
* Do the post to GL Account and AP
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = headerinfo
IMPORTING
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
TABLES
accountgl = gl_acc
currencyamount = amt_in_cur
accountpayable = ap_acc
return = returns.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
* Check for any errors
counter = 0.
LOOP AT returns.
IF returns-type = 'E'.
output-code = 'E'.
error_count = error_count + 1.
ELSE.
output-code = 'S'.
ENDIF.
counter = counter + 1.
IF counter = 1.
output-mesg1 = returns-message.
ELSE.
IF counter = 2.
output-mesg2 = returns-message.
ENDIF.
ENDIF.
ENDLOOP.
APPEND output.
cur_line = cur_line + 1.
ENDLOOP.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All,
I wrote to SAP and they suggested not to passany values to tax structure.I am able to post to fb41 without any error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
10 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.