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_ACC_DOCUMENT_POST - Clearing not happening.

Former Member
0 Likes
6,893

Hi Team,

I am trying to post accounting entry followed by clearing of the same ( in ref to FB05 )  using BAPI_ACC_DOCUMENT_POST.

My FI document get posted successfully and is also visible as required but, the clearing is not happening.

I searched alot for this combined activity and found the above BAPI suitable, but it seems some where i am missing something for getting clearing done.

I don't wont to write a BDC for F-03 (clearing). Can posting & clearing both be feasible by BAPI_ACC_DOCUMENT_POST.

Please find my code below and share your inputs.

wa_doc-obj_type = 'BKPFF'.

CONCATENATE '00' wa_outc-belnr INTO wa_doc-obj_key+0(12).

wa_doc-obj_key+10(4) = wa_outc-bukrs.

wa_doc-obj_key+14(4) = wa_outc-gjahr.

wa_doc-obj_key = '$'.

wa_doc-bus_act = 'RFBU'.

CONCATENATE sy-sysid 'CLNT' sy-mandt

             INTO wa_doc-obj_sys.

wa_doc-username = sy-uname.

wa_doc-header_txt = 'HEADER'.

wa_doc-comp_code = wa_outc-bukrs.

wa_doc-fisc_year = wa_outc-gjahr.

wa_doc-doc_date = sy-datum.

wa_doc-pstng_date = lv_budat.

wa_doc-doc_type = 'SA'.

CONCATENATE wa_outc-belnr wa_outc-gjahr INTO wa_doc-ref_doc_no.

wa_doc-fis_period = lv_monat.

wa_accgl-itemno_acc = '1'.

wa_accgl-gl_account = wa_outc-tkont.

wa_accgl-comp_code = wa_outc-bukrs.

wa_accgl-pstng_date = lv_budat.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-zmwsk.

wa_accgl-fis_period = lv_monat.

wa_accgl-fisc_year = wa_outc-gjahr.

wa_accgl-profit_ctr = '0000601000'.

APPEND wa_accgl TO it_accgl.

wa_accgl-itemno_acc = '2'.

wa_accgl-gl_account = wa_outc-dhkont.

wa_accgl-comp_code = wa_outc-bukrs.

wa_accgl-pstng_date = lv_budat.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-mwskz.

wa_accgl-fis_period = lv_monat.

wa_accgl-fisc_year = wa_outc-gjahr.

wa_accgl-profit_ctr = '0000601000'.

APPEND wa_accgl TO it_accgl.

wa_curr-itemno_acc = '1'.

wa_curr-curr_type  = '00'.

wa_curr-currency_iso = wa_outc-hwaer.

wa_curr-amt_doccur = wa_outc-hteis.

APPEND wa_curr TO it_curr.

wa_curr-itemno_acc = '2'.

wa_curr-curr_type  = '00'.

wa_curr-currency_iso = wa_outc-hwaer.

wa_curr-amt_doccur = wa_outc-hteis * -1.

APPEND wa_curr TO it_curr.

BREAK-POINT.

CLEAR : wa_obj_type, wa_obj_key, wa_obj_sys.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

   EXPORTING

     documentheader = wa_doc

   IMPORTING

     obj_type       = wa_obj_type

     obj_key        = wa_obj_key

     obj_sys        = wa_obj_sys

   TABLES

     accountgl      = it_accgl

     currencyamount = it_curr

     return         = it_return.

LOOP AT it_return INTO wa_return.

   WRITE: / wa_return-type,

          wa_return-id(5),

          wa_return-number,

          wa_return-message(120),

          ' Ligne : ',wa_return-row.

   IF wa_return-type = 'S'.

     COMMIT WORK.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

   ENDIF.

   CLEAR : wa_return.

ENDLOOP.

Regards,

Anmol Saxena.

1 ACCEPTED SOLUTION
Read only

VijayCR
Active Contributor
0 Likes
4,418

Hello Anmol,

Can you look at the error messege it_return provided by BAPI? Can you tell me if there is any error messege for this or its not getting posted with out errors?

Thanks ,

Vijay.

Hi Team,

I am trying to post accounting entry followed by clearing of the same ( in ref to FB05 )  using BAPI_ACC_DOCUMENT_POST.

My FI document get posted successfully and is also visible as required but, the clearing is not happening.

I searched alot for this combined activity and found the above BAPI suitable, but it seems some where i am missing something for getting clearing done.

I don't wont to write a BDC for F-03 (clearing). Can posting & clearing both be feasible by BAPI_ACC_DOCUMENT_POST.

Please find my code below and share your inputs.

wa_doc-obj_type = 'BKPFF'.

CONCATENATE '00' wa_outc-belnr INTO wa_doc-obj_key+0(12).

wa_doc-obj_key+10(4) = wa_outc-bukrs.

wa_doc-obj_key+14(4) = wa_outc-gjahr.

wa_doc-obj_key = '$'.

wa_doc-bus_act = 'RFBU'.

CONCATENATE sy-sysid 'CLNT' sy-mandt

             INTO wa_doc-obj_sys.

wa_doc-username = sy-uname.

wa_doc-header_txt = 'HEADER'.

wa_doc-comp_code = wa_outc-bukrs.

wa_doc-fisc_year = wa_outc-gjahr.

wa_doc-doc_date = sy-datum.

wa_doc-pstng_date = lv_budat.

wa_doc-doc_type = 'SA'.

CONCATENATE wa_outc-belnr wa_outc-gjahr INTO wa_doc-ref_doc_no.

wa_doc-fis_period = lv_monat.

wa_accgl-itemno_acc = '1'.

wa_accgl-gl_account = wa_outc-tkont.

wa_accgl-comp_code = wa_outc-bukrs.

wa_accgl-pstng_date = lv_budat.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-zmwsk.

wa_accgl-fis_period = lv_monat.

wa_accgl-fisc_year = wa_outc-gjahr.

wa_accgl-profit_ctr = '0000601000'.

APPEND wa_accgl TO it_accgl.

wa_accgl-itemno_acc = '2'.

wa_accgl-gl_account = wa_outc-dhkont.

wa_accgl-comp_code = wa_outc-bukrs.

wa_accgl-pstng_date = lv_budat.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-mwskz.

wa_accgl-fis_period = lv_monat.

wa_accgl-fisc_year = wa_outc-gjahr.

wa_accgl-profit_ctr = '0000601000'.

APPEND wa_accgl TO it_accgl.

wa_curr-itemno_acc = '1'.

wa_curr-curr_type  = '00'.

wa_curr-currency_iso = wa_outc-hwaer.

wa_curr-amt_doccur = wa_outc-hteis.

APPEND wa_curr TO it_curr.

wa_curr-itemno_acc = '2'.

wa_curr-curr_type  = '00'.

wa_curr-currency_iso = wa_outc-hwaer.

wa_curr-amt_doccur = wa_outc-hteis * -1.

APPEND wa_curr TO it_curr.

BREAK-POINT.

CLEAR : wa_obj_type, wa_obj_key, wa_obj_sys.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

   EXPORTING

     documentheader = wa_doc

   IMPORTING

     obj_type       = wa_obj_type

     obj_key        = wa_obj_key

     obj_sys        = wa_obj_sys

   TABLES

     accountgl      = it_accgl

     currencyamount = it_curr

     return         = it_return.

LOOP AT it_return INTO wa_return.

   WRITE: / wa_return-type,

          wa_return-id(5),

          wa_return-number,

          wa_return-message(120),

          ' Ligne : ',wa_return-row.

   IF wa_return-type = 'S'.

     COMMIT WORK.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

   ENDIF.

   CLEAR : wa_return.

ENDLOOP.

Regards,

Anmol Saxena.

5 REPLIES 5
Read only

Former Member
0 Likes
4,418

Dear Anmol,

Please check this link.

http://scn.sap.com/thread/1898646

Regards,

Amit

Read only

VijayCR
Active Contributor
0 Likes
4,419

Hello Anmol,

Can you look at the error messege it_return provided by BAPI? Can you tell me if there is any error messege for this or its not getting posted with out errors?

Thanks ,

Vijay.

Read only

Former Member
0 Likes
4,418

Hi Vijay,

Thanks for your reply.

I am looking into the URL http://scn.sap.com/thread/1898646.

Whereas, there is not error reported by the BAPI post execution, only the new accounting document number gets reflected.

Is the BAPI_ACC_DOCUMENT_POST sufficient for Account Posting and Clearing..??

Regards,

Anmol Saxena.

Read only

VijayCR
Active Contributor
0 Likes
4,418

Hello Anmol,

Please try Call Tranaction FB05 instead of that hope this shuld since the BAPI is used only to post not to  clear .

Thanks,

Vijay.

Read only

Former Member
0 Likes
4,418

Hi Vijay,

I managed my issue in the below mentioned fashion.

loop at .....

CLEAR: wa_doc.

wa_doc-obj_type = 'BKPFF'.

CONCATENATE '00' wa_outc-belnr INTO wa_doc-obj_key+0(12).

wa_doc-obj_key+10(4) = wa_outc-bukrs.

wa_doc-obj_key+14(4) = wa_outc-gjahr.

wa_doc-obj_key = '$'."sy-uzeit.

wa_doc-bus_act = 'RFBU'.

CONCATENATE sy-sysid 'CLNT' sy-mandt

             INTO wa_doc-obj_sys.

wa_doc-username = sy-uname.

wa_doc-header_txt = 'HEADER'.

wa_doc-comp_code = wa_outc-bukrs.                           "'1000'.

wa_doc-fisc_year = wa_outc-gjahr.                           "'2011'.

wa_doc-doc_date = sy-datum.

wa_doc-pstng_date = lv_budat."sy-datum.

wa_doc-doc_type = 'SA'."wa_outc-blart."'SA'.

CONCATENATE wa_outc-belnr wa_outc-gjahr INTO wa_doc-ref_doc_no.

wa_doc-fis_period = lv_monat."sy-datum+4(2)."wa_outc-monat.             "'09'.

wa_accgl-itemno_acc = '1'.

wa_accgl-gl_account = wa_outc-tkont."'0000470000'.

wa_accgl-comp_code = wa_outc-bukrs.                         "'1000'.

wa_accgl-pstng_date = lv_budat."sy-datum.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-zmwsk.                          "'0I'.

wa_accgl-fis_period = lv_monat."sy-datum+4(2)."wa_outc-monat.           "'0I'.

wa_accgl-fisc_year = wa_outc-gjahr.                         "'0I'.

wa_accgl-profit_ctr = '0000601000'."wa_outc-gjahr.             "'0I'.

CONCATENATE wa_outc-belnr wa_outc-gjahr INTO wa_accgl-alloc_nmbr.

APPEND wa_accgl TO it_accgl.

wa_accgl-itemno_acc = '2'.

wa_accgl-gl_account = wa_outc-dhkont."'0000470000'.

wa_accgl-comp_code = wa_outc-bukrs.                         "'6000'.

wa_accgl-pstng_date = lv_budat."sy-datum.

wa_accgl-item_text = 'item text'.

wa_accgl-tax_code = wa_outc-mwskz.                          "'0I'.

wa_accgl-fis_period = lv_monat."sy-datum+4(2)."wa_outc-monat.           "'0I'.

wa_accgl-fisc_year = wa_outc-gjahr.                         "'0I'.

wa_accgl-profit_ctr = '0000601000'."wa_outc-gjahr.             "'0I'.

CONCATENATE wa_outc-belnr wa_outc-gjahr INTO wa_accgl-alloc_nmbr.

APPEND wa_accgl TO it_accgl.

wa_curr-itemno_acc = '1'.

wa_curr-curr_type  = '00'.    "  00  = TRAN curr     10 = DI

wa_curr-currency_iso = wa_outc-hwaer."'USD'.

wa_curr-amt_doccur = wa_outc-hteis." * -1.            "'-100.00'.

APPEND wa_curr TO it_curr.

wa_curr-itemno_acc = '2'.

wa_curr-curr_type  = '00'.    "  00  = TRAN curr     10 = DI

wa_curr-currency_iso = wa_outc-hwaer."'USD'.

wa_curr-amt_doccur = wa_outc-hteis * -1.                    "'-100.00'.

APPEND wa_curr TO it_curr.

CLEAR : wa_obj_type, wa_obj_key, wa_obj_sys.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

   EXPORTING

     documentheader = wa_doc

   IMPORTING

     obj_type       = wa_obj_type

     obj_key        = wa_obj_key

     obj_sys        = wa_obj_sys

   TABLES

     accountgl      = it_accgl

     currencyamount = it_curr

     return         = it_return.

LOOP AT it_return INTO wa_return.

   WRITE: / wa_return-type,

          wa_return-id(5),

          wa_return-number,

          wa_return-message(120),

          ' Ligne : ',wa_return-row.

   IF wa_return-type = 'S'.

     COMMIT WORK.

     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

     CLEAR : wa_accgl, lv_date, gt_bdcdata[].

     READ TABLE it_accgl INTO wa_accgl INDEX '2'.

     MOVE : sy-datum TO lv_date.

     CALL FUNCTION '/SAPDII/SPP05_CONVERT_DATE'

       EXPORTING

         if_date = lv_date

       IMPORTING

         ef_date = lv_date.

     CLEAR : r_gjahr, r_zuonr, r_hkont.

     r_gjahr-sign = 'I'.

     r_gjahr-option = 'EQ'.

     r_gjahr-low = wa_doc-fisc_year.

     APPEND r_gjahr TO r_gjahr.

     r_zuonr-sign = 'I'.

     r_zuonr-option = 'EQ'.

     r_zuonr-low = wa_accgl-alloc_nmbr.

     APPEND r_zuonr TO r_zuonr.

     r_hkont-sign = 'I'.

     r_hkont-option = 'EQ'.

     r_hkont-low = wa_accgl-gl_account.

     APPEND r_hkont TO r_hkont.

     CLEAR : r_gjahr, r_zuonr, r_hkont.

   ENDIF.

   CLEAR : wa_return.

ENDLOOP.

CLEAR : wa_doc, it_accgl[], it_curr[], it_return[].

CLEAR : wa_outc.

ENDLOOP.

SUBMIT zas_lo_sapf124 AND RETURN USING SELECTION-SCREEN '1000'

      WITH bukrx    EQ '6000'

      WITH gjahx    IN r_gjahr" wa_doc-fisc_year

      WITH so_zuonr IN r_zuonr" wa_accgl-alloc_nmbr "r_zuonr" 12220000822013

      WITH x_saknr  EQ 'X'

      WITH konts    IN r_hkont" wa_accgl-gl_account "r_konts

      WITH x_testl  EQ ' '

      WITH xausbel  EQ 'X'

      WITH xnausbel EQ 'X'

      WITH xnausbel EQ 'X'

      WITH x_fehler EQ 'X'.

endloop.

'zas_lo_sapf124' is a program copy of sapf124 which supresses the warning raised while execution of sapf124 for informing that it is a production run.

This worked for me, thus closing the thread.

Regards,
Anmol Saxena.