BAPI_ACC_DOCUMENT_POST导入外币凭证

使用 BAPI_ACC_DOCUMENT_POST 导入外币凭证有两种方法。

  • 方法一: 将 header 币别设置为外币,然后在行项目中指定外币金额,SAP 根据系统汇率自动确定汇率和本位币金额
  • 方法二: 将 header 币别设置为外币,然后在行项目中同时指定本位币和外币的金额

基于测试和演示目的,数据使用硬编码。

方法一:

*&---------------------------------------------------------------------*
*& Report  Z_BAPI_AC_DOCUMENT_POST_TEST
*&
*&---------------------------------------------------------------------*


report  z_bapi_ac_document_post_test.

data:
  ls_docheader      like bapiache09,                           " structure of document header
  lt_accountgl      like bapiacgl09 occurs 0 with header line, " internal table for gl accounts
  lt_currencyamount like bapiaccr09 occurs 0 with header line, " internal table for currency
  lt_return         like bapiret2   occurs 0 with header line. " internal table for return

* Populate required values
data: l_cocd    type bukrs value 'Z900',                    " company code
      l_curr    type bapiaccr09-currency value 'USD',
      l_doctype type bapiache09-doc_type value 'SA'.

data: wa_return like line of lt_return. " return value

start-of-selection.
  perform populate_doc_header.
  perform populate_gl_accounts.
  perform populate_currency_amt.
  perform generate_fi_document.

*&---------------------------------------------------------------------*
*&      Form  populate_doc_header
*&---------------------------------------------------------------------*
form populate_doc_header.
  clear ls_docheader.

  ls_docheader-bus_act = 'RFBU'.
  ls_docheader-username = sy-uname.
  ls_docheader-header_txt = 'Test FI doc using BAPI'.
  ls_docheader-comp_code = l_cocd.  " company code
  ls_docheader-doc_date = sy-datum.
  ls_docheader-pstng_date = sy-datum.
  ls_docheader-doc_type = l_doctype.
endform.                    "populate_doc_header

*&---------------------------------------------------------------------*
*&      Form  populate_gl_accounts
*&---------------------------------------------------------------------*
form populate_gl_accounts.
  clear lt_accountgl.

  lt_accountgl-itemno_acc = '1'.
  lt_accountgl-gl_account = '0010010100'.
  lt_accountgl-comp_code = l_cocd.
  lt_accountgl-pstng_date = sy-datum.
  lt_accountgl-doc_type = l_doctype.
  lt_accountgl-item_text = '外币凭证测试'.
  append lt_accountgl.

  clear lt_accountgl.
  lt_accountgl-itemno_acc = '2'.
  lt_accountgl-gl_account = '0010020100'.
  lt_accountgl-comp_code = l_cocd.
  lt_accountgl-pstng_date = sy-datum.
  lt_accountgl-value_date = sy-datum.
  lt_accountgl-doc_type = l_doctype.
  lt_accountgl-item_text = '外币凭证测试'.
  append lt_accountgl.
endform.                    "populate_gl_accounts

*&---------------------------------------------------------------------*
*&      Form  populate_currency_amt
*&---------------------------------------------------------------------*
form populate_currency_amt.
  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '1'.
  lt_currencyamount-curr_type = '00'.  " document currency
  lt_currencyamount-currency = 'USD'.
  lt_currencyamount-amt_doccur = '100.00'.
  append lt_currencyamount.

  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '2'.
  lt_currencyamount-curr_type = '00'.  " document currency
  lt_currencyamount-currency = 'USD'.
  lt_currencyamount-amt_doccur = '-100.00'.
  append lt_currencyamount.
endform.                    "populate_currency_amt

*&---------------------------------------------------------------------*
*&      Form  generate_fi_document
*&---------------------------------------------------------------------*
form generate_fi_document.
  call function 'BAPI_ACC_DOCUMENT_POST'
    exporting
      documentheader = ls_docheader
    tables
      accountgl      = lt_accountgl[]
      currencyamount = lt_currencyamount[]
      return         = lt_return[].

  read table lt_return into wa_return with key type = 'E'.
  if not sy-subrc is initial.  " sy-subrc with rows will return 0
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait = 'X'.

    read table lt_return into wa_return index 1.
    write wa_return-message.
  else.
    loop at lt_return into wa_return where type = 'E'.
      write: wa_return-message.
      clear wa_return.
    endloop.
  endif.
endform.                    "generate_fi_document

效果:


方法二:修改 populate_currency_amt.。每一行在 lt_currencyamount 内表中用两行来表示,通过 curr_type 来区分。 00 表示凭证币别,10 表示本位币。

form populate_currency_amt.
  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '1'.
  lt_currencyamount-curr_type = '00'.  " document currency
  lt_currencyamount-currency = 'USD'.
  lt_currencyamount-amt_doccur = '100.00'.
  append lt_currencyamount.

  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '1'.
  lt_currencyamount-curr_type = '10'.  " company code currency
  lt_currencyamount-currency = 'CNY'.
  lt_currencyamount-amt_doccur = '710.00'.
  append lt_currencyamount.

  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '2'.
  lt_currencyamount-currency = 'USD'.
  lt_currencyamount-curr_type = '00'.  " document currency
  lt_currencyamount-amt_doccur = '-100.00'.
  append lt_currencyamount.


  clear lt_currencyamount.
  lt_currencyamount-itemno_acc = '2'.
  lt_currencyamount-curr_type = '10'.  " company code currency
  lt_currencyamount-currency = 'CNY'.
  lt_currencyamount-amt_doccur = '-710.00'.
  append lt_currencyamount.
endform.                    "populate_currency_amt

效果:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值