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 Posting

Former Member
0 Likes
496

How Do Everyone!

I am writing a program to post documents held in an internal table using the BAPI

'BAPI_ACC_GL_POSTING_POST'.

For each row in the internal table I call the above BAPI followed by BAPI_TRANSACTION_COMMIT.

Everything is working fine for the first row only. i.e. There are 10 rows in the table and only 9

documents are being posted.

Is there anything I need to do after the BAPI_TRANSACTION_COMMIT?

Should I be calling BAPI_TRANSACTION_COMMIT after every row ? or just the once

at the end of the program?

Any help much appreciated

Thanks

Andy

3 REPLIES 3
Read only

Former Member
0 Likes
472

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = wa_account_header

TABLES

accountgl = it_accountgl

accountpayable = it_account_pay

currencyamount = it_currency_amount

return = it_bapi_return.

CLEAR v_lineitem.

v_lineitem = 1.

LOOP AT it_bapi_return INTO wa_type_bapi_return.

--


To Save Success Record Through BAPI Commit--

IF wa_type_bapi_return-type = c_suc .''if it is success

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ENDIF.

ENDLOOP .

Read only

Former Member
0 Likes
472

Hi Andy

can you paste the LOOP code of yours.

ideally all records should be committed. I guess there will be some logical mistake in your code.

check the conditions where in you are calling the TRANSACTION COMMIT bapi

Cheers

~Arun

Read only

0 Likes
472

Many thanks Arun for replying. Sorry I have taken a few days to reply.

Here is my code:

CLEAR: documentheader,

accountgl,

currencyamount.

documentheader-obj_type = 'BKPFF'.

documentheader-obj_key = '$'.

documentheader-obj_sys = sy-host.

documentheader-username = sy-uname.

documentheader-header_txt = invoice_wa-header_text.

documentheader-comp_code = invoice_wa-company_code.

documentheader-doc_date = invoice_wa-document_date.

documentheader-pstng_date = sy-datum.

documentheader-doc_type = pa_type. " Select Screen Document Type

documentheader-ref_doc_no = invoice_wa-reference.

  • For some reason we have to enter line 2 before line 1 ??

  • Credit - Posting Key 50

accountgl-itemno_acc = '2'.

accountgl-gl_account = pa_gl.

accountgl-pstng_date = sy-datum.

APPEND accountgl.

  • Debit - Posting Key 40

accountgl-itemno_acc = '1'.

accountgl-gl_account = invoice_wa-gl_code.

accountgl-costcenter = invoice_wa-cost_centre.

accountgl-item_text = invoice_wa-text.

accountgl-pstng_date = sy-datum.

APPEND accountgl.

  • Debit - Posting Key 40

currencyamount-itemno_acc = '1'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = invoice_wa-net_trans_amount.

APPEND currencyamount.

  • Credit - Posting Key 50

currencyamount-itemno_acc = '2'.

currencyamount-currency = 'GBP'.

currencyamount-amt_doccur = invoice_wa-net_trans_amount.

MULTIPLY currencyamount-amt_doccur BY -1.

APPEND currencyamount.

  • Call BAPI-function to Posty the Document

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.

CONCATENATE 'Document Posted Successfully : ' return-message_v2(+10)

INTO invoice_wa-line.

invoice_wa-document_no = return-message_v2(+10).

wa_num_of_posted_documents = wa_num_of_posted_documents + 1.

wa_total_net_amount = wa_total_net_amount + invoice_wa-net_trans_amount.

CLEAR return.

REFRESH return.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

IMPORTING

return = return.

ENDIF.

----


  • Update Internal Table

----


*

MODIFY invoice_tab FROM invoice_wa.

ENDLOOP.

IF sy-subrc <> 0.

MOVE-CORRESPONDING return TO bapi_retn_info.

invoice_wa-error_ind = 'Y'.

invoice_wa-line = bapi_retn_info-message.

invoice_wa-document_no = bapi_retn_info-message_v2.

ROLLBACK WORK.

ELSE.

COMMIT WORK.

ENDIF.