Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI - BAPI_ACC_DOCUMENT_POST

Former Member
0 Likes
800

How Do Everyone,

I am trying to use the BAPI BAPI_ACC_DOCUMENT_POST without much success.

I have searched this site and got numerous suggestions has to how this BAPI should be called.

They are all different in there own way. Does anybody have a working example that I could have

a I look at ?

It would solve many headaches !!

Thanks

Andy

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
738

DATA: it_acc_gl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,

it_acc_ap LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,

it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

it_curr_amt LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,

it_doc_header LIKE bapiache09 OCCURS 0 WITH HEADER LINE,

it_acc_tax 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 it_doc_header-pstng_date,

doc_date LIKE it_doc_header-doc_date,

loop_cnt TYPE i VALUE 0,

gv_vendor(10) TYPE c,

gv_gl_acc(10) TYPE c.

LOOP AT bdc_source.

  • First line of table is heading so don't do anything

IF bdc_layout IS INITIAL.

MOVE bdc_source TO bdc_layout.

TRANSLATE bdc_layout TO UPPER CASE.

CONTINUE.

ENDIF.

bdc_out = bdc_source.

CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor, gv_gl_acc.

  • Setup the dates in correct format

CONCATENATE bdc_source-col_c6(4) bdc_source-col_c(2) bdc_source-col_c3(2) INTO pstng_date.

CONCATENATE bdc_source-col_b6(4) bdc_source-col_b(2) bdc_source-col_b3(2) INTO doc_date.

  • Padding zeros, very important otherwise bunch of stuff is missing

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = bdc_source-col_e

IMPORTING

output = gv_vendor.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = bdc_source-col_j

IMPORTING

output = gv_gl_acc.

  • Header

REFRESH it_doc_header.

it_doc_header-bus_act = 'RFBU'.

it_doc_header-username = sy-uname.

it_doc_header-header_txt = bdc_source-col_h. " Invoice Text

it_doc_header-comp_code = bdc_source-col_a. " Company Code

it_doc_header-doc_date = doc_date. " Invoice Date

it_doc_header-pstng_date = pstng_date. " Posting Date

it_doc_header-doc_type = 'KR'. " Return Order...?

it_doc_header-ref_doc_no = bdc_source-col_d. " Invoice Number

APPEND it_doc_header.

  • GL Account

REFRESH it_acc_gl.

it_acc_gl-itemno_acc = '1'.

it_acc_gl-gl_account = gv_gl_acc. " GL Account

it_acc_gl-item_text = bdc_source-col_o. " Line Item Text

it_acc_gl-doc_type = 'KR'. " Return Order...?

it_acc_gl-comp_code = bdc_source-col_a. " Company Code

it_acc_gl-pstng_date = pstng_date. " Posting Date

it_acc_gl-vendor_no = gv_vendor. " Vendor Number

it_acc_gl-costcenter = bdc_source-col_k. " Cost Center

it_acc_gl-wbs_element = bdc_source-col_q. " WBS Element

"it_acc_gl-tax_code = bdc_source-col_m. " Tax Code

it_acc_gl-network = bdc_source-col_p. " Internal Order

conv_s_amt = bdc_source-col_f. " Invoice Amount

REPLACE ALL OCCURRENCES OF ',' IN conv_s_amt WITH ''.

IF conv_s_amt < 0.

it_acc_gl-de_cre_ind = 'H'. " H-Credit

conv_s_amt = - conv_s_amt.

ELSE.

it_acc_gl-de_cre_ind = 'S'. " S-Debit

ENDIF.

CONDENSE conv_s_amt.

APPEND it_acc_gl.

  • AP Account

REFRESH it_acc_ap.

it_acc_ap-itemno_acc = '2'. " Invoice Number

it_acc_ap-vendor_no = gv_vendor. " Vendor Number

it_acc_ap-comp_code = bdc_source-col_a. " Company Code

it_acc_ap-item_text = bdc_source-col_o. " Line Item Text

APPEND it_acc_ap.

  • Currancy

REFRESH it_curr_amt.

it_curr_amt-itemno_acc = '1'. " Invoice Number

it_curr_amt-curr_type = '00'.

it_curr_amt-currency = bdc_source-col_g. " Currancy

it_curr_amt-amt_doccur = conv_s_amt. " Line Item Amount

APPEND it_curr_amt.

it_curr_amt-itemno_acc = '2'. " Invoice Number

it_curr_amt-curr_type = '00'.

it_curr_amt-currency = bdc_source-col_g. " Currancy

it_curr_amt-amt_doccur = conv_s_amt * -1. " Line Item Amount

APPEND it_curr_amt.

REFRESH it_return.

  • Do the post to GL Account and AP

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = it_doc_header

IMPORTING

obj_type = obj_type

obj_key = obj_key

obj_sys = obj_sys

TABLES

accountgl = it_acc_gl

currencyamount = it_curr_amt

accountpayable = it_acc_ap

return = it_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

  • Check for any errors

loop_cnt = 0.

LOOP AT it_return.

IF it_return-type = 'E'.

bdc_out-code = 'E'.

error_count = error_count + 1.

ELSE.

bdc_out-code = 'S'.

ENDIF.

loop_cnt = loop_cnt + 1.

IF loop_cnt = 1.

bdc_out-mesg1 = it_return-message.

ELSE.

IF loop_cnt = 2.

bdc_out-mesg2 = it_return-message.

ENDIF.

ENDIF.

ENDLOOP.

APPEND bdc_out.

cur_line = cur_line + 1.

ENDLOOP.

4 REPLIES 4
Read only

former_member404244
Active Contributor
0 Likes
737
Read only

Former Member
0 Likes
739

DATA: it_acc_gl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,

it_acc_ap LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,

it_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

it_curr_amt LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,

it_doc_header LIKE bapiache09 OCCURS 0 WITH HEADER LINE,

it_acc_tax 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 it_doc_header-pstng_date,

doc_date LIKE it_doc_header-doc_date,

loop_cnt TYPE i VALUE 0,

gv_vendor(10) TYPE c,

gv_gl_acc(10) TYPE c.

LOOP AT bdc_source.

  • First line of table is heading so don't do anything

IF bdc_layout IS INITIAL.

MOVE bdc_source TO bdc_layout.

TRANSLATE bdc_layout TO UPPER CASE.

CONTINUE.

ENDIF.

bdc_out = bdc_source.

CLEAR: obj_type, obj_sys, obj_key, pstng_date, doc_date, gv_vendor, gv_gl_acc.

  • Setup the dates in correct format

CONCATENATE bdc_source-col_c6(4) bdc_source-col_c(2) bdc_source-col_c3(2) INTO pstng_date.

CONCATENATE bdc_source-col_b6(4) bdc_source-col_b(2) bdc_source-col_b3(2) INTO doc_date.

  • Padding zeros, very important otherwise bunch of stuff is missing

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = bdc_source-col_e

IMPORTING

output = gv_vendor.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = bdc_source-col_j

IMPORTING

output = gv_gl_acc.

  • Header

REFRESH it_doc_header.

it_doc_header-bus_act = 'RFBU'.

it_doc_header-username = sy-uname.

it_doc_header-header_txt = bdc_source-col_h. " Invoice Text

it_doc_header-comp_code = bdc_source-col_a. " Company Code

it_doc_header-doc_date = doc_date. " Invoice Date

it_doc_header-pstng_date = pstng_date. " Posting Date

it_doc_header-doc_type = 'KR'. " Return Order...?

it_doc_header-ref_doc_no = bdc_source-col_d. " Invoice Number

APPEND it_doc_header.

  • GL Account

REFRESH it_acc_gl.

it_acc_gl-itemno_acc = '1'.

it_acc_gl-gl_account = gv_gl_acc. " GL Account

it_acc_gl-item_text = bdc_source-col_o. " Line Item Text

it_acc_gl-doc_type = 'KR'. " Return Order...?

it_acc_gl-comp_code = bdc_source-col_a. " Company Code

it_acc_gl-pstng_date = pstng_date. " Posting Date

it_acc_gl-vendor_no = gv_vendor. " Vendor Number

it_acc_gl-costcenter = bdc_source-col_k. " Cost Center

it_acc_gl-wbs_element = bdc_source-col_q. " WBS Element

"it_acc_gl-tax_code = bdc_source-col_m. " Tax Code

it_acc_gl-network = bdc_source-col_p. " Internal Order

conv_s_amt = bdc_source-col_f. " Invoice Amount

REPLACE ALL OCCURRENCES OF ',' IN conv_s_amt WITH ''.

IF conv_s_amt < 0.

it_acc_gl-de_cre_ind = 'H'. " H-Credit

conv_s_amt = - conv_s_amt.

ELSE.

it_acc_gl-de_cre_ind = 'S'. " S-Debit

ENDIF.

CONDENSE conv_s_amt.

APPEND it_acc_gl.

  • AP Account

REFRESH it_acc_ap.

it_acc_ap-itemno_acc = '2'. " Invoice Number

it_acc_ap-vendor_no = gv_vendor. " Vendor Number

it_acc_ap-comp_code = bdc_source-col_a. " Company Code

it_acc_ap-item_text = bdc_source-col_o. " Line Item Text

APPEND it_acc_ap.

  • Currancy

REFRESH it_curr_amt.

it_curr_amt-itemno_acc = '1'. " Invoice Number

it_curr_amt-curr_type = '00'.

it_curr_amt-currency = bdc_source-col_g. " Currancy

it_curr_amt-amt_doccur = conv_s_amt. " Line Item Amount

APPEND it_curr_amt.

it_curr_amt-itemno_acc = '2'. " Invoice Number

it_curr_amt-curr_type = '00'.

it_curr_amt-currency = bdc_source-col_g. " Currancy

it_curr_amt-amt_doccur = conv_s_amt * -1. " Line Item Amount

APPEND it_curr_amt.

REFRESH it_return.

  • Do the post to GL Account and AP

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = it_doc_header

IMPORTING

obj_type = obj_type

obj_key = obj_key

obj_sys = obj_sys

TABLES

accountgl = it_acc_gl

currencyamount = it_curr_amt

accountpayable = it_acc_ap

return = it_return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'.

  • Check for any errors

loop_cnt = 0.

LOOP AT it_return.

IF it_return-type = 'E'.

bdc_out-code = 'E'.

error_count = error_count + 1.

ELSE.

bdc_out-code = 'S'.

ENDIF.

loop_cnt = loop_cnt + 1.

IF loop_cnt = 1.

bdc_out-mesg1 = it_return-message.

ELSE.

IF loop_cnt = 2.

bdc_out-mesg2 = it_return-message.

ENDIF.

ENDIF.

ENDLOOP.

APPEND bdc_out.

cur_line = cur_line + 1.

ENDLOOP.

Read only

0 Likes
737

Many thanks for the quick reply Parminder.

I have looked at your code and I can't see the BDC_SOURCE.

Could you let me have the layout as well please.

Thanks

Andy

Read only

Former Member
0 Likes
737

Hi,,

Andy

wht u need exactly if u need any docments regarding BAPI i.e

wht are BAPI's

how to create them why they are needed

i have those documents if u want just send me one testmail so tht i can send u the documents

my mail id mutyalasunilkumar@gmail.com

plzz reward after getting those documents

plzz dont forget to reward....