创建总账科目类型会计凭证

 

datai_bukrs like t001-bukrs     value '1000',       "公司代码
      i_netwr like vbap-netwr     value 1,            "金额
      i_saknr like zsdt015-hkont  value '0066021001'"总账科目

perform frm_create_bkpf using i_bukrs i_netwr i_saknr.
*&---------------------------------------------------------------------*
*&      Form  frm_create_bkpf
*&---------------------------------------------------------------------*
form frm_create_bkpf using i_bukrs i_netwr i_saknr.

*----------------------- Data definition -------------------------------
  datalw_documentheader    type bapiache09,           "凭证抬头
        l_obj_type           type bapiache09-obj_type,
        l_obj_key            type bapiache09-obj_key,
        l_obj_sys            type bapiache09-obj_sys,

        lt_accountgl         type table of bapiacgl09,  "总账科目项
        lw_accountgl         type bapiacgl09,


        lt_currencyamount    type table of bapiaccr09,  "货币项目
        lw_currencyamount    type bapiaccr09,

        lt_return            type table of bapiret2,
        lw_return            type bapiret2,

        lt_extension2        type table of bapiparex,   "参考结构
        lw_extension2        type bapiparex,

        lc_msg_temp          type string.
*----------------------- header ----------------------------------------
  lw_documentheader-bus_act    'RFBU'.                     "业务事务
  lw_documentheader-username   sy-uname.                   "用户
  lw_documentheader-comp_code  i_bukrs.                    "公司代码

  lw_documentheader-doc_date   sy-datum.                   "凭证中的凭证日期
  lw_documentheader-pstng_date sy-datum.                   "凭证中的记帐日期
  lw_documentheader-doc_type   'SA'.                       "凭证类型,DZ:客户付款,SA:总账科目凭证
  lw_documentheader-header_txt '费用记账-收款单创建'.       "凭证抬头文本,这个必须要带上才能创建成功
*----------------------- Item ------------------------------------------
*---货币项目
  lw_currencyamount-itemno_acc 1.                          "行项目
  lw_currencyamount-currency   'CNY'.                      "货币
  lw_currencyamount-amt_doccur i_netwr.                    "金额
  append lw_currencyamount to lt_currencyamount.

  lw_currencyamount-itemno_acc 2.                          "行项目
  lw_currencyamount-currency 'CNY'.                        "货币
  lw_currencyamount-amt_doccur i_netwr.                "金额
  append lw_currencyamount to lt_currencyamount.

*---总账科目
  clear lw_accountgl.
  lw_accountgl-itemno_acc 1.                               "行项目
  lw_accountgl-gl_account '0066021501'.                    "总帐科目
  lw_accountgl-comp_code  i_bukrs.                         "公司代码
  lw_accountgl-costcenter '1000210056'.                    "成本中心
  append lw_accountgl to lt_accountgl.

  clear lw_accountgl.
  lw_accountgl-itemno_acc 2.                               "行项目
  lw_accountgl-gl_account '0021910012'.                    "总帐科目,?
  lw_accountgl-comp_code  i_bukrs.                         "公司代码
  append lw_accountgl to lt_accountgl.

*---扩展结构
  datalw_field_enhance type zfi_e_001.
  lw_field_enhance-posnr 2.
  lw_field_enhance-zz0001 '1201'.

  lw_extension2-structure 'ZFI_E_001'.
  lw_extension2-valuepart1 lw_field_enhance.
  append lw_extension2 to lt_extension2.


*---call bapi
  call function 'BAPI_ACC_DOCUMENT_POST'
    exporting
      documentheader lw_documentheader
    importing
      obj_type       l_obj_type
      obj_key        l_obj_key
      obj_sys        l_obj_sys
    tables
      accountgl      lt_accountgl
      currencyamount lt_currencyamount
      return         lt_return
      extension2     lt_extension2.

*---处理BAPI返回结果
  delete lt_return where type 'S' or type 'I' or type 'W'.
  if lt_return is initial.
    call function 'BAPI_TRANSACTION_COMMIT'
      exporting
        wait 'X'.
*    p_belnr     = l_obj_key(10).
  else.
    call function 'BAPI_TRANSACTION_ROLLBACK'.
  endif.

endform.                    " FRM_CREATE_BKPF

你可能感兴趣的:(创建总账科目类型会计凭证)