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: 

Problems with 'BAPI_ACC_DOCUMENT_POST'

Former Member
0 Kudos

Hi there !!

I got this problem , from a report I need to simulate the FB01 transactio to crate a document, I tried the 2 bapi

'BAPI_ACC_DOCUMENT_POST'

'BAPI_ACC_GL_POSTING_POST'

but seems that there is some problem and no documents aer created , can someone help me ,

After the bapi's launch in the return table I found this 2 lines of errors:

E - RW - 609 - Error in document: BKPFF 164356

E - F5 - 702 - Balance in transaction currency

**********************************************************

  • THIS THE SOURCE CODE

**********************************************************

data: tb_header like bapiache09 occurs 0 with header line,

tb_return like bapiret2 occurs 0 with header line,

tb_camount like bapiaccr09 occurs 0 with header line,

tb_account like bapiacgl09 occurs 0 with header line.

      • header

move: 'D1' to tb_header-doc_type,

'BKPFF' to tb_header-obj_type,

sy-uzeit to tb_header-obj_key,

sy-datum to tb_header-doc_date,

'XXXX' to tb_header-comp_code,

sy-uname to tb_header-username,

'RFBU' to tb_header-bus_act,

sy-datum to tb_header-pstng_date .

append tb_header.

***

      • amount

move: 1 to tb_camount-itemno_acc,

"my_amount" to tb_camount-amt_doccur,

'EUR' to tb_camount-currency.

append tb_camount. clear tb_camount.

*

move: 2 to tb_camount-itemno_acc,

"my_amount" to tb_camount-amt_doccur,

'EUR' to tb_camount-currency.

append tb_camount.clear tb_camount.

***

      • Item

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = pr_hkonp

importing

output = tb_account-gl_account.

move: 1 to tb_account-itemno_acc,

sy-datum to tb_account-pstng_date,

'40' to tb_account-acttype.

append tb_account.clear tb_account.

*

call function 'CONVERSION_EXIT_ALPHA_INPUT'

exporting

input = pr_hkonr

importing

output = tb_account-gl_account.

***

move: 2 to tb_account-itemno_acc,

pr_hkonr to tb_account-gl_account,

sy-datum to tb_account-pstng_date,

pr_aufnr to tb_account-orderid,

'50' to tb_account-acttype.

append tb_account.clear tb_account.

*

call function 'BAPI_ACC_DOCUMENT_POST'

exporting

documentheader = tb_header

importing

obj_type = va_obj_type

obj_key = va_obj_key

tables

accountgl = tb_account

currencyamount = tb_camount

return = tb_return.

*

if va_obj_key ne '$'.

call function 'BAPI_TRANSACTION_COMMIT'

importing

return = return.

endif.

*

9 REPLIES 9

Former Member
0 Kudos

Hi Pino,

Looking at the long text of your error, ot seems that your line items don't balance. Have you double checked your ACCOUNTGL and CURRENCYAMOUNT parameters?

Brad

0 Kudos

I think Brad is right.

A working test program will give you some idea.

Then you can take it from there .

Thanks,

Ram

report z_test_bapi_gl_ac_doc LINE-SIZE 200.

data:

obj_type like bapiache02-obj_type,

obj_key like bapiache02-obj_key,

obj_sys like bapiache02-obj_sys,

documentheader like bapiache08,

accountgl like bapiacgl08

occurs 0 with header line,

currencyamount like bapiaccr08

occurs 0 with header line,

return like bapiret2

occurs 0 with header line,

extension1 like bapiextc

occurs 0 with header line,

t_edidd like edidd occurs 0 with header line,

bapi_retn_info like bapiret2 occurs 0 with header line.

data: error_flag.

*documentheader-obj_type = 'BKPFF'.

*documentheader-obj_key = '18000000002002004'.

*documentheader-obj_type = 'BKPFF'.

*documentheader-obj_key = '180000000010002004'.

*documentheader-obj_sys = 'RD1CLNT200'.

documentheader-username = sy-uname.

documentheader-header_txt = 'Test using BAPI'.

documentheader-comp_code = '1000'.

*documentheader-ac_doc_no

*documentheader-fisc_year = '2005'.

documentheader-doc_date = sy-datum.

documentheader-pstng_date = sy-datum.

documentheader-doc_type = 'SA'.

*documentheader-ref_doc_no

*documentheader-compo_acc

*documentheader-reason_rev

accountgl-itemno_acc = '1'.

accountgl-gl_account = '0000160100'.

accountgl-comp_code = '1000'.

accountgl-pstng_date = sy-datum.

accountgl-doc_type = 'SA'.

accountgl-profit_ctr = '0000010000'.

append accountgl.

accountgl-itemno_acc = '2'.

accountgl-gl_account = '0000160100'.

accountgl-comp_code = '1000'.

accountgl-pstng_date = sy-datum.

accountgl-doc_type = 'SA'.

accountgl-profit_ctr = '0000010000'.

append accountgl.

currencyamount-itemno_acc = '1'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = '100.00'.

append currencyamount.

currencyamount-itemno_acc = '2'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = '-100.00'.

append currencyamount.

  • call BAPI-function in this system

call function 'BAPI_ACC_GL_POSTING_POST'

exporting

documentheader = documentheader

  • importing

  • obj_type = obj_type

  • obj_key = obj_key

  • obj_sys = obj_sys

tables

accountgl = accountgl

currencyamount = currencyamount

return = return

extension1 = extension1

exceptions

others = 1.

if sy-subrc <> 0.

message e999(re) with 'Problem occured'.

else.

loop at return.

if not return is initial.

clear bapi_retn_info.

move-corresponding return to bapi_retn_info.

if return-type = 'A' or return-type = 'E'.

error_flag = 'X'.

endif.

append bapi_retn_info.

endif.

endloop.

if error_flag = 'X'.

message e999(re) with 'Problem occured'.

rollback work.

else.

commit work.

endif.

endif.

0 Kudos

Thank you all for the answer the problem was on the amount , I thought that the item field tb_account-acttype was referred to the posting key and so the sign of the amount.

Now the bapi create the document and I'd like to have another info about the document number, I noted that the ones created by the 'FB01' have 10 digits numbers (like this "0100000006") while the documents created by my program are only 6 digit long ("101850") what I must change to my code to use the "standard" numeration range ?

0 Kudos

Hi Pino,

try that :

PERFORM ALPHAFORMAT(SAPFS000) USING belnr belnr.

regards Andreas

0 Kudos

Hi Pino,

Are you sure its not a 10 digit number? Maybe the L_OBJ_KEY parameter returns it like "101850", but in the database its "0000101850".

Refer the following thread:

If you don't pass an accounting document number it will generate one from the internal number range. This should be the same range as other accounting documents.

Cheers,

Brad

0 Kudos

thank you but my problem is that I'd like an assignment related to to the document type range managed by the bapi and not a format conversion.

0 Kudos

Hi Pino,

i do'nt understand the problem:

you can check the number range with ta's <b>OBA7</b> (doc-types)

and <b>FBN1</b> (number range)

regards Andreas

0 Kudos

Thanks Brad in the discussion there was a relation to a note that solved my problem

0 Kudos

Hi Pino,

Can you please close the thread then.

Just click on either "Solved problem" next to one of the responses, or "Solved it on my own" next to your original post.

Cheers,

Brad