22 мая 2019

FB01: счёт от кредитора с НДС (BAPI, а также предварительная регистрация)

Используется функциональный модуль BAPI_ACC_DOCUMENT_POST. Если поставить header-doc_status = '2', то документ будет предварительно зарегистрирован.



  DATA:
    ls_header TYPE bapiache09,
    lt_accountgl TYPE TABLE OF bapiacgl09,
    lt_accountpay TYPE TABLE OF bapiacap09,
    lt_accounttax TYPE TABLE OF bapiactx09,
    lt_currencyamount TYPE TABLE OF bapiaccr09,
    lt_return TYPE TABLE OF bapiret2,
    lv_obj_type TYPE bapiache02-obj_type,
    lv_obj_key TYPE bapiache02-obj_key,
    lv_obj_sys TYPE bapiache02-obj_sys,
    lv_bukrs TYPE bukrs,
    lv_waers TYPE waers,
    lv_mwskz TYPE mwskz,
    lv_wrbtr TYPE bseg-wrbtr,
    lt_mwdat TYPE TABLE OF rtax1u15.

  FIELD-SYMBOLS:
    <fs_accountgl>        LIKE LINE OF lt_accountgl,
    <fs_accountpay>       LIKE LINE OF lt_accountpay,
    <fs_accounttax>       LIKE LINE OF lt_accounttax,
    <fs_currencyamount>   LIKE LINE OF lt_currencyamount,
    <fs_mwdat>            LIKE LINE OF lt_mwdat.

  lv_bukrs = ''. " БЕ
  lv_waers = 'RUB'. " Валюта
  lv_mwskz = ''. " Код налога
  
  ls_header-bus_act = 'RFBU'.
  ls_header-username = sy-uname.
  ls_header-header_txt = ''.
  ls_header-comp_code = lv_bukrs.
  ls_header-doc_date = sy-datum.
  ls_header-pstng_date = sy-datum.
  ls_header-fisc_year = sy-datum+0(4).
  ls_header-fis_period = sy-datum+4(2).
  ls_header-doc_type = 'KR'.
  ls_header-ref_doc_no = 'N001-2019'.
*  ls_header-doc_status = '2'. " Если нужно предварительно зарегистрировать документ

  lv_wrbtr = 100.

  CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
    EXPORTING
      i_bukrs                       = lv_bukrs
      i_mwskz                       = lv_mwskz
*     i_txjcd                       = ' '
      i_waers                       = lv_waers
      i_wrbtr                       = lv_wrbtr
*     i_zbd1p                       = 0
*     i_prsdt                       =
*     i_protokoll                   =
*     i_taxps                       =
*     i_accnt_ext                   =
*     i_accdata                     =
*     is_enhancement                =
*     i_pricing_refresh_tx          = ' '
*   IMPORTING
*     e_fwnav                       =
*     e_fwnvv                       =
*     e_fwste                       =
*     e_fwast                       =
    TABLES
      t_mwdat                       = lt_mwdat
    EXCEPTIONS
      bukrs_not_found               = 1
      country_not_found             = 2
      mwskz_not_defined             = 3
      mwskz_not_valid               = 4
      account_not_found             = 5
      different_discount_base       = 6
      different_tax_base            = 7
      txjcd_not_valid               = 8
      not_found                     = 9
      ktosl_not_found               = 10
      kalsm_not_found               = 11
      parameter_error               = 12
      knumh_not_found               = 13
      kschl_not_found               = 14
      unknown_error                 = 15
      OTHERS                        = 16.

  IF sy-subrc EQ 0.
    READ TABLE lt_mwdat ASSIGNING <fs_mwdat> INDEX 1.
  ENDIF.

  INSERT INITIAL LINE INTO TABLE lt_accountpay ASSIGNING <fs_accountpay>.
  <fs_accountpay>-itemno_acc = 1.
  <fs_accountpay>-vendor_no = 'VENDOR0001'.
  <fs_accountpay>-item_text = ''.
  <fs_accountpay>-tax_code = lv_mwskz.

  INSERT INITIAL LINE INTO TABLE lt_currencyamount ASSIGNING <fs_currencyamount>.
  <fs_currencyamount>-itemno_acc = 1.
  <fs_currencyamount>-curr_type = '00'.
  <fs_currencyamount>-currency = lv_waers.
  <fs_currencyamount>-amt_doccur = -1 * 120.

  INSERT INITIAL LINE INTO TABLE lt_accountgl ASSIGNING <fs_accountgl>.
  <fs_accountgl>-itemno_acc = 2.
  <fs_accountgl>-gl_account = '0000100000'.
  <fs_accountgl>-item_text = ''.
  <fs_accountgl>-costcenter = ''.
  <fs_accountgl>-plant = ''.
  <fs_accountgl>-tax_code = lv_mwskz.

  INSERT INITIAL LINE INTO TABLE lt_currencyamount ASSIGNING <fs_currencyamount>.
  <fs_currencyamount>-itemno_acc = 2.
  <fs_currencyamount>-curr_type = '00'.
  <fs_currencyamount>-currency = lv_waers.
  <fs_currencyamount>-amt_doccur = lv_wrbtr.

  IF <fs_mwdat> IS ASSIGNED.

    INSERT INITIAL LINE INTO TABLE lt_accounttax ASSIGNING <fs_accounttax>.
    <fs_accounttax>-itemno_acc = 3.
*    <fs_accounttax>-gl_account = <fs_mwdat>-hkont.
    <fs_accounttax>-tax_code = lv_mwskz.

    INSERT INITIAL LINE INTO TABLE lt_currencyamount ASSIGNING <fs_currencyamount>.
    <fs_currencyamount>-itemno_acc = 3.
    <fs_currencyamount>-curr_type = '00'.
    <fs_currencyamount>-currency = lv_waers.
    <fs_currencyamount>-amt_doccur = 20.
    <fs_currencyamount>-amt_base = 100.

  ENDIF.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader          = ls_header
*     customercpd             =
*     contractheader          =
*   IMPORTING
*     obj_type                =
*     obj_key                 =
*     obj_sys                 =
    TABLES
      accountgl               = lt_accountgl
*     accountreceivable       =
      accountpayable          = lt_accountpay
      accounttax              = lt_accounttax
      currencyamount          = lt_currencyamount
*     criteria                =
*     valuefield              =
*     extension1              =
      return                  = lt_return
*     paymentcard             =
*     contractitem            =
*     extension2              =
*     realestate              =
*     accountwt               =
            .

  LOOP AT lt_return TRANSPORTING NO FIELDS
    WHERE type CA 'EAX'.
    EXIT.
  ENDLOOP.

  IF sy-subrc NE 0.
    COMMIT WORK.
  ELSE.
    ROLLBACK WORK.
  ENDIF.

Комментариев нет:

Отправить комментарий