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_INCOMINGINVOICE_CREATE

Former Member
0 Kudos

Hello, I am using BAPI_INCOMINGINVOICE_CREATE to create an Invoice from incoming IDocs. One of the requirements is to set the flag for PPA Exempt, BKPF-EXCLUDE_FLAG =’X’ (Accounting Document Header Table), in the invoice header. I have looked through all the Importing Structures as well as Tables and I don't see anything that remotely refers to this field. Can someone please let me know if this is possible when creating the Invoice or if there is a function module I can call after the invoice has been created.

Thank you in Advance.

Ron

1 ACCEPTED SOLUTION

karthikeyan_p3
Contributor
0 Kudos

Hi Ronald,

First implement the BADI INVOICE_UPDATE. This BADI is called immediately before saving the Invoice data (RBKP) and it is triggered from many transaction.

So, have a check and make sure that your piece of code is triggered only for your custom code. Set a flag say (lv_flag = 'X') and move it to shared memory (database index).

Now, implement the BADI AC_DOCUMENT and use method CHANGE_Initial to update the EXCLUDE_FLAG.

  DATA: lt_accit TYPE char18 VALUE '(SAPLMRMP)XACCIT[]'.

  FIELD-SYMBOLS : <ft_accit> TYPE accit_t,

                  <fs_accit> TYPE accit.

  ASSIGN (lt_accit) TO <ft_accit>.

  IF <ft_accit> IS ASSIGNED.
    LOOP AT <ft_accit> ASSIGNING <fs_accit>.
*Import the flag and check if it is valid     
     <fs_accit>-EXCLUDE_FLAG = <your value>

    ENDLOOP.
  ENDIF.

Hope this helps you.

Thanks,

Karthikeyan

7 REPLIES 7

karthikeyan_p3
Contributor
0 Kudos

Hi Ronald,

First implement the BADI INVOICE_UPDATE. This BADI is called immediately before saving the Invoice data (RBKP) and it is triggered from many transaction.

So, have a check and make sure that your piece of code is triggered only for your custom code. Set a flag say (lv_flag = 'X') and move it to shared memory (database index).

Now, implement the BADI AC_DOCUMENT and use method CHANGE_Initial to update the EXCLUDE_FLAG.

  DATA: lt_accit TYPE char18 VALUE '(SAPLMRMP)XACCIT[]'.

  FIELD-SYMBOLS : <ft_accit> TYPE accit_t,

                  <fs_accit> TYPE accit.

  ASSIGN (lt_accit) TO <ft_accit>.

  IF <ft_accit> IS ASSIGNED.
    LOOP AT <ft_accit> ASSIGNING <fs_accit>.
*Import the flag and check if it is valid     
     <fs_accit>-EXCLUDE_FLAG = <your value>

    ENDLOOP.
  ENDIF.

Hope this helps you.

Thanks,

Karthikeyan

karthikeyan_p3
Contributor
0 Kudos

You could also check the below link

http://blog.csdn.net/xyfchris/article/details/1811359

Thanks,

Karthikeyan

0 Kudos

Thank you Karthikeyan, I have been reviewing your comments and it seems that is a great solution. I will implement a test and go from there. One thing though, the field i'm trying to update is actually in ACCHD since it is a header item on table BKPF. So i assume I just substitute that for the item table ACCIT in the code. Question, how do I confirm that BAPI_INCOMINGINVOICE_CREATE will call these BADIs and I'm not sure why you suggested both INVOICE_UPDATE and AC_DOCUMENT . Can you please explain their specific use as it relates to setting the value for EXCLUDE_FLAG?

Thank you again!

Ron

0 Kudos

Oh forgot to ask since this is table ACCHD instead of ACCIT, would you still recommend using method CHANGE_AFTER_CHECK  or does it not make a difference which data i'm updating?

Ron....

0 Kudos

Hi Ron,

Yeah, Sorry. It was my mistake. You could go ahead with ACCHD[].

When you create MM doc (using BAPI_incominginvoice_create), system will automatically create its equivalent FI doc (accounting doc)
BADI AC_DOCUMENT will be called generically for all the accounting documents. (ie FB01, FB50, FV60, MIRO, MIR8 etc..)

I guess, your requirement will be to update EXCLUDE_FLAG only for a specific scenario (MIRO using BAPI_incominginvoice_create)
You need to differentiate that. Isn't it.

We are going for INVOICE_UDPATE BADI for that. This BADI will be called only during (MIRO, MIR7, MR8M tcode) & their equivalent FMs.
So, you are going to set a flag in memory (you could choose your own approach) after making sure that the BADI is triggered from your ZREPORT.
& Use that flag in the other BADI. By this way we could make sure that EXCLUDE_FLAG is updated only for your specific requirement.


Thanks,
Karthikeyan

0 Kudos

Thus far, I have tried BADI AC_DOCUMENT. I have tried both methods CHANGE_INITIAL and CHANGE_AFTER_CHECK with the following code:

DATA: lt_acchd TYPE char18 VALUE '(SAPLMRMP)XACCHD[]'.
   FIELD-SYMBOLS: <ft_acchd> TYPE acchd_t,
                  <fs_acchd> TYPE acchd.
   ASSIGN (lt_acchd) TO <ft_acchd>.
   IF <ft_acchd> IS ASSIGNED.
     LOOP AT <ft_acchd> ASSIGNING <fs_acchd>.
*Import the flag and check if it is valid
       <fs_acchd>-exclude_flag = 'X'.
     ENDLOOP.
   ENDIF.

One of the problems, the ASSIGN (lt_acchd) TO <ft_acchd> does not make the assignment (SY-SUBRC = 4) so the remaining code does not get executed. Does anyone know what I may be doing wrong or perhaps a better way to make this update, would there need to be additional data other than the EXCLUDE_FLAG inserted into XACCHD in order for it to identify what invoice document to modify?

0 Kudos

Hi Ronald,

Can you check the call stack once the break point reaches the BADI. In your case, it may not be from the program "SAPLMRMP". Check in which program (from call stack) the internal table XACCHD[] is getting set. (You could do that by setting watchpoint on XACCHD[]).

Then you need to change the <PROGRAM NAME> in the below statement.

DATA: lt_acchd TYPE char18 VALUE '(<PROGRAM NAME>)XACCHD[]'.

Thanks,

Karthikeyan