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_INCOMINGINVOICE_CREATE

Former Member
0 Likes
3,772

Hi,

I am using BAPI_INCOMINGINVOICE_CREATE to create invoice which is working fine. But for some POs which does not have GR-Based IV checked in its Item data > Invoice tab the BAPI fails with the error: Enter goods receipt data only when working with GR-based IV. My question is: Is there any field to be set at BAPI item data for this kind of POs? Please let me know if you want my code.

Thank you,

Surya.

9 REPLIES 9
Read only

Former Member
0 Likes
1,418

Surya,

Can you post a Goods receipt(MIGO) and Invoice (MIRO) online when you don't check the GR based flag on the PO?

Read only

Former Member
0 Likes
1,418

Hi,

Don't populate the following fields if it is not GR-Based IV.

ref_doc

ref_doc_year

ref_doc_it

Thanks,

Naren

Read only

0 Likes
1,418

Kris,

I have not done this let me try it.

Naren,

I will try your suggsion also.

Thank you for your quick response.

-Thank you,

Surya.

Read only

Former Member
0 Likes
1,418

Hi,

You can check this sample code which creates invoice for the input PO..

TABLES: ekko.

PARAMETERS: p_ebeln TYPE ebeln OBLIGATORY.

DATA: itab LIKE ekpo OCCURS 0 WITH HEADER LINE.

DATA: invoice_items LIKE bapi_incinv_create_item OCCURS 0

WITH HEADER LINE.

DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

DATA: invheader TYPE bapi_incinv_create_header.

DATA: v_counter TYPE rblgp.

DATA: v_amount TYPE rbkp-rmwwr,

v_invoice TYPE bapi_incinv_fld-inv_doc_no,

v_year TYPE bapi_incinv_fld-fisc_year.

START-OF-SELECTION.

  • Get ekko.

SELECT SINGLE * FROM ekko

WHERE ebeln = p_ebeln.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH 'INVALID PO'.

LEAVE LIST-PROCESSING.

ENDIF.

  • Get ekpo.

SELECT * FROM ekpo

INTO TABLE itab

WHERE ebeln = p_ebeln.

IF sy-subrc <> 0.

MESSAGE s208(00) WITH 'INVALID PO'.

LEAVE LIST-PROCESSING.

ENDIF.

  • Prepare the line items.

LOOP AT itab.

  • Increment the counter.

v_counter = v_counter + 1.

  • Populate the invoice line item details.

invoice_items-invoice_doc_item = v_counter.

invoice_items-po_number = itab-ebeln.

invoice_items-po_item = itab-ebelp.

invoice_items-item_amount = itab-netpr *

itab-menge.

invoice_items-quantity = itab-menge.

invoice_items-po_unit = itab-meins.

APPEND invoice_items.

v_amount = v_amount + invoice_items-item_amount.

ENDLOOP.

  • Prepare the header

invheader-doc_date = sy-datum.

invheader-pstng_date = sy-datum .

invheader-comp_code = ekko-bukrs.

invheader-invoice_ind = 'X'.

invheader-currency = ekko-waers.

invheader-ref_doc_no = 'Test Invoice'.

invheader-gross_amount = v_amount.

  • Call the BAPI

CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'

EXPORTING

headerdata = invheader

IMPORTING

invoicedocnumber = v_invoice

fiscalyear = v_year

TABLES

itemdata = invoice_items

return = return.

  • Check the return code..

LOOP AT return

TRANSPORTING NO FIELDS

WHERE type = 'E' OR type = 'A'.

EXIT.

ENDLOOP.

IF sy-subrc = 0.

WRITE: / 'Error in creating'.

ELSE.

COMMIT WORK.

WRITE: / 'Invoice ', v_invoice, ' Year ', v_year, ' Created'.

ENDIF.

Thanks,

Naren

Read only

0 Likes
1,418

Hi Naren,

In your following sample code, you are not passing values to ref_doc, ref_doc_year, and ref_doc_it. So all your POs with GR-Based IV unchecked ?What are these fields use?

Thank you,

Surya.

Read only

0 Likes
1,418

Surya,

Please see the documentation for BAPI_INCOMINGINVOICE_CREATE.It is pretty extensive.

Ref_doc fields are populated for GR based invoices with GR document details.

regards

Read only

Former Member
0 Likes
1,418

Hi,

Try this passing

  CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
       EXPORTING
            headerdata       = i_headerdata
       IMPORTING
            invoicedocnumber = v_invoicedocnumber
            fiscalyear       = v_fiscalyear
       TABLES
            itemdata         = i_itemdata
            accountingdata   = i_accountingdata
            glaccountdata    = i_glaccountdata
            return           = i_return.
 IF  i_return[] IS INITIAL.
    COMMIT WORK.
ELSE.
ROLLBACK.
ENDIF.

Read only

Former Member
0 Likes
1,418

Hi,

If it is GR based based Invoice..Then in the fields REF_DOC..you have to populate the Material document number that created after the goods receipt..

SO in your case you don't have to populate those fields..

Thanks,

Naren

Read only

0 Likes
1,418

Naren,

I have both kinds of POs, that means some are GR-Based IV checked and some not checked. Right now I does not have a check on whether GR-Based IV checked or not. I can change the code accordingly. Here are the values I am passing to these fields now. Please let me if I am passing wrong values.

ref_doc = wa_ekbe-lfbnr (EKBE-LFBNR)

ref_doc_year = wa_ekbe-lfpos (EKBE-LFPOS)

ref_doc_it = wa_ekbe-gjahr (Is EKBE-GJAHR the right field? I just saw a field EKBE-LFGJA )

Kris:

I will look into the documentation also.

Thank you,

Surya.