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 for FB08 (Reverse Document)

Former Member
0 Kudos

hi guys,,

I have an requirement to reverse the existing document which was created by BAPI not FB01 or FB50

I found the following BAPI for FB08

BAPI_ACC_BILLING_REV_POST

BAPI_ACC_GL_POSTING_REV_POST

BAPI_ACC_INVOICE_REV_POST

BAPI_ACC_DOCUMENT_REV_POST

But above all BAPI are giving some errors and not allow to reverse the documents.

but while using the FB08 it is enough to pass the douc no, comp code, year and reason for revers so its simple to reverse while come to BAPIs all required the other inofr like logical sys name, object key,etc.

can any body send the exact BAPI, and what r all parameters necessary to pass them if possible plase send the sample code which is very helpful to me.

Rewad for useful reply......

urs

Vijay

2 REPLIES 2

Former Member
0 Kudos

Hi,

I am facing the same issue while try to reverse the posted document.

Former Member
0 Kudos

Hi Vijay,

          With BAPI_ACC_DOCUMENT_POST to be reversed in the normal way in SAP (FB08) you must set the parameters OBJ_KEY, OBJ_SYS and OBJ_TYPE to BLANK when executing the BAPI_ACC_DOCUMENT_POST to create the document. This allows SAP to fill the return fields from the BAPI and so allows the reversal. The return fields will have type as BKPFF, object key will be the SAP document and system will be the current SAP system.

Follow the Steps:

  • Create a Structure include the item number & the field you want to Transport.
  • Implement the BADI "ACC_DOCUMENT". Tcode SE19.

        Reference Transaction is "BKPFF"

        Implement the method: CHANGE

  • Now prepare the parameters for BAPI
  • Call BAPI at last

call function 'BAPI_ACC_DOCUMENT_POST'

  exporting

    documentheader    = wa_documentheader

*     CUSTOMERCPD       =

*     CONTRACTHEADER    =

  importing

    obj_type          = wa_obj-obj_type

    obj_key           = wa_obj-obj_key

    obj_sys           = wa_obj-obj_sys

  tables

    accountgl         = it_accountgl

    accountreceivable = it_accountreceivable

*     ACCOUNTPAYABLE    =

*     ACCOUNTTAX        =

    currencyamount    = it_currencyamount

    criteria          = it_criteria

    valuefield        = it_valuefield

*     EXTENSION1        =

    return            = it_return

*     PAYMENTCARD       =

*     CONTRACTITEM      =

    extension2        = it_extension2

*     REALESTATE        =

*     ACCOUNTWT         =

  .

read table it_return into wa_return with key type = 'E'.

if sy-subrc = 0.

  call function 'BAPI_TRANSACTION_ROLLBACK'.

  perform frm_message_display.

else.

  call function 'BAPI_TRANSACTION_COMMIT'

    exporting

      wait = 'X'.

  " Return the Accounting Document Number and Fiscal Year

  p_belnr = wa_obj-obj_key(10).

  p_gjahr = wa_obj-obj_key+14(4).

endif.

  • As for use "BAPI_ACC_DOCUMENT_REV_POST" to reverse document is more simpler. Get the object type and object key of reverse document from table BKPF .

wa_reversal-obj_type  = wa_bkpf-awtyp.

wa_reversal-obj_key   = wa_bkpf-awkey.

wa_reversal-obj_key_r = wa_bkpf-awkey.

wa_reversal-reason_rev = '04'.          " The reason code is required:

wa_reversal-pstng_date = sy-datum.          " The posting date is optional:

call function 'BAPI_ACC_DOCUMENT_REV_POST'

     exporting

       reversal = wa_reversal

       bus_act  = 'RFBU'

     importing

       obj_type = wa_obj-obj_type

       obj_key  = wa_obj-obj_key

       obj_sys  = wa_obj-obj_sys

     tables

       return   = it_return.

   read table it_return into wa_return with key type = 'E'.

   if sy-subrc = 0.

     call function 'BAPI_TRANSACTION_ROLLBACK'.

   else.

     call function 'BAPI_TRANSACTION_COMMIT'

       exporting

         wait = 'X'.

     g_suc = 'X'.

   endif.

     Hope this Sample Code  is usefull.

Regards,

Surya