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 posting duplicate entries

Former Member
0 Likes
7,700

Hello,

I have been working on BAPI_ACC_DOCUMENT_POST bapi to create a WD application for creating an invoice similar to Tcode FB10. My issue is:-

The BAPI_ACC_DOCUMENT_POST" bapi is allowing the end user to make duplicate invoice payments which is not acceptable. We need the BAPI to return an error message if a duplicate entry exists. For eg:- If we enter a duplicate entry in FB10 it throws an error message telling the user that a duplicate entry exists. But, this is not happening in the case of the BAPI.

Could anyone help me in finding a way to check for duplicate invoice entries and throw an error message. I would greately appreciate your help.

Regards,

Gopal Yarlagadda.

41 REPLIES 41
Read only

Former Member
0 Likes
2,489

Is it not just a warning in FB10?

Rob

Read only

0 Likes
2,488

Hello Rob,

No, in FB10 it is an error message "Check whether document has already been entered under number 1000 600000188 2009".

I think this has been configured in our system as a custom configuration.

Regards,

Gopal.

Read only

0 Likes
2,488

Hi

That msg can be customized as warning or error.

Anyway the main fields of vendor invoice are stored in BSIP table, u can check this table in order to know if an invoice was just posted.

Max

Read only

Former Member
0 Likes
2,489

Hi

In generally it means to check if there's an invoice with the same reference, so try to check the entries in BSIP table

Max

Read only

0 Likes
2,489

Hi Max,

Thanks for your reply. I checked in the table BSIP and I can see the duplicate entries being created. My problem is:-

Our system is not allowing duplicate entries through tcode:- FB10 or FB60. But, when when we enter an invoice through a Webdynpro Application created through BAPI_ACC_DOCUMENT_POST bapi, the BAPI is not returning any error message about the duplicate entries. Could you please help me about this problem. I would greatly appreciate your help.

Regard,

Gopal.

Read only

0 Likes
2,489

just a thought: try out the same scenario by wrting a Z report prog. or in SE37, then check their results. Also check Cross company code flag, multiple currencies, posting keys

thanq

Edited by: SAP ABAPer on Sep 3, 2009 6:27 PM

Read only

0 Likes
2,489

Hi

The BAPI doesn't call the fm FI_DUPLICATE_INVOICE_CHECK in order to check the posting: I was the same problem and I solved it by the BTE RWBAPI01, usually used to transfer the extension data.

If your release is ECC 6 u can also use the BADI acc_document (method change).

If you use the BTE u need to use a record dummy for extension in order to trigger the BTE

This is the code (Step 1):

.FUNCTION Z_SDFI_INTERFACE_RWBAPI01.
*"----------------------------------------------------------------------
*"*"Interfaccia locale:
*"  TABLES
*"      IT_ACCIT STRUCTURE  ACCIT
*"      IT_ACCCR STRUCTURE  ACCCR
*"      RETURN STRUCTURE  BAPIRET2
*"      EXTENSION STRUCTURE  BAPIACEXTC
*"      IT_ACCWT STRUCTURE  ACCIT_WT
*"  CHANGING
*"     VALUE(DOCUMENT_HEADER) LIKE  ACCHD STRUCTURE  ACCHD
*"----------------------------------------------------------------------
............................
  LOOP AT IT_ACCIT WHERE KOART = 'K'.

    IT_ACCIT-XUMSW = 'X'.
    MODIFY IT_ACCIT.

    SELECT SINGLE REPRF FROM LFB1 INTO _REPRF
                                           WHERE LIFNR = IT_ACCIT-LIFNR
                                             AND BUKRS = IT_ACCIT-BUKRS.
    IF SY-SUBRC <> 0.
      CLEAR _REPRF.
    ENDIF.

    READ TABLE IT_ACCCR WITH KEY POSNR = IT_ACCIT-POSNR.

.

Max

Read only

0 Likes
2,489

The BAPI may not be returning it as an "Error" message but it may be there in the return table as a warning message. Please check the return table for all the messages.

Read only

0 Likes
2,489

......Step 2

CALL FUNCTION 'FI_DUPLICATE_INVOICE_CHECK'
         EXPORTING
              I_BUKRS       = IT_ACCIT-BUKRS
              I_LIFNR       = IT_ACCIT-LIFNR
              I_WAERS       = IT_ACCCR-WAERS
              I_BLDAT       = IT_ACCIT-BLDAT
              I_XBLNR       = IT_ACCIT-XBLNR
              I_WRBTR       = IT_ACCCR-WRBTR
              I_KOART       = 'K'
              I_REPRF       = _REPRF
              I_SHKZG       = IT_ACCIT-SHKZG
              I_XUMSW       = IT_ACCIT-XUMSW
              I_BSTAT       = IT_ACCIT-BSTAT
              I_BLART       = IT_ACCIT-BLART
         EXCEPTIONS
              MISSING_DATA  = 1
              ERROR_MESSAGE = 2
              OTHERS        = 3.

    IF SY-SUBRC <> 0.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
           EXPORTING
                TYPE   = SY-MSGTY
                CL     = SY-MSGID
                NUMBER = SY-MSGNO
                PAR1   = SY-MSGV1
                PAR2   = SY-MSGV2
                PAR3   = SY-MSGV3
                PAR4   = SY-MSGV4
           IMPORTING
                RETURN = RETURN.
      APPEND RETURN.
    ENDIF.

  ENDLOOP.

ENDFUNCTION.

Max

Read only

0 Likes
2,489

Hi Max,

Thanks a lot for your reply. I appreciate your help. Actually, I am new to ABAP. So, could you please explain me of what to do in more detail. Can I insert the code into the my Webdynpro application so that my the duplicate entry check would be done??

I am sorry if I am causing any inconvenience. I appreciate your help and support.

Regards,

Gopal.

Read only

0 Likes
2,489

Hi srinivas,

Thanks for your reply. I did check the return table and it doesn't show any warning messages as well!!! I haven't got a clue of what to do in this situation.

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

I suppose your Webdynpro just calls the BAPI, so u need any modification here, but only place the control inside the BAPI.

Let me know which tool u prefer to use:

BTE or BADI?

Max

Read only

0 Likes
2,489

Hi Max,

I prefer the easiest way of doing this as I am a bit new to ABAP. I hope you can understand my situation!!

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

Start with following steps

- Run trx SE19

- Insert ACC_DOCUMENT in CLASSIC BADI section

- Press Create Impl.

- Insert Z_ACC_DOCUMENT as implementation name

- Press Enter

- Insert a short text in your implementation

- Add BKPFF as filter

- Active it

Max

Read only

0 Likes
2,489

Hi Max,

I did what you said. What should I do next?

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

After activing the BADI the system should migrate it to the new BADI

Have you done it?

Max

Read only

0 Likes
2,489

Hi Max,

Yes, I think I did the migration. Because I can see the field "Impl migrates to enhancement --Z_ACC_DOCUMENT" in the present screen. What should I do next?

Read only

0 Likes
2,489

Hi

Now u need to implement the method CHANGE, so back to the BADI and press INTERFACE tab and double click on method CHANGE

Here u need to insert the code to check the duplicate posting

DATA: W_ACCIT  TYPE ACCIT.
  DATA: _REPRF   TYPE LFB1-REPRF.
  DATA: W_ACCCR  TYPE ACCCR.
  DATA: W_RETURN TYPE BAPIRET2.



  LOOP AT C_ACCIT INTO W_ACCIT WHERE KOART = 'K'.
* Check if the vendor has to be available for duplicete posting control
    SELECT SINGLE REPRF FROM LFB1 INTO _REPRF
       WHERE LIFNR = W_ACCIT-LIFNR
         AND BUKRS = W_ACCIT-BUKRS.
    IF SY-SUBRC <> 0.
      CLEAR _REPRF.
    ENDIF.

    READ TABLE C_ACCCR INTO W_ACCCR WITH KEY POSNR = W_ACCIT-POSNR.

    CALL FUNCTION 'FI_DUPLICATE_INVOICE_CHECK'
      EXPORTING
        I_BUKRS       = W_ACCIT-BUKRS
        I_LIFNR       = W_ACCIT-LIFNR
        I_WAERS       = W_ACCCR-WAERS
        I_BLDAT       = W_ACCIT-BLDAT
        I_XBLNR       = W_ACCIT-XBLNR
        I_WRBTR       = W_ACCCR-WRBTR
        I_KOART       = 'K'
        I_REPRF       = _REPRF
        I_SHKZG       = W_ACCIT-SHKZG
        I_XUMSW       = W_ACCIT-XUMSW
        I_BSTAT       = W_ACCIT-BSTAT
        I_BLART       = W_ACCIT-BLART
      EXCEPTIONS
        MISSING_DATA  = 1
        ERROR_MESSAGE = 2
        OTHERS        = 3.

    IF SY-SUBRC <> 0.
      CALL FUNCTION 'BALW_BAPIRETURN_GET2'
        EXPORTING
          TYPE   = SY-MSGTY
          CL     = SY-MSGID
          NUMBER = SY-MSGNO
          PAR1   = SY-MSGV1
          PAR2   = SY-MSGV2
          PAR3   = SY-MSGV3
          PAR4   = SY-MSGV4
        IMPORTING
          RETURN = W_RETURN.
      APPEND W_RETURN TO C_RETURN.
    ENDIF.

  ENDLOOP.

Max

Read only

0 Likes
2,489

Hi Max,

I did insert the code in the "Change" method and activated the method as well. What should I do next? Sorry for asking you every step. Your help is very much appreciated!

Regards,

Gopal.

Edited by: Gopal on Sep 4, 2009 11:25 AM

Read only

0 Likes
2,489

Hi

U've finished.

Now try to call the BAPI by your WebDynpro, try to post an inovice just posted, now an error message should be displayed.

Max

Read only

0 Likes
2,489

Hi Max,

Could you please explain me about:-

After activing the BADI the system should migrate it to the new BADI

I think I did not do it properly. Could you explain me what is happening here? I appreciate your help and support.

Regards,

Gopal.

Read only

0 Likes
2,489

Hi Max,

When I activated the Badi, I got a Pop-up window "Select or Create Enhancement Implementaion" and a button to "Create Enhancement Implementation". The Pop-up box has already got two values, "ISM_BYTITLEPP_ACCDOC" and "ACC_DOCUMENT_CREDIT". I am not able to figure out what to do here. Please let me know of what to do. I would appreciate your help.

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

It's the new concept of BADI, it's better to use an own Enhancement Implementation: ISM_BYTITLEPP_ACCDOC" and "ACC_DOCUMENT_CREDIT are standard.

So when popup "Select or Create Enhancement Implementaion" is shown, press "Create Enhancement Implementation":

Here insert a name (for example: Z_ACC_DOCUMENT_BAPI), a short description and it's better to create "Composite Enhancement Implementation": u can assigne the same name of Enhancement Implementation.

After creating them the Enhancement Implementation should be shown in the popup, now u need to select it in order to assign it to your BADI

Max

Read only

0 Likes
2,489

Hi Max,

Thats great. I just did it. Now, in the code for the "Change" method, it is throwing syntax errors at the following line of code:-


IF SY-SUBRC  0.

Should I change it to


"IF SY-SUBRC EQ 0"

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

No, it's not equal:

I don't know why but this editor hides the sign for less and greater

So after calling the fm u need to check SY-SUBRC is not equal to 0

Max

Read only

0 Likes
2,489

Hi Max,

So, should I change it to:-


IF SY-SUBRC NE 0

Regards,

Gopal.

Read only

0 Likes
2,489

Yes

Read only

0 Likes
2,489

Hi Max,

Thanks for your help. But, I have implemented it and check my BAPI_ACC_DOCUMENT_POST bapi. I entered the same data twice and the BAPI is posting a document without returning any error message. I dont know what the reason is? Do you want me to check anything else? I think the Badi thing did not help us!!!

Regard,

Gopal.

Edited by: Gopal on Sep 4, 2009 12:14 PM

Read only

0 Likes
2,489

Hi Max,

Should I mentioned the created Badi implementation anywhere in my webdynpro application to check for duplicate AP documents?

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

No, the BADI is just a user-exit inside the BAPI:

it'll be triggered as soon as the BAPI BAPI_ACC_DOCUMENT_POST is called.

So u need to try to post a vendor invoice just posted and now an error message should be returned by the BAPI.

Max

Read only

0 Likes
2,489

Hi Max,

I did tested the BAPI again and it is not throwing any error message if I post the same document more than once. Do I need to do anything else for this?

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

Try to post a break-point in the BAPI in this line:

PERFORM call_badi
            TABLES extension2.

and run the WD again, check if the BADI is triggered

Max

Read only

0 Likes
2,489

Hi Max,

Yes, the Badi is getting triggered but it is not throwing any error message about the duplicate entries. is this because, the BAPI doesn't post the actual document in to the database table until the BAPI_TRANSACTION_COMMIT bapi is executed?

What do you think the problem might be?

Regards,

Gopal.

Edited by: Gopal on Sep 4, 2009 1:20 PM

Read only

0 Likes
2,489

Hi Max,

Any updates please?

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

If the BADI is triggered u make check what's happens after calling the fm FI_DUPLICATE_INVOICE_CHECK, if it returns a SY-BURC different from 0, u call the fm BALW_BAPIRETURN_GET2 in order to append the error message in table RETURN.

This table has all messages and if there's a message type E or A, the document won't be posted.

So u need to check which message is returned in the BAPI paramenter RETURN.

If the invoice was just posted u should find out the message 117 of class F5, if in your customizing this message is set as type ERROR, any document will be posted.

Now your WD should display the messages returned by the BAPI

Max

Read only

0 Likes
2,489

Hi Max,

I did check the SY_SUBRC and it is "0" even if I enter an invoice twice or thrice. I debugged the BAPI_ACC_DOCUMENT_POST at the point and it is not showing any error message even the "BALW_BAPIRETURN_GET2" is called. I am not able to understand what to do. Is there any other setting I need to configure to avaoid postingthe duplicate invoice using the BAPI?

Please help me to resolve this problem. I greatly appreciate your help.

Regards,

Gopal.

Read only

0 Likes
2,489

Hi

U need to debug FI_DUPLICATE_INVOICE_CHECK, not the BAPI, it seems the system doesn't find a record in BSIP.

So try to debug that fm while selecting BSIP table:

*------- Index für doppelte Rechnungen lesen ---------------------------
*        Rechnungen können in BSIP mit SHKZG 'H' und SPACE stehen,
*        da SHKZG neu in BSIP zu 4.0A
  not_shkzg = i_shkzg.
  translate not_shkzg using 'SHHS'.

  if i_xblnr = space.
    select * into bsip
             from bsip
             where bukrs = i_bukrs
             and   lifnr = i_lifnr
             and   waers = i_waers
             and   xblnr = i_xblnr
             and   wrbtr = i_wrbtr
             and   bldat = i_bldat
             and   shkzg ne not_shkzg.

*     credit memos & invoice < 4.0
      check not ( i_shkzg = 'S' and bsip-shkzg = space ).

* check if bsip refers to same document
      check not ( i_belnr = bsip-belnr and
                  i_bukrs = bsip-bukrs and
                  i_gjahr = bsip-gjahr ) .

      perform doppelte_belege_pruefen_s using rc.
      check rc = 0.
      exit.
    endselect.
  else.
    select * into bsip
             from bsip
             where bukrs = i_bukrs
             and   lifnr = i_lifnr
             and   waers = i_waers
             and   xblnr = i_xblnr
             and   bldat = i_bldat
             and   shkzg ne not_shkzg.

*     credit memos & invoice < 4.0
      check not ( i_shkzg = 'S' and bsip-shkzg = space ).


* check if bsip refers to same document
      check not ( i_belnr = bsip-belnr and
                  i_bukrs = bsip-bukrs and
                  i_gjahr = bsip-gjahr ) .

      perform doppelte_belege_pruefen_s using rc.
      check rc = 0.
      exit.
    endselect.
  endif.

If a record in BSIP exists, the routine doppelte_belege_pruefen_s is triggered, here an error message should be raised.

Max

Read only

0 Likes
2,489

The routine doppelte_belege_pruefen_s calls the fm CUSTOMIZED_MESSAGE where the message should be raised: so check what happens there

Max

Read only

0 Likes
2,489

Hi Max,

Thanks a lot for your great help. I figured out the problem. The problem is in the "Change" method of the Badi Implementation. There i had to change the code at:-


I_XUMSW       = W_ACCIT-XUMSW

to


I_XUMSW       = 'X'

As soon I changed the code and executed my BAPI it worked. Thanks a lot for your great effort throughtout the day.

Regards,

Gopal.