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: 

how to use Bapi - 'BAPI_ACC_DOCUMENT_POST'

Former Member
35,418

Hi Gurus,

I want to use Bapi - 'BAPI_ACC_DOCUMENT_POST'.

The below code gived message that - Document posted successfully: BKPFF 180000046710012010 DW1CLNT100

but the document number gererated is not getting stored in any of BKPF or BSEG tables.

The Bapi should work in the same way as FB01

Please check and let me know your valuable suggestions on why document number is not getting saved.

_______________________________________________________________________________

DATA: lwa_header TYPE bapiache09,

lt_ar TYPE TABLE OF bapiacar09,

lwa_ar TYPE bapiacar09,

lt_return TYPE TABLE OF bapiret2,

lwa_return TYPE bapiret2,

lt_curr TYPE TABLE OF bapiaccr09,

lwa_curr TYPE bapiaccr09.

*Start

DATA : it_accountgl TYPE STANDARD TABLE OF bapiacgl09 ,

lwa_accountgl TYPE bapiacgl09.

*End

CLEAR: lwa_header, lt_ar, lwa_ar, lt_return, lwa_return, lt_curr, lwa_curr.

lwa_header-bus_act = 'BKPF'.

lwa_header-username = 'GOWDA'.

lwa_header-comp_code = '1001'.

lwa_header-doc_date = '20091102'.

lwa_header-pstng_date = '20091102'.

lwa_header-trans_date = '20091102'.

lwa_header-fisc_year = '2010'.

lwa_header-fis_period = '06'.

lwa_header-doc_type = 'DR'.

lwa_accountgl-itemno_acc = '0000000001'.

lwa_accountgl-gl_account = '0020000000'.

lwa_accountgl-tax_code = 'V1'.

lwa_accountgl-item_text = 'BAPI Test G/L line item'.

APPEND lwa_accountgl TO it_accountgl.

*lwa_ar-itemno_acc = '0000000001'.

*lwa_ar-customer = '4000000006'.

*lwa_ar-gl_account = '0012110000'.

**lwa_ar-gl_account = '0020000000'.

*lwa_ar-profit_ctr = '0000000217'.

*APPEND lwa_ar TO lt_ar.

lwa_curr-itemno_acc = '0000000001'.

lwa_curr-curr_type = '00'.

lwa_curr-currency = 'USD'.

lwa_curr-amt_base = '100.00'.

APPEND lwa_curr TO lt_curr.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = lwa_header

TABLES

accountgl = it_accountgl

accountreceivable = lt_ar

currencyamount = lt_curr

return = lt_return.

COMMIT WORK.

DATA: bt_return LIKE bapiret2.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = bt_return.

LOOP AT lt_return INTO lwa_return.

WRITE: / lwa_return-message.

ENDLOOP.

18 REPLIES 18

Former Member
5,336

Hi,

Check, are you passing all the parameters.


 CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      DOCUMENTHEADER    = DOC_HEADER
    IMPORTING
      OBJ_KEY           = OBJTYP
    TABLES
      ACCOUNTGL         = DOC_ITEM
      ACCOUNTRECEIVABLE = CUSTOMER
      ACCOUNTPAYABLE    = VENDOR
      CURRENCYAMOUNT    = DOC_VALUES
      RETURN            = RETURN.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      IMPORTING
        RETURN = RETURN.
    COMMIT WORK AND WAIT.

Thanks,

Krishna..

0 Kudos
5,336

Hi Krishna,

Can you ples let me know how you are filling the parameters which you pass into the BAPI.

regards

avi

0 Kudos
5,336

Check this sample program.

ACC_BAPI_TEST_DOCUMENT

Former Member
0 Kudos
5,336

Hi,

Use parameter WAIT in BAPI_TRANSACTION_COMMIT as follows:-

DATA:wa_return TYPE BAPIRET2.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = wa_return.

anusurbab
Explorer
0 Kudos
5,336

Hi,

use BAPI_TRANSACTION_COMMIT after BAPI_ACC_DOCUMENT_POST call was successful to commit changes to database.

RahulKeshav
Active Contributor
0 Kudos
5,336

Hi Avi,

As u r getting sucess message in return table, it means values passed to the BAPI perameters are fine.

just use commit as..

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'. thats it

Thnx

RK

0 Kudos
5,336

Hi,

As you can see in my code , I have tried that as well using BAPI TRANSACTION COMMIT Still its not happening

0 Kudos
5,336

data: l_obj_type LIKE bapiache08-obj_type,

l_obj_key LIKE bapiache02-obj_key,

l_obj_sys LIKE bapiache02-obj_sys.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = l_doc_header

IMPORTING

obj_type = l_obj_type

obj_key = l_obj_key

obj_sys = l_obj_sys

TABLES

accountgl = lt_doc_item

currencyamount = lt_doc_values

return = lt_return

extension1 = lt_extension1.

try to get the import parameters as well.

I used the same way for FB01 number of times and it is working fine for me..

Please check...

Thanks

RK

0 Kudos
5,336

Hi,

Did you try using the parameter with WAIT = X.

That will surely work.

Regards,

Subhashini

0 Kudos
5,336

Hi rahul,

Did you pass any values in Import parameters?

Or else

Can you please paste your code here on how you filled the Bapi import and export parameters

Regards

Avi

0 Kudos
5,336

no i didnt ...its an import parameter...it only gives the value.....

one more thing.....

after seeing your code....

in header ...u r passing posting/documnet date as 02 11 2009 and fiscal period as 06....

how can that be possible...

check it.....

fiscal period should be 11 if ur date format is ddmmyyyy.

same for fiscal year .....

Please correct....

Edited by: Rahul Keshav on Nov 3, 2009 6:25 PM

0 Kudos
5,336

if answered please close the thread...

RahulKeshav
Active Contributor
0 Kudos
5,336

try to use .....

l_doc_header-bus_act = 'RFBU'. replace BKPF with RFBU

and also try to pass Business area or costcenter depending on the account type....

Edited by: Rahul Keshav on Nov 3, 2009 6:36 PM

former_member206396
Active Participant
0 Kudos
5,336

Avi,

Please check the document its been posting in 2010 fisical year. Its not correct.

Please change the fisical year to 2009.

Hope it works.

Ram

former_member206632
Participant
0 Kudos
5,336

Hello, Avi

In fact I've came across the same problem: this is due to the fact that the BAPI issues a success message even when the FI document is not finantialy correct, like in your example.

It appears that you´re trying to post a debit of USD 100, but not the credit - you need at least item '0000000002' with USD -100 for the posting to be successful. Of course this is only an example - what I mean is that the sum of positive (debit) items should be equal to (minus the) sum of negative (credit) items:

Examples of correct debit/credit using:

USD 100

USD -100

or

USD 100

USD -30

USD -70

Regards,

Joã

Former Member
0 Kudos
5,336

Hi Avi

check this code may you get some hint

DATA gd_documentheader LIKE bapiache09.
DATA l_type            LIKE gd_documentheader-obj_type.
DATA l_key             LIKE gd_documentheader-obj_key.
DATA l_sys             LIKE gd_documentheader-obj_sys.
DATA it_accountgl      LIKE TABLE OF bapiacgl09 WITH HEADER LINE.
DATA it_currencyamount LIKE TABLE OF bapiaccr09 WITH HEADER LINE.
DATA it_return         LIKE TABLE OF bapiret2   WITH HEADER LINE.
DATA it_return1        LIKE TABLE OF bapiret2   WITH HEADER LINE.

gd_documentheader-username   = sy-uname.
gd_documentheader-header_txt = 'BAPI Test'.
gd_documentheader-comp_code  =  'RS01'.
gd_documentheader-fisc_year  = '2008'.
*gd_documentheader-doc_date   = '0'.
*gd_documentheader-pstng_date = sy-datum.
gd_documentheader-bus_act    = 'RMRP'.
gd_documentheader-fis_period = '11'.
gd_documentheader-doc_type = 'DW'.

CLEAR it_accountgl.
it_accountgl-itemno_acc     = 1.
it_accountgl-gl_account     = '0011500000'.
it_accountgl-tax_code       = 'V0'.
it_accountgl-item_text      = 'BAPI Test G/L line item'.
it_accountgl-customer       = 'AG0460'.
*it_accountgl-profit_ctr     = '0000002002'.
it_accountgl-de_cre_ind     = 'H'.
it_accountgl-comp_code      = 'RS01'.
it_accountgl-doc_type       = 'DR'.
*it_accountgl-fis_period     = '06'.
*it_accountgl-fisc_year      = '2009'.
it_accountgl-pstng_date     = sy-datum.
APPEND it_accountgl.

CLEAR it_currencyamount.
it_currencyamount-itemno_acc   = 1.
it_currencyamount-curr_type    = '00'.
it_currencyamount-currency     = 'INR'.
it_currencyamount-amt_base     = '100'.
APPEND it_currencyamount.

CLEAR it_currencyamount.
it_currencyamount-itemno_acc   = 2.
it_currencyamount-curr_type    = '00'.
it_currencyamount-currency     = 'INR'.
it_currencyamount-amt_base     = '100'.
APPEND it_currencyamount.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
    documentheader = gd_documentheader
  IMPORTING
    obj_type       = l_type
    obj_key        = l_key
    obj_sys        = l_sys
  TABLES
    accountgl      = it_accountgl
    currencyamount = it_currencyamount
    return         = it_return.

WAIT UP TO 10 SECONDS.

IF sy-subrc IS INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      wait = 'X'.
ENDIF.

Regards

Nilesh

0 Kudos
5,336

You have the data in append, how do I place that data by loading an excel file Thank

Former Member
0 Kudos
5,336

Answered