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_REV_POST Need info and example would be great

Former Member
0 Likes
24,701

Please bear with me if I don't describe certain aspects of my question correctly as I am new to FI, ABAP, and the document concept.

We post a document into the GL once a month with BAPI_ACC_DOCUMENT_POST. This document may contain 500 line items. It is my understanding that a Document contains a list of items to post to the GL. Sometimes a mistake is made and the document needs to be reversed. Since this posted with an IDOC, you can't reverse using FB08. It must be reversed with another IDOC. So I want to reverse the document with another program that I will create.

I see the record of the document I want to reverse in table BKPF.

I see the following parameters are required to fire off this BAPI:

Parameters
REVERSAL
BUS_ACT
OBJ_TYPE
OBJ_KEY
OBJ_SYS
RETURN

I am looking for as much information on this as possible. I only need to reverse 1 document and it has about 500 line items in it. Do you call the bapi for each line in the document or do you call the bapi one time and it will reverse each of the line items in the document?

Also, I have to ask: I did a search for this BAPI and many people say check the documentation for info and examples as if the documentation has actual examples. The documentation for this appears very limited to me and I don't see a single example. Am I missing something? Is there some place in the documentation that actually has a complete example?

I am hoping someone can post a good example or some very good detailed information on how to use this FM.

Thanks!

25 REPLIES 25
Read only

Abhijit74
Active Contributor
15,015

Hello,


For your case i think the good example is standard report ACC_BAPI_TEST_DOCUMENT. Please check it.


Thanks & Regards,


Abhijit

Read only

Former Member
0 Likes
15,015

I will give this a try and report back. Thank you for the information. Is there a certain section within SAP that has all of the examples that I can browse or something? I mean how did you know that example existed?

Read only

Former Member
0 Likes
15,015

Where-used list can be used to see which programs are calling a particular FM. Some program names indicate that they are test or demo programs.

Read only

Abhijit74
Active Contributor
0 Likes
15,015

Yeah..I agree with Manish...

Read only

Former Member
0 Likes
15,015

Please also refer the below links:

    Reversing a document using the bapi 'BAPI_ACC_D... | SCN

Read only

Former Member
0 Likes
15,015

Hello Richard,

Pass the following Parameters to the FM ' BAPI_ACC_DOCUMENT_REV_POST'.

Code Snippet :

        reversal-reason_rev = '02'.( Pass any valid Value based on your requirement)

         reversal-pstng_date = sy-datum.

CONCATENATE bkpf-belnr bkpf--bukrs bkpf--gjahr  INTO lw_reversal-obj_key.

      reversal-obj_sys = Logic system

       reversal-obj_type = ' BKPFF'.

       reversal-obj_key_r = reversal-obj_key.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'

         EXPORTING

           reversal = reversal

           bus_act  = 'RFBU'

         TABLES

           return   = lt_return.


       IF sy-subrc EQ 0.

       success

       else.

        populate error message.

endif.

Thanks,

Kishor.

Read only

0 Likes
15,015

Kishor, I will give it a try. The Logical System, what is that? Is that IDOC? Why is reversal-obj_type  BKPFF instead of BKPF? And why is bus_act RFBU? What is RFBU?

Read only

0 Likes
15,015

Hello Richard,

It's not IDOC. When data is distributed between different systems, each system within a network has to be clearly identifiable. The “logical system” deals with this issue.    

To get own logical system : use OWN_LOGICAL_SYSTEM_GET.

And BKPFF is the Business object.

I think it will be better if you consult with some ABAP guy.

Thanks & Regards,

Abhijit

Read only

0 Likes
15,015

I am the ABAP guy!!! This is how we learn. Thank you. When I am finsihed and have it working, I will post the code in case someone else needs to learn it too. Thanks again.

Read only

Former Member
0 Likes
15,015

Assuming the document number that I need to reverse is 123456. This document was posted with the BAPI for posting documents and is shown as an IDOC. Can anyone answer the individual areas below with literal terms?

The header is one area that don't have a solid understanding or explanation of. Here is what I have so far:

  gd_documentheader-obj_type   = 'IDOC'. - I think this is IDOC because the document I am reversing is an IDOC

  gd_documentheader-obj_key    =  - What do they expect here?

  gd_documentheader-username   = sy-uname. - I understand this

  gd_documentheader-header_txt = 'describe the reversal' - I understand this

* gd_documentheader-obj_key_r  = what do they expect here

* GD_DOCUMENTHEADER-reason_rev = '01' I understand this

  gd_documentheader-comp_code  = '1234'. I understand this

* GD_DOCUMENTHEADER-AC_DOC_NO  = Is this the document number of the one I want to reverse?

  gd_documentheader-fisc_year  = '2014'. - I understand this

  gd_documentheader-doc_date   = sy-datum. - I understand this

  gd_documentheader-pstng_date = sy-datum. I understsand this

* GD_DOCUMENTHEADER-TRANS_DATE = I think when I want this to be effective

* GD_DOCUMENTHEADER-VALUE_DATE = What do they expect here?

* GD_DOCUMENTHEADER-FIS_PERIOD = '01' I understand this

* GD_DOCUMENTHEADER-DOC_TYPE   = What do they expect here?

* GD_DOCUMENTHEADER-REF_DOC_NO = maybe this is the doc num of the one I want to reverse?

* GD_DOCUMENTHEADER-COMPO_ACC  = What do they want here?

  gd_documentheader-bus_act    = 'RFBU'. Original doc was posted here so I assume this will be the same

Read only

0 Likes
15,015

Hello,

Just follow the standard program I have mentioned.

Obj_key is the concatenation of all document number company code and year. But Put 'R' for reversal.

And the reverse key will also be the same like obj_key but do not add 'R'.

Left other field as it is.

Thanks & Regards,

Abhijit

Read only

0 Likes
15,015

Ok. I will try.

One more question, the original document that was posted had about 500 line items. When you run this reversal BAPI, it will reverse all of the items within that document or do you loop and run it 1 time for each of the items?

Thank you for the help and patience as I learn this!

Read only

0 Likes
15,015

Richard,

When you are reversing the A/C document,with the input of the Document Number, Company Code, Fiscal year as a combination in obj_key (which are key fields from BKPF, BSEG for Accounting document) the Program will automatically look for all the Line items associated with it & reverse at the document level.

I mean you dont need to loop items at all.

Read only

0 Likes
15,015

That's great. Thank you. It just dawned on me that they want the KEY...as in DB key fields...

I'll post back when I am done. Almost there. Thanks again.

Read only

0 Likes
15,015

Ok, guys I'm just about done. The reason I had so much confusion about this is because in the sample program, they want the header field populated as you see in my question above. They did this because the sample gives you options to post as well. For the reversal you don't need that much info. It is simpler than I was making it to be.

Abhijit, you say the following:

------------------------------------------------------

Obj_key is the concatenation of all document number company code and year. But Put 'R' for reversal.

And the reverse key will also be the same like obj_key but do not add 'R'.

------------------------------------------------------

So if the document that we are going to reverse has a document number of 12345 and we have a company code of 6789 and the fiscal year is 2014

REVERSAL-OBJ_KEY would be 1234567892014R

and

REVERSAL-OBJ_KEY_R would be 1234567892014

What is in REVERSAL-OBJ_KEY is what matches the field AWKEY in table BKPF and this is how the bapi knows which document to reverse.

Is that a correct statement?

Here is my second question:

Here are the parameters that the BAPI says it needs:

REVERSAL

BUS_ACT

OBJ_TYPE

OBJ_KEY

OBJ_SYS

RETURN

I have provided it the first two and I am going to use RETURN and I understand how it works.

Its the other three that I have a question on. Each of those three are already provided in REVERSAL. Do I need to provde them again with the call to the bapi? Remember that the document I am reversing was originally created with an IDOC. The documentation for OBJ_TYPE says this:

--------------------------------------------

When a business transaction is updated in Accounting, it may be that several

documents are updated at the same time (FI document, CO document, etc). If the

business transaction is not initiated in Accounting, a source document must

exist outside Accounting. The information from this document must be transferred

when the FI/CO interface is called up. The source information is updated in all

accounting documents, and is made up of the following fields:

--------------------------------------------

Thanks again.

Read only

Former Member
0 Likes
15,015

Ok guys. I finally got back on this.

Anyways, it's not working! When I run the code as shown below, I get the following message:

I thought you meant BKPF instead of BKPFF so I changed it and ran it as well, and in fact the error does change, slightly. Here is that error:

I tried it with object type IDOC and was given the same as the first error.

The program that does the original upload of data is bapi_acc_document_post. In that program they do the formula for the AWKEY a little different than what you guys said to use for OBJ_KEY so in order make sure I get the exact key that is used in AWKEY, I am grabbing it directly out of BKPF as you can see in my code below. Any idea why this is not working?

------------------------------------------------------------------------------------


REPORT REVERSE_posting .

SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE T_DOC.
PARAMETERS:
  P_docnum LIKE RF05A-BELNS,
  P_comp LIKE BKPF-BUKRS OBLIGATORY DEFAULT '4100',
  P_fiscyr LIKE BKPF-GJAHR OBLIGATORY DEFAULT '2014'.
SELECTION-SCREEN END   OF BLOCK bl01 .

SELECTION-SCREEN BEGIN OF BLOCK bl02 WITH FRAME TITLE T_REV.
  PARAMETERS:
  P_Date LIKE BSIS-BUDAT OBLIGATORY DEFAULT sy-datum,


START-OF-SELECTION.

TABLES: BKPF.


DATA: rev LIKE bapiacrev,
        orig_key LIKE bapiache01-obj_key,
        new_key LIKE orig_key,
        rflag(1) TYPE c value 'R',
        it_return            LIKE TABLE OF bapiret2   WITH HEADER LINE,
        logsys LIKE rev-obj_sys,
        gd_documentheader    LIKE bapiache09.


* Get the original reference key.
SELECT SINGLE AWKEY
    INTO orig_key
    FROM BKPF
    WHERE BELNR = P_docnum and BUKRS = P_comp and GJAHR = P_fiscyr.


  CONCATENATE orig_key rflag INTO new_key.

  CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'
    IMPORTING
      own_logical_system = logsys.

*Fill rev to pass to bapi
rev-obj_type  = 'BKPFF'.
rev-obj_key   = new_key.
rev-obj_sys   = logsys.
rev-obj_key_r = orig_key.
rev-pstng_date = P_Date.
rev-Reason_Rev = P_Reason.

      CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'
        EXPORTING
          reversal = rev
          bus_act  = 'RFBU'
        TABLES
          return   = it_return.

  WRITE: / 'Result of Reversal Posting:'.                   "#EC NOTEXT
  PERFORM show_messages.

COMMIT WORK.

FORM show_messages.

  IF it_return[] IS INITIAL.
    WRITE: / 'no messages'.
  ELSE.
    SKIP 1.
    LOOP AT it_return.
      WRITE: /    it_return-type,
             (2)  it_return-id,
             (80) it_return-message,
             (20) it_return-parameter,
             (3)  it_return-row,
                  it_return-field.
    ENDLOOP.
  ENDIF.

  ULINE.

ENDFORM.

Read only

0 Likes
15,015

Hello,

Check below. This will work I think.

REPORT REVERSE_posting .

TABLES: BKPF.

DATA: rev LIKE bapiacrev,

         orig_key LIKE bapiache01-obj_key,

         new_key LIKE orig_key,

         rflag(1) TYPE c value 'R',

         it_return            LIKE TABLE OF bapiret2   WITH HEADER LINE,

         logsys LIKE rev-obj_sys,

         gd_documentheader    LIKE bapiache09.

*REPORT REVERSE_posting .

SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE T_DOC.

PARAMETERS:

   P_docnum LIKE RF05A-BELNS,

   P_comp LIKE BKPF-BUKRS OBLIGATORY DEFAULT '1111',

   P_fiscyr LIKE BKPF-GJAHR OBLIGATORY DEFAULT '2014'.

SELECTION-SCREEN END   OF BLOCK bl01 .

SELECTION-SCREEN BEGIN OF BLOCK bl02 WITH FRAME TITLE T_REV.

PARAMETERS:

P_Date LIKE BSIS-BUDAT OBLIGATORY DEFAULT sy-datum.

SELECTION-SCREEN END OF BLOCK bl02.

START-OF-SELECTION.

* Get the original reference key.

*  SELECT SINGLE AWKEY

*      INTO orig_key

*      FROM BKPF

*      WHERE BELNR = P_docnum and BUKRS = P_comp and GJAHR = P_fiscyr.

 

   CONCATENATE p_comp p_docnum  p_fiscyr INTO orig_key.

   CONCATENATE rflag orig_key  INTO new_key.

   CALL FUNCTION 'OWN_LOGICAL_SYSTEM_GET'

     IMPORTING

       own_logical_system = logsys.

*Fill rev to pass to bapi

   rev-obj_type  = 'BKPFF'.

   rev-obj_key   = new_key.

   rev-obj_sys   = logsys.

   rev-obj_key_r = orig_key.

   rev-pstng_date = P_Date.

*  rev-Reason_Rev = P_Reason.

   CALL FUNCTION 'BAPI_ACC_DOCUMENT_REV_POST'

     EXPORTING

       reversal = rev

       bus_act  = 'RFBU'

     TABLES

       return   = it_return.

   WRITE: / 'Result of Reversal Posting:'.                   "#EC NOTEXT

   PERFORM show_messages.

   COMMIT WORK.

FORM show_messages.

   IF it_return[] IS INITIAL.

     WRITE: / 'no messages'.

   ELSE.

     SKIP 1.

     LOOP AT it_return.

       WRITE: /    it_return-type,

              (2it_return-id,

              (80) it_return-message,

              (20) it_return-parameter,

              (3it_return-row,

                   it_return-field.

     ENDLOOP.

   ENDIF.

   ULINE.

ENDFORM.


Thanks & Regards,


Abhijit

Read only

0 Likes
15,015

Same error:

Read only

0 Likes
15,015

Hello,

Have you checked your test data. May be your document number is matching the criteria for reversal.

Or that is already reversed.

Try to execute the standard report with your test data and see what results you get.

Thanks & Regards,

Abhijit

Read only

0 Likes
15,015

I triede using the example from SAP mentioned above and it errored out the same way. I am going to look around some more to see why it has such a hard time. I will report back when I find something. This one has me stumped at this point.

Read only

0 Likes
15,015

I am starting to wonder if the problem is that I am running this all in our Q01 test system. I saw another post from someone where they were getting this error and he said it was because the test system is something different.

Could this be my problem?

Read only

0 Likes
15,015

Success! The problem was that it did not have a match on the OBJ_SYS. When running this bapi, it does not want to know what system you are on. It wants to know which system is the match for what is supplied under BKPF-AWSYS for the document number that you are going to reverse. So what I did was as in my original code I additionally pulled that field as well and set that as OBJ_SYS in the bapi call and it went right through and worked. Thank all of you for your help.

Read only

0 Likes
15,015

Great Richard....Now you can close the thread by marked as answered...

Read only

Former Member
0 Likes
15,015

Did I really stump you guys on this?

Read only

Former Member
0 Likes
15,015

BTW...the point of this was to reverse an IDOC. That is in fact what I needed to specify in my BAPI call, not BKPF. You would do BKPF for transactions that were originally posted in Financial Accounting and not with IDOC.