<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem with BAPI_INCOMINGINVOICE_CREATE in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-bapi-incominginvoice-create/m-p/3760927#M904821</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a vendor invoice using BAPI_INCOMINGINVOICE_CREATE. The main problem i am facing is that after the invoice has been posted, when i check the created invoice, the G/L account is taken from the material not the one associated with the PO and the posting key is not 40.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the G/L account be taken from the PO and have posting key as 40.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly let me know how do i that....if anyone has a sample code...it is highly appreciated...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;&lt;P&gt;Preetham S&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 06 May 2008 15:02:51 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-05-06T15:02:51Z</dc:date>
    <item>
      <title>Problem with BAPI_INCOMINGINVOICE_CREATE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-bapi-incominginvoice-create/m-p/3760927#M904821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to create a vendor invoice using BAPI_INCOMINGINVOICE_CREATE. The main problem i am facing is that after the invoice has been posted, when i check the created invoice, the G/L account is taken from the material not the one associated with the PO and the posting key is not 40.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the G/L account be taken from the PO and have posting key as 40.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kindly let me know how do i that....if anyone has a sample code...it is highly appreciated...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks..&lt;/P&gt;&lt;P&gt;Preetham S&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2008 15:02:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-bapi-incominginvoice-create/m-p/3760927#M904821</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-06T15:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with BAPI_INCOMINGINVOICE_CREATE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-bapi-incominginvoice-create/m-p/3760928#M904822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a sample code to copy a document.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
*&amp;amp;---------------------------------------------------------------------*
*&amp;amp;      Form  f300_duplicate
*&amp;amp;---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  --&amp;gt;  p1        text
*  &amp;lt;--  p2        text
*----------------------------------------------------------------------*
FORM f300_duplicate .

  LOOP AT t_bseg.
    MOVE-CORRESPONDING t_bseg TO t_bseg2.
    APPEND t_bseg2.
  ENDLOOP.

  SORT t_bseg2 BY belnr bschl.

  LOOP AT t_bseg2.
    MOVE-CORRESPONDING t_bseg2 TO w_bseg2.

    AT NEW belnr.
* Invoice or Credit memo ?
      IF w_bseg2-bschl = k_31.
        w_headerdata-invoice_ind = k_x.
* Full structure W_HEADERDATA
        PERFORM f310_header_data.
      ELSE.
        w_headerdata-invoice_ind = space.
        PERFORM f310_header_data.
      ENDIF.
    ENDAT.

* Full table T_ITEMDATA
    IF t_bseg2-bschl = k_81 OR t_bseg2-bschl = k_91.
      PERFORM f320_item_data.
    ENDIF.

* If item 40 or 50 : + or - amnt on the hight amount of line in 81 or 91
    IF w_headerdata-invoice_ind = k_x.
      CLEAR w_wrbtr2.
      w_wrbtr2 = t_bseg2-wrbtr.
      IF t_bseg2-bschl = k_40.
        w_wrbtr = w_wrbtr + w_wrbtr2.
        SORT t_itemdata BY item_amount DESCENDING.
        READ TABLE t_itemdata INDEX 1.
        t_itemdata-item_amount = t_itemdata-item_amount + w_wrbtr2.
        MODIFY t_itemdata INDEX 1.
      ELSEIF t_bseg2-bschl = k_50.
        w_wrbtr = w_wrbtr - w_wrbtr2.
        SORT t_itemdata BY item_amount DESCENDING.
        READ TABLE t_itemdata INDEX 1.
        t_itemdata-item_amount = t_itemdata-item_amount - w_wrbtr2.
        MODIFY t_itemdata INDEX 1.
      ENDIF.
    ELSE.
      CLEAR w_wrbtr2.
      w_wrbtr2 = t_bseg2-wrbtr.
      IF t_bseg2-bschl = k_40.
        w_wrbtr = w_wrbtr - w_wrbtr2.
        SORT t_itemdata BY item_amount DESCENDING.
        READ TABLE t_itemdata INDEX 1.
        t_itemdata-item_amount = t_itemdata-item_amount - w_wrbtr2.
        MODIFY t_itemdata INDEX 1.
      ELSEIF t_bseg2-bschl = k_50.
        w_wrbtr = w_wrbtr + w_wrbtr2.
        SORT t_itemdata BY item_amount DESCENDING.
        READ TABLE t_itemdata INDEX 1.
        t_itemdata-item_amount = t_itemdata-item_amount + w_wrbtr2.
        MODIFY t_itemdata INDEX 1.
      ENDIF.
    ENDIF.


    AT END OF belnr.
      IF w_wrbtr = w_amount_lifnr.
        w_headerdata-gross_amount = w_wrbtr.
      ELSE.
        w_headerdata-gross_amount = w_amount_lifnr.
      ENDIF.
      t_taxdata-tax_code = k_v1.
      APPEND t_taxdata.

*** Check if doc already exist only when online
      IF sy-batch = space.
        SELECT bukrs belnr gjahr UP TO 1 ROWS FROM bkpf
                               INTO (bkpf-bukrs, bkpf-belnr, bkpf-gjahr)
                                  WHERE bukrs = w_headerdata-comp_code
                                    AND gjahr = p_gjahr
                                    AND bldat = w_headerdata-doc_date
                                    AND blart = w_headerdata-doc_type
                                    AND xblnr = w_headerdata-ref_doc_no.
        ENDSELECT.
        IF sy-subrc = 0.
*** BEGIN ADD LCO020108
          w_message1 = text-007.
          REPLACE '&amp;amp;1' WITH bkpf-belnr INTO w_message1.
*** END ADD
          CALL FUNCTION 'FI_WT_POPUP_TO_CONFIRM_STEP'
            EXPORTING
              defaultoption = 'Y'
              textline1     = w_message1
              textline2     = text-008
              titel         = text-009
              start_column  = 25
              start_row     = 6
            IMPORTING
              answer        = w_answer.
        ENDIF.
      ENDIF.

      IF ( sy-batch = space AND w_answer = 'J' ) OR sy-batch = k_x
                                                 OR sy-subrc &amp;lt;&amp;gt; 0.

*----- call BAPI Create -----------------------------------------------*
        CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
          EXPORTING
            headerdata       = w_headerdata
            addressdata      = w_addressdata
          IMPORTING
            invoicedocnumber = w_invoicedocnumber
            fiscalyear       = w_fiscalyear
          TABLES
            itemdata         = t_itemdata
            taxdata          = t_taxdata
            return           = t_return.

        IF NOT t_return[] IS INITIAL.
          ROLLBACK WORK.
          CLEAR : w_headerdata, w_addressdata,
                  w_invoicedocnumber, w_fiscalyear,
                  t_itemdata, t_taxdata.
          REFRESH : t_itemdata, t_taxdata.
          LOOP AT t_return.
            MOVE t_return-message TO t_error-message.
            MOVE t_bseg2-belnr TO t_error-belnr.
            APPEND t_error.
          ENDLOOP.
*** BEGIN ADD LCO020108
          IF ( sy-batch = space AND w_answer = 'J' ).
            CALL FUNCTION 'POPUP_TO_INFORM'
              EXPORTING
                titel = text-014
                txt1  = text-013
                txt2  = text-016.
          ENDIF.
*** END ADD
        ELSE.
          COMMIT WORK AND WAIT.
          MOVE w_headerdata-comp_code TO t_report2-bukrs.
          MOVE w_invoicedocnumber TO t_report2-nb.
          MOVE w_fiscalyear TO t_report2-year.
          APPEND t_report2.
*** BEGIN ADD LCO020108
          IF ( sy-batch = space AND w_answer = 'J' ).
            CALL FUNCTION 'POPUP_TO_INFORM'
              EXPORTING
                titel = text-014
                txt1  = text-015
                txt2  = space.
          ENDIF.
*** END ADD
          CLEAR : w_headerdata, w_addressdata, w_wrbtr,
                  w_invoicedocnumber, w_fiscalyear,
                  t_itemdata, t_taxdata.
          REFRESH : t_itemdata, t_taxdata.
        ENDIF.

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Christophe&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Please reward if helpful&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 06 May 2008 16:13:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/problem-with-bapi-incominginvoice-create/m-p/3760928#M904822</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-05-06T16:13:03Z</dc:date>
    </item>
  </channel>
</rss>

