SAP Bilgi Merkezi
Ana Sayfa  ABAP   FI   CO   MM   SD   PP   QM   HR   BW 
ABAP Destek
Satıcı Faturası At

Sisteme satıcı faturası girebilmek için BAPI_INCOMINGINVOICE_CREATE fonksiyonu çağırılabilir. Aşağıdaki örnek programda nasıl yapılacağını görebilirsiniz.

Örnek Kod :

  CONSTANTS: lc_function(27) VALUE 'BAPI_INCOMINGINVOICE_DELETE'.

  DATA: be_data LIKE bbp_iv_be,
        h_return LIKE bapiret2 OCCURS 0 WITH HEADER LINE,
        belnr LIKE bkpf-belnr,
        gjahr LIKE bkpf-gjahr.

  DATA: ls_header    TYPE bapi_incinv_create_header,
        ls_address   TYPE bapi_incinv_create_addressdata,
        lt_item      TYPE bapi_incinv_create_item OCCURS 0,
        lt_account   TYPE bapi_incinv_create_account OCCURS 0,
        lt_glaccount TYPE bapi_incinv_create_gl_account OCCURS 0,
        lt_tax       TYPE bapi_incinv_create_tax OCCURS 0,
        lt_withtax   TYPE bapi_incinv_create_withtax OCCURS 0,
        lt_vendor    TYPE bapi_incinv_create_vendorsplit OCCURS 0.

  CLEAR: belnr, gjahr.
  REFRESH return. CLEAR return.

*-------- get additional backend data ---------------------------------*
  PERFORM get_data_from_backend TABLES ti_it
                                       ti_tax
                                       ti_shp
                                       ti_add
                                       ti_cmt
                                       return
                                 USING i_hd
                                 CHANGING be_data.
  CHECK return[] IS INITIAL.

*-------- default header text for credit memo -------------------------*
  PERFORM default_header_text CHANGING i_hd.

*-------- country-specific extensions ---------------------------------*
  PERFORM icc_before_invoice TABLES ti_it
                                    ti_tax
                                    ti_shp
                                    ti_add
                                    ti_cmt
                                    return
                           CHANGING i_hd
                                    be_data.

* gaps
  IF be_data-release >= c_release_60 AND
     i_hd-exi_ind = 'X'.
*   call BAPIs

    IF i_hd-del_ind = 'X'.

*     LIV reference (deletion of invoice)
      WRITE i_hd-inv_ref+00(10) TO belnr.
      WRITE i_hd-inv_ref+10(4)  TO gjahr.

*     call BAPI in order to delete invoice
      CALL FUNCTION lc_function
        EXPORTING
          invoicedocnumber = belnr
          fiscalyear       = gjahr
        TABLES
          return           = return.

    ELSE.

      PERFORM invoice_for_bapi_fill TABLES   ti_it
                                             ti_tax
                                             ti_shp
                                             ti_cmt
                                             ti_add
                                             ti_exr
                                             lt_item
                                             lt_account
                                             lt_glaccount
                                             lt_tax
                                             lt_withtax
                                             lt_vendor
                                             return
                                    USING    i_hd
                                    CHANGING ls_header
                                             ls_address
                                             be_data.

      CHECK return[] IS INITIAL.

      CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
        EXPORTING
          headerdata          = ls_header
          addressdata         = ls_address
        IMPORTING
          invoicedocnumber    = belnr
          fiscalyear          = gjahr
        TABLES
          itemdata            = lt_item
          accountingdata      = lt_account
          glaccountdata       = lt_glaccount
          taxdata             = lt_tax
          withtaxdata         = lt_withtax
          vendoritemsplitdata = lt_vendor
          return              = return.

      LOOP AT return WHERE type CA 'EA'.
        EXIT.
      ENDLOOP.

      IF sy-subrc = 0.
        REFRESH return. CLEAR return.
        CALL FUNCTION 'BAPI_INCOMINGINVOICE_PARK'
          EXPORTING
            headerdata          = ls_header
            addressdata         = ls_address
          IMPORTING
            invoicedocnumber    = belnr
            fiscalyear          = gjahr
          TABLES
            itemdata            = lt_item
            accountingdata      = lt_account
            glaccountdata       = lt_glaccount
            taxdata             = lt_tax
            withtaxdata         = lt_withtax
            vendoritemsplitdata = lt_vendor
            return              = return.
      ENDIF.
    ENDIF.

  ELSE.

*-------- non-PO invoice ----------------------------------------------*
    IF be_data-ivtype = c_ivtype_fi.
      CALL FUNCTION 'BBP_NON_PO_INVOICE'
        EXPORTING
          i_hd    = i_hd
          iv_simu = space
        IMPORTING
          e_belnr = belnr
          e_gjahr = gjahr
        TABLES
          ti_it   = ti_it
          ti_tax  = ti_tax
          ti_shp  = ti_shp
          ti_add  = ti_add
          ti_cmt  = ti_cmt
          ti_exr  = ti_exr
          return  = return
        EXCEPTIONS
          OTHERS  = 1.

      CHECK return[] IS INITIAL.

* ------- Obligo buchen ------------------------ *
      IF NOT ti_cmt IS INITIAL.
        REFRESH h_return. CLEAR h_return.
        CALL FUNCTION 'BBP_ACC_PURCHASE_ORDER_POST'
          EXPORTING
            i_with_commit = space
          TABLES
            purchaseorder = ti_cmt
            return        = h_return
          EXCEPTIONS
            error_message = 1
            OTHERS        = 2.
        CASE sy-subrc.
          WHEN 1.
            PERFORM fill_return TABLES return
                                USING sy-msgty
                                      sy-msgid
                                      sy-msgno
                                      sy-msgv1
                                      sy-msgv2
                                      sy-msgv3
                                      sy-msgv4.
          WHEN 2.
            PERFORM fill_return TABLES return
                                USING 'A'
                                      'M8'
                                      '008'
                                      'BBP_ACC_PURCHASE_ORDER_POST'
                                      ' ' ' ' ' '.
        ENDCASE.
        IF NOT h_return[] IS INITIAL.
          PERFORM fill_return TABLES return
                              USING  h_return-type
                                     h_return-id
                                     h_return-number
                                     h_return-message_v1
                                     h_return-message_v2
                                     h_return-message_v3
                                     h_return-message_v4.
        ENDIF.
      ENDIF.

*-------- PO invoice --------------------------------------------------*
    ELSE.
      CALL FUNCTION 'BBP_INVOICE_CREATE_4X'                 "#EC *
           EXPORTING
                i_hd          = i_hd
                be_data       = be_data
           IMPORTING
                e_belnr       = belnr
                e_gjahr       = gjahr
           TABLES
                ti_it         = ti_it
                ti_tax        = ti_tax
                ti_shp        = ti_shp
                ti_add        = ti_add
                ti_exr        = ti_exr
           EXCEPTIONS
                error_message = 1
                OTHERS        = 2.
      CASE sy-subrc.
        WHEN 1.
          PERFORM fill_return TABLES return
                              USING sy-msgty
                                    sy-msgid
                                    sy-msgno
                                    sy-msgv1
                                    sy-msgv2
                                    sy-msgv3
                                    sy-msgv4.
        WHEN 2.
          PERFORM fill_return TABLES return
                              USING 'A'
                                    'M8'
                                    '008'
                                    'BBP_INVOICE_CREATE_4X'
                                    ' ' ' ' ' '.
      ENDCASE.
    ENDIF.

* Gaps
  ENDIF.

*-------- country-specific extensions ---------------------------------*
  PERFORM icc_after_invoice TABLES  ti_it
                                    ti_tax
                                    ti_shp
                                    ti_add
                                    ti_cmt
                                    return
                           CHANGING i_hd
                                    be_data
                                    belnr
                                    gjahr.

* check for E- and A-messages
  LOOP AT return WHERE type CA 'EA'.
    EXIT.
  ENDLOOP.

* export document number if posted or deleted
  IF sy-subrc IS INITIAL.
    EXIT.
  ELSEIF NOT belnr IS INITIAL.
    IF be_data-release >= c_release_60 AND
       i_hd-exi_ind = 'X' AND
       i_hd-del_ind = 'X'.
      PERFORM fill_return TABLES return
                          USING 'I'
                                'M8'
                                '257'
                                belnr
                                ' ' ' ' ' '.
    ELSE.
      PERFORM fill_return TABLES return
                          USING 'I'
                                'M8'
                                '060'
                                belnr
                                ' ' ' ' ' '.
    ENDIF.
* add gjahr if a suitable message can be found
  ENDIF.

  e_belnr = belnr.
  e_gjahr = gjahr.

ENDFUNCTION.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_FROM_BACKEND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TI_IT  text                                                *
*      -->P_TI_TAX  text                                               *
*      -->P_TI_SHP  text                                               *
*      -->P_TI_ADD  text                                               *
*      -->P_TI_CMT  text                                               *
*      -->P_I_HD  text                                                 *
*      <--P_BE_DATA  text                                              *
*----------------------------------------------------------------------*
FORM get_data_from_backend TABLES   ti_it STRUCTURE bbp_iv_it
                                    ti_tax STRUCTURE bbp_iv_tax
                                    ti_shp STRUCTURE bbp_iv_shp
                                    ti_add STRUCTURE bbp_iv_add
                                    ti_cmt STRUCTURE bbpacpo01
                                    return STRUCTURE bapiret2
                           USING    i_hd STRUCTURE  bbp_iv_hd
                           CHANGING be_data STRUCTURE bbp_iv_be.

*-------- get release of backend system -------------------------------*
  CALL FUNCTION 'BBP_GET_RELEASE'
    IMPORTING
      ev_release_constant = be_data-release
      et_return           = return[]
    EXCEPTIONS
      OTHERS              = 0.

*-------- get t001 data -----------------------------------------------*
  CALL FUNCTION 'FI_COMPANY_CODE_DATA'
    EXPORTING
      i_bukrs       = i_hd-company
    IMPORTING
      e_t001        = t001
    EXCEPTIONS
      error_message = 1
      OTHERS        = 2.
  IF NOT sy-subrc IS INITIAL.
    PERFORM fill_return TABLES return
                        USING 'A'
                              'M8'
                              '008'
                              'FI_COMPANY_CODE_DATA'
                              ' ' ' ' ' '.
    EXIT.
  ENDIF.
  be_data-hwaer = t001-waers.
  be_data-ktopl = t001-ktopl.

*-------- get exchange rate -------------------------------------------*
  CALL FUNCTION 'READ_EXCHANGE_RATE'
    EXPORTING
      date             = sy-datlo
      foreign_currency = i_hd-currency
      local_currency   = be_data-hwaer
    IMPORTING
      exchange_rate    = be_data-rate
    EXCEPTIONS
      error_message    = 1
      OTHERS           = 2.
  IF NOT sy-subrc IS INITIAL.
    PERFORM fill_return TABLES return
                        USING 'A'
                              'M8'
                              '008'
                              'READ_EXCHANGE_RATE'
                              ' ' ' ' ' '.
    EXIT.
  ENDIF.

*-------- set parameters; call customer exit --------------------------*
  PERFORM document_type TABLES ti_it
                               ti_tax
                               ti_shp
                               ti_add
                         USING i_hd
                      CHANGING be_data.

*-------- determine type of invoice: PO or NON-PO ---------------------*
  IF NOT i_hd-mm_po_ind IS INITIAL.
    IF i_hd-mm_po_ind = 'J'.
      be_data-ivtype = c_ivtype_mm.
    ELSE.
      be_data-ivtype = c_ivtype_fi.
    ENDIF.
  ELSE.
*   check: does PO exist in backend ?
    LOOP AT ti_it WHERE po_number NE space.
      EXIT.
    ENDLOOP.
    SELECT SINGLE * FROM ekko WHERE ebeln = ti_it-po_number.
    IF sy-subrc IS INITIAL.
      be_data-ivtype = c_ivtype_mm.
    ELSE.
      be_data-ivtype = c_ivtype_fi.
    ENDIF.
  ENDIF.
ABAP Programlar
SAP Chain
SAP NetWeaver
ticket sistemimize katılın ve ücretsiz
10 adam gün kazanın >>
 Ana Sayfa  |  ABAP  |  FI  |  CO  |  MM  |  SD  |  PP  |  QM  |  HR  |  BW 
ykomut@gmail.com