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: 

MB_DOCUMENT_BADI and bapis/commit work

Former Member
0 Kudos

Hi all,

I need to book an invoice while executing MIGO. I use the class MB_DOCUMENT_BADI and the method MB_DOCUMENT_UPDATE, where I call BAPI_INCOMINGINVOICE_CREATE. Unfortunately it does not work (it exits debugger), as it seems that the material document has not been created yet ( but inside the badi I have already MBLNR...) . I tried to use BAPI_TRANSACTION_COMMIT before creating invoice, but it also exits. Can use those BAPIs inside MB_DOCUMENT_UPDATE?

Thanks!

Anna

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

when calling the BAPI call it in background task..

CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'

IN BACKGROUND TASK

...............

Thanks

Naren

2 REPLIES 2

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

Looks like the invoice creation fails because it tries to reference a material document that doesn't exist yet.

What you could try is to call BAPI_INCOMINGINVOICE_CREATE in a subroutine that is in a Z-program, and in method MB_DOCUMENT_UPDATE, you'd call that subroutine ON COMMIT. This would wait until your transaction does a COMMIT and only then it would execute the registered subroutine which then should be able to find the material document.

So, something like this:

Method MB_DOCUMENT_UPDATE.

Perform CALL_INVOICE_CREATE(ZPROG) Using <parameter list>

ON COMMIT.

Endmethod.

***

Program ZPROG.

Form CALL_INVOICE_CREATE Using <parameter list>.

Call Function BAPI_INCOMINGINVOICE_CREATE

EXPORTING...

IMPORTING...

Call Function BAPI_TRANSACTION_COMMIT.

Endform.

Former Member
0 Kudos

Hi,

when calling the BAPI call it in background task..

CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'

IN BACKGROUND TASK

...............

Thanks

Naren