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 - Error

Former Member
0 Likes
1,735

Hi guys,

I'm creating an credit invoice that a return.

I've done succesfully the following steps: VA01, VL01N, VF01 and MIGO.

Here goes my codding:



  DATA: l_headerdata TYPE bapi_incinv_create_header.
  DATA: l_invoicedocnumber TYPE bapi_incinv_fld-inv_doc_no.
  DATA: lt_return  TYPE STANDARD TABLE OF bapiret2.
  DATA: lt_itemdata TYPE STANDARD TABLE OF bapi_incinv_create_item.
  DATA: ls_itemdata TYPE bapi_incinv_create_item.
  DATA: ls_goodsmvt_item TYPE bapi2017_gm_item_create.


  READ TABLE lt_zvpfpdev INTO ls_zvpfpdev INDEX 1.
  READ TABLE lt_goodsmvt_item INTO ls_goodsmvt_item INDEX 1.


  IF ls_zvpfpdev-belnr_fp IS INITIAL.

    DATA: ls_vbrk TYPE vbrk.

    SELECT SINGLE * FROM vbrk
      INTO ls_vbrk
    WHERE vbeln EQ ls_zvpfpdev-vbeln_pi.

***COPIADO DA MIGO*********
    DATA: lt_mseg TYPE STANDARD TABLE OF mseg.
    DATA: ls_mseg TYPE mseg.
    FIELD-SYMBOLS: <mseg> TYPE mseg.



    SELECT * FROM mseg
      INTO TABLE lt_mseg
      WHERE mblnr = ls_zvpfpdev-mblnr_101
      AND   mjahr = sy-datum(4).

******************
    DATA: lt_ekbe TYPE STANDARD TABLE OF ekbe.
    DATA: ls_ekbe TYPE ekbe.

    READ TABLE lt_mseg INTO ls_mseg INDEX 1.

    SELECT * FROM ekbe
      INTO TABLE lt_ekbe
      WHERE ebeln = ls_mseg-ebeln
      AND   belnr = ls_zvpfpdev-mblnr_101
      AND     gjahr = sy-datum(4).


    READ TABLE lt_ekbe INTO ls_ekbe INDEX 1.

***COPIADO DA MIGO*********

    l_headerdata-doc_type = 'DC'.
    l_headerdata-doc_date = sy-datum.
    l_headerdata-pstng_date = sy-datum.
    l_headerdata-ref_doc_no = ls_zvpfpdev-vbeln_d_fp.
    l_headerdata-header_txt = 'Devoluções Pasta Fine Paper à Portucel'.
    l_headerdata-calc_tax_ind = 'X'.
    l_headerdata-bline_date = sy-datum.
    l_headerdata-gross_amount = ls_vbrk-netwr - ls_vbrk-mwsbk. " + ou - ??

******************
    l_headerdata-currency     = ls_ekbe-waers.
    l_headerdata-bline_date   = sy-datum.

    l_headerdata-comp_code    = 'P168'. "ls_ekko-bukrs.




    DATA: n TYPE i.
*  if p_id = 'CPST1' and p_bukrs = 'PI10' and zsdvdesp-bukrs_c = 'P160'.
*    tab_itemdata-quantity         = vbrp-fkimg * 1000.
*  else.




    LOOP AT lt_goodsmvt_item INTO ls_goodsmvt_item.
      n = n + 10.
CLEAR: LS_EKBE.
read table LT_EKBE INTO LS_EKBE WITH KEY CHARG = ls_goodsmvt_item-BATCH.

      ls_itemdata-invoice_doc_item = n.
      ls_itemdata-po_number = ls_goodsmvt_item-po_number.
      ls_itemdata-po_item   =   ls_goodsmvt_item-po_item.
      ls_itemdata-po_unit   =   ls_goodsmvt_item-base_uom.



***TEST*****
      ls_itemdata-ref_doc_year =   ls_goodsmvt_item-ref_doc_yr.
      ls_itemdata-ref_doc_it   =   ls_goodsmvt_item-ref_doc_it.
      ls_itemdata-ref_doc      =   ls_goodsmvt_item-ref_doc.
      ls_itemdata-quantity     =   ls_goodsmvt_item-quantity.

***TEST*****




      ls_itemdata-tax_code = 'MW'.
     ls_itemdata-de_cre_ind = 'X'.
      ls_itemdata-ITEM_AMOUNT = LS_EKBE-WRBTR.

      APPEND ls_itemdata TO lt_itemdata.
      CLEAR: ls_itemdata.
    ENDLOOP.



    CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
      EXPORTING
        headerdata                = l_headerdata
*   ADDRESSDATA               =
     IMPORTING
       invoicedocnumber          = l_invoicedocnumber
*   FISCALYEAR                =
      TABLES
        itemdata                  = lt_itemdata
*   ACCOUNTINGDATA            =
*   GLACCOUNTDATA             =
*   MATERIALDATA              =
*   TAXDATA                   =
*   WITHTAXDATA               =
*   VENDORITEMSPLITDATA       =
        return                    = lt_return
*   NFMETALLITMS              =
              .

    IF l_invoicedocnumber IS NOT INITIAL.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     WAIT          = 'X'
*   IMPORTING
*     RETURN        =
            .

      LOOP AT lt_zvpfpdev ASSIGNING <zvpfpdev>.
        <zvpfpdev>-belnr_fp = l_invoicedocnumber.
      ENDLOOP.

      MODIFY zvpfpdev FROM TABLE lt_zvpfpdev.

    ENDIF.

  ENDIF.

It is comming back with the error: MSGID - M8 - MESSAGE - 080

Its something about the Quantity of the return is bigger than the invoices.

I'm sure that we got a invoice of 100k, and i'm testing this with just 2k.

Any idea ? The functional says everything is alright, that it should go through, but I'm stuck and with this, since friday, and I cannot see anything ..

Help please.

4 REPLIES 4
Read only

Former Member
0 Likes
1,150

Check the document history for the order. It will tell you if other returns were made.

Rob

Read only

former_member182371
Active Contributor
0 Likes
1,150

Hi,

put a break-point in function module MRM_QUANTITY_CHECK and check what is going on.

Best regards.

Read only

0 Likes
1,150

Hi Rob and Pablo,

Thanks for the quicks replys, both helped me to understand that i was referencing to a wrong Material Document. The functional told me that I have to use the one that was created on Migo with Movement type 101 ( the one that was made when the goods were sent to the customer) and not the return one that I've created.

Ok, so far so good.

I got it through, I had some other mistakes as well, doc_type.

Thank you both for your help.

Really apreciate it !

Read only

Former Member
0 Likes
1,150

The error was on the reference document.

You must reference to the material document with the type 101, and not the 122 ( Return to Vendor ).

Thank you all.