Application Development 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: 

BAPI BAPI_ACC_DOCUMENT_POST

Former Member
0 Kudos

I want to transfer COPA characteristics to an accounting document being created using FM BAPI_ACC_DOCUMENT_POST. I am in doubt of how i should go about using the tables CRITERIA and VALUEFIELD.

Can you please share a code example for the same.

3 REPLIES 3

Former Member
0 Kudos

Here is an example code on how to use this puppy:

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.

0 Kudos

Karthikeyan i am not seeking to know how to use the FM in totality.

I need to know how to make use of the COPA characteristics. If you have an example of that please do forward me the same.

The answer you provided is not what i am looking for,

0 Kudos

Hi Karthikeyan

Where are the tables CRITERIA and VALUEFIELD asked for?

You may win some merits answering questions, not necessarily for posting code without direct relevance to the question.

AND: If you post any code, please use the Code button on top of the text input window. This retains the formatting and helps read.

We all hate the point-grabbers, don't we?

Regards,

Clemens