F-02/FB01 BAPI BAPI_ACC_DOCUMENT_POST

资产


 DATA:ls_head           LIKE bapiache09,
       lv_tabix          TYPE sy-tabix,
       lv_key            LIKE bapiache09-obj_key,
       lv_message        TYPE string,
       lv_message1       TYPE string,
       lv_itemno         TYPE posnr_acc,
       lv_hkont          TYPE bseg-hkont,
       lv_answer         TYPE char1,
       lt_accountgl      LIKE STANDARD TABLE OF bapiacgl09,
       ls_accountgl      LIKE bapiacgl09,
       lt_curramount     LIKE STANDARD TABLE OF bapiaccr09,
       ls_curramount     LIKE bapiaccr09,
       ls_extension1     LIKE bapiacextc,
       ls_extension2     LIKE bapiparex,
       lt_extension2     TYPE STANDARD TABLE OF bapiparex,
       ls_zexten         LIKE zsfi_bapi_exten,
       lv_ext_value(960) TYPE c,
       ls_return         LIKE bapiret2,
       lt_return         LIKE STANDARD TABLE OF bapiret2.

  CLEAR:lv_key,ls_return,ls_head.

  REFRESH:lt_accountgl,lt_curramount,lt_return,lt_extension2.

  ls_head-bus_act     = 'RFBU'.
  ls_head-username    = sy-uname.
  ls_head-comp_code   = p_bukrs.       "公司代码
  ls_head-doc_date    = gv_end_date.   "凭证日期 过账期间最后一天
  ls_head-pstng_date  = gv_end_date.   "过账日期
  ls_head-fisc_year   = p_gjahr.       "会计年度
  ls_head-fis_period  = p_monat.       "会计期间
  ls_head-doc_type    = 'AF'.          "凭证类型
  ls_head-header_txt  =  '模具工作量法折旧'.

  LOOP AT gt_data INTO gs_data.

    "40借方数据录入  40对应的科目:6600110300
    CLEAR lv_itemno.
    lv_itemno = lv_itemno + 1.               "行项目序号
    ls_accountgl-itemno_acc = lv_itemno.     "序号
    ls_accountgl-gl_account = '6600110300'.  "总账科目
    ls_accountgl-item_text  = '模具工作量法折旧'.  "凭证行文本 前台显示必输

    ls_accountgl-costcenter = gs_data-kostl.  "成本中心

    SELECT SINGLE gsber
    INTO ls_accountgl-bus_area" 业务范围
    FROM csks
    WHERE kokrs = '8000'
    AND kostl = gs_data-kostl
    AND datbi >= sy-datum.

    ls_accountgl-orderid   = gs_data-aufnr.   "订单号

    APPEND ls_accountgl TO lt_accountgl.
    CLEAR  ls_accountgl.

    ls_curramount-itemno_acc = lv_itemno.       "序号
    ls_curramount-currency   = 'CNY'.           "货币单位
    ls_curramount-amt_doccur = gs_data-zaufpri. "费用总金额
    APPEND ls_curramount TO lt_curramount .
    CLEAR  ls_curramount.

    CLEAR: ls_zexten,ls_extension2.
    ls_zexten-posnr = lv_itemno.          "凭证行项目
    ls_zexten-bschl  = '40'.       "记账码
    ls_extension2-structure  = 'ZSFI_BAPI_EXTEN'.
    ls_extension2-valuepart1 = ls_zexten.
    APPEND ls_extension2 TO lt_extension2.
    CLEAR: ls_zexten,ls_extension2.

    "75贷方数据录入 :75对应的科目:资产号、科目1801040000
    lv_itemno = lv_itemno + 1.                  "行项目序号
    ls_accountgl-itemno_acc = lv_itemno.        "序号
    ls_accountgl-gl_account = '1801040000'.    "总账科目
    ls_accountgl-asset_no = gs_data-anln1.      "资产号

    "    ls_accountgl-bus_area = 'ZD01'.
    ls_accountgl-sub_number = '0000'.           "次级编号
    ls_accountgl-acct_type = 'A'.               "账户类型

    ls_accountgl-costcenter = gs_data-kostl.     "成本中心
    ls_accountgl-item_text  =  '模具工作量法折旧'."凭证行文本
    APPEND ls_accountgl TO lt_accountgl.
    CLEAR  ls_accountgl.

    ls_curramount-itemno_acc = lv_itemno.       "序号
    ls_curramount-currency   = 'CNY'.           "货币单位
    ls_curramount-amt_doccur = gs_data-zaufpri  * ( -1 ). "费用总金额
    APPEND ls_curramount TO lt_curramount .
    CLEAR  ls_curramount.

    CLEAR: ls_zexten,ls_extension2.
    ls_zexten-posnr = lv_itemno.          "凭证行项目
    ls_zexten-bschl  ='.       "记账码
    ls_zexten-anbwa  = 'Z01'.       "业务类型
    ls_zexten-bzdat = sy-datum.    "资产价值日
    ls_extension2-structure  = 'ZSFI_BAPI_EXTEN'.
    ls_extension2-valuepart1 = ls_zexten.
    APPEND ls_extension2 TO lt_extension2.
    CLEAR: ls_zexten,ls_extension2.

    CLEAR:gs_data.

  ENDLOOP.

* 每一行数据对应2行数据
* 产生一张凭证,除非行数不够,自动拆分
  REFRESH: lt_return.
  CLEAR: ls_return,lv_key.

  CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
      documentheader = ls_head
    IMPORTING
      obj_key        = lv_key
    TABLES
      accountgl      = lt_accountgl
      currencyamount = lt_curramount
      return         = lt_return
      extension2     = lt_extension2.

  CLEAR:ls_return.
  READ TABLE lt_return INTO ls_return WITH KEY type = 'S'
                                                id  = 'RW'
                                                number = '605'.
  IF sy-subrc = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.


    "    gs_alv-bukrs  = lv_key+10(4).
    "    gs_alv-gjahr  = lv_key+14(4).
    "    gs_alv-zsign  = icon_green_light.
    "    gs_alv-budat  = sy-datum.

    "    MODIFY gt_data FROM gs_data TRANSPORTING belnr zmsg.

    "    MOVE-CORRESPONDING gs_alv TO gs_co001.
    "    gs_co001-mandt     = sy-mandt.
    "    gs_co001-zcre_name = sy-uname.
    "    gs_co001-zcre_date = sy-datum.
    "    gs_co001-zcre_time = sy-uzeit.
    "    APPEND gs_co001 TO gt_co001.
    "    CLEAR gs_alv.
    LOOP AT gt_data INTO gs_data.
      gs_data-zsign  = icon_green_light.
      gs_data-belnr  = lv_key+0(10).
      gs_data-zmsg   = '执行成功,生成的会计凭证:' && lv_key+0(10).
      MODIFY gt_data FROM gs_data TRANSPORTING zmsg zsign belnr.
      CLEAR gs_data.
    ENDLOOP.

    PERFORM frm_process_after_post."成功生成会计凭证后

  ELSE.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    CLEAR: lv_message.
    LOOP AT lt_return INTO ls_return WHERE ( type = 'E' OR type = 'A' )
    AND message IS NOT INITIAL.
      IF lv_message IS INITIAL.
        lv_message = ls_return-message.
      ELSE.
        CONCATENATE lv_message ls_return-message
        INTO lv_message SEPARATED BY '/'.
      ENDIF.
    ENDLOOP.

    "    gs_alv-zsign  = icon_red_light.
    CONCATENATE '入账失败,原因:'lv_message INTO DATA(lv_zmsg).
    LOOP AT gt_data INTO gs_data.
      gs_data-zmsg = lv_zmsg.
      gs_data-zsign  = icon_red_light.
      MODIFY gt_data FROM gs_data TRANSPORTING zmsg zsign.
      CLEAR gs_data.
    ENDLOOP.

  ENDIF.

注意:

1.这两个参数在业务类型anbwa不为空时必填,否则会报错

ls_accountgl-sub_number = '0000'. "次级编号

ls_accountgl-acct_type = 'A'. "账户类型

2.记账码不填默认40/50,其它值需要通过增强字段填入

增强badi:ACC_DOCUMENT 方法:IF_EX_ACC_DOCUMENT~CHANGE


  DATA: wa_extension   TYPE bapiparex,
        ext_value(960) TYPE c,
        wa_accit       TYPE accit,
        l_ref          TYPE REF TO data.

  DATA: gs_bapi_exten  TYPE zsfi_bapi_exten.                   "BADI增强扩展字段及结构
  DATA: gt_bapi_exten  TYPE STANDARD TABLE OF zsfi_bapi_exten. "BADI增强扩展字段及结构

  FIELD-SYMBOLS: <fs_accit> TYPE accit.

*  BREAK senchu7.
  IF c_extension2[] IS NOT INITIAL.
    LOOP AT c_extension2 INTO wa_extension WHERE structure = 'ZSFI_BAPI_EXTEN'.
      gs_bapi_exten = wa_extension-valuepart1.
      READ TABLE c_accit ASSIGNING <fs_accit> WITH KEY posnr = gs_bapi_exten-posnr.
      IF sy-subrc = 0.
        <fs_accit>-numpg = gs_bapi_exten-numpg.   "发票页数
        <fs_accit>-xnegp = gs_bapi_exten-xnegp.   "标识: 反记帐
        <fs_accit>-rstgr = gs_bapi_exten-rstgr.   "付款原因代码
        <fs_accit>-anbwa = gs_bapi_exten-anbwa.   "资产业务类型
        <fs_accit>-bzdat = gs_bapi_exten-bzdat.   "资产价值日
        <fs_accit>-zz01  = gs_bapi_exten-zz01.    "辅助客商
        <fs_accit>-zz02  = gs_bapi_exten-zz02.    "增减变动原因
        <fs_accit>-zz03  = gs_bapi_exten-zz03.    "往来款项类别
        <fs_accit>-zz04  = gs_bapi_exten-zz04.    "投融资产品
        <fs_accit>-zz05  = gs_bapi_exten-zz05.    "补助项目
        <fs_accit>-zz06  = gs_bapi_exten-zz06.    "预提费用
        <fs_accit>-zz07  = gs_bapi_exten-zz07.    "自主项目
        <fs_accit>-zz08  = gs_bapi_exten-zz08.    "合同号
        <fs_accit>-zz09  = gs_bapi_exten-zz09.    "人员档案
        <fs_accit>-zz10  = gs_bapi_exten-zz10.    "预留字段
        <fs_accit>-bschl  = gs_bapi_exten-bschl.   "记账代码  
        <fs_accit>-anbwa  = gs_bapi_exten-anbwa.   "业务类型  
      ENDIF.
    ENDLOOP.
  ENDIF.

也可采用通用方法


METHOD if_ex_acc_document~change .

***********************************************************************
* Example to move fields from BAPI parameter EXTENSION2 to structure  *
* ACCIT (accounting document line items).                             *
* The dictionary structure (content for EXTENSION2-STRUCTURE) must    *
* contain field POSNR, (TYPE POSNR_ACC) to indentify the correct line *
* item of the internal table ACCIT.                                   *
***********************************************************************

  DATA: wa_extension   TYPE bapiparex,
        ext_value(960) TYPE c,
        wa_accit       TYPE accit,
        wa_acchd       TYPE acchd,   " ins by zihua liang on 20160111
        l_ref          TYPE REF TO data.

  FIELD-SYMBOLS: <l_struc> TYPE any,
                 <l_field> TYPE any.

  SORT c_extension2 BY structure.

  LOOP AT c_extension2 INTO wa_extension.
    AT NEW structure.
      CREATE DATA l_ref TYPE (wa_extension-structure).
      ASSIGN l_ref->* TO <l_struc>.
    ENDAT.
    CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
                wa_extension-valuepart3 wa_extension-valuepart4
           INTO ext_value.
    MOVE ext_value TO <l_struc>.
    ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.
    IF sy-subrc EQ 0.
      READ TABLE c_accit WITH KEY posnr = <l_field>
            INTO wa_accit.
      IF sy-subrc IS INITIAL.
        MOVE-CORRESPONDING <l_struc> TO wa_accit.
        MODIFY c_accit FROM wa_accit INDEX sy-tabix.
      ENDIF.
    ELSE."增强凭证抬头   ins by zihua liang on 20160111
      MOVE-CORRESPONDING <l_struc> TO c_acchd.
    ENDIF.
  ENDLOOP.

*--------------------------------------------------------------------*begin F-47 bapi增强
  BREAK:lvsulei.

  FIELD-SYMBOLS <accit>     TYPE accit.
  DATA ls_extension2        TYPE bapiparex.

  IF c_extension2 IS NOT INITIAL.
    LOOP AT c_extension2 INTO ls_extension2 WHERE structure = 'ZEXTEN_PAYMENT'.

      IF ls_extension2-valuepart1 = 'BUS_ACT' AND ls_extension2-valuepart2 = 'RFST'.
*        c_acchd-glvor = 'RFST'.
        LOOP AT c_accit ASSIGNING <accit>.
          <accit>-bstat = 'S'.
          IF ls_extension2-valuepart3 IS NOT INITIAL.
            <accit>-zumsk = ls_extension2-valuepart3.
          ELSE.
            <accit>-zumsk = 'A'.
          ENDIF.
        ENDLOOP.

      ENDIF.
      IF ls_extension2-valuepart1 = 'BUS_ACT' AND ls_extension2-valuepart2 = 'WBS'.
        LOOP AT c_accit ASSIGNING <accit>.
          IF ls_extension2-valuepart3 IS NOT INITIAL.
            <accit>-ps_psp_pnr = ls_extension2-valuepart3.
          ENDIF.
        ENDLOOP.
      ENDIF.

      IF ls_extension2-valuepart1 = 'BUS_ACT' AND ls_extension2-valuepart2 = 'FDTAG'.
        LOOP AT c_accit ASSIGNING <accit>.
          IF ls_extension2-valuepart3 IS NOT INITIAL.
            <accit>-fdtag = ls_extension2-valuepart3.
          ENDIF.
        ENDLOOP.
      ENDIF.

      IF ls_extension2-valuepart1 = 'BUS_ACT' AND ls_extension2-valuepart2 = 'KIDNO'.
        LOOP AT c_accit ASSIGNING <accit>.
          IF ls_extension2-valuepart3 IS NOT INITIAL.
            <accit>-kidno = ls_extension2-valuepart3.
          ENDIF.
        ENDLOOP.
      ENDIF.
      "add by YIQIANG 20220823 新增参考码2赋值
      IF ls_extension2-valuepart1 = 'BUS_ACT' AND ls_extension2-valuepart2 = 'XREF2_HD'.
        LOOP AT c_accit ASSIGNING <accit>.
          IF ls_extension2-valuepart3 IS NOT INITIAL.
            <accit>-xref2_hd = ls_extension2-valuepart3.
          ENDIF.
        ENDLOOP.
      ENDIF.

      CLEAR ls_extension2.
    ENDLOOP.

  ENDIF.

*--------------------------------------------------------------------*end

ENDMETHOD.                    "IF_EX_ACC_DOCUMENT~CHANGE

问题记载

经测试出现该问题的原因是40必须对应H ,75对应S即(75对应的金额必须是负数,40对应的金额是正数)

客户类

 DATA:
    ls_header    LIKE bapiache09,
    lv_key       TYPE bapiache09-obj_key,
*    lt_accountpayable LIKE bapiacap09 OCCURS 0 WITH HEADER LINE,
    lt_accountgl LIKE bapiacgl09 OCCURS 0 WITH HEADER LINE,
    lt_cus       LIKE bapiacar09 OCCURS 0 WITH HEADER LINE,
    lt_currency  LIKE bapiaccr09 OCCURS 0 WITH HEADER LINE,
    lt_return    LIKE bapiret2   OCCURS 0 WITH HEADER LINE.
  DATA: lt_extension2 LIKE TABLE OF bapiparex,
        ls_extension2 LIKE bapiparex,
        ls_exten      TYPE zfi_s_extension.
  DATA:lv_item      TYPE i.

    CLEAR ls_header.
    ls_header-bus_act     = 'RFBU'.
    ls_header-comp_code    = gv_bukrs .
    ls_header-fisc_year    = p_gjahr .
    ls_header-fis_period   = p_monat.
    ls_header-doc_date     = sy-datum.
    ls_header-pstng_date   = gv_budat.
    ls_header-doc_type     = 'SA' .
    ls_header-username     = sy-uname .
    ls_header-header_txt   = |{ p_pspid }项目{ p_gjahr }年{ p_monat }月手工结算凭证|."'记账凭证' .

 CLEAR:lt_cus[],lt_accountgl[],lt_currency[],lt_extension2.
*-----行项目--
    CLEAR lv_item.
*----计算POC收入
    "-09----

    lv_item = lv_item + 1.

    "客户
    CLEAR lt_cus.
    lt_cus-itemno_acc  = lv_item.
    lt_cus-customer = ls_kna1-kndnr.
    lt_cus-comp_code = gv_bukrs.
    lt_cus-sp_gl_ind = 'E'.
    lt_cus-alloc_nmbr = <ls_tab>-posid.
    lt_cus-pmnttrms     = '0000'.
    APPEND lt_cus.

  "金额
    CLEAR lt_currency.
    lt_currency-itemno_acc = lv_item.
    lt_currency-currency = 'RMB'.
    CLEAR ls_cedj.
    READ TABLE lt_cedj INTO ls_cedj WITH KEY posid = <ls_tab>-posid.
    lt_currency-amt_doccur  = abs(  <ls_tab>-con_rel  - ls_cedj-con_rel ).
    APPEND lt_currency.

    CLEAR: ls_extension2,ls_exten.
    ls_exten-posnr     = lv_item .
*    ls_exten-anbwa = '100'.""业务类型
    ls_exten-bschl     = '09' .
    ls_exten-umskz     = 'X' .
    ls_extension2-structure  = 'ZFI_S_EXTENSION' .
    ls_extension2-valuepart1 = ls_exten .
    APPEND ls_extension2 TO lt_extension2.
    CLEAR ls_extension2.

*-------------------------------50---------------------------------*
    lv_item = lv_item + 1.
    CLEAR lt_accountgl.
    lt_accountgl-itemno_acc = lv_item.
    "科目
    lt_accountgl-gl_account = COND #( WHEN <ls_tab>-zstatus = '1' THEN '6001000130'
                                      WHEN <ls_tab>-zstatus = '2' THEN '6001000140'
                                      WHEN <ls_tab>-zstatus = '3' THEN '6001000150'  ).
    lt_accountgl-alloc_nmbr = <ls_tab>-posid.  "WBS
    lt_accountgl-wbs_element = <ls_tab>-posid.  "WBS
    APPEND lt_accountgl.

    CLEAR lt_currency.
    lt_currency-itemno_acc = lv_item.
    lt_currency-currency = 'RMB'.
    lt_currency-amt_doccur  = abs(  <ls_tab>-con_rel  - ls_cedj-con_rel ) * ( -1 ) .
    APPEND lt_currency.

    CLEAR :ls_extension2,ls_exten.
    ls_exten-posnr     = lv_item .
    ls_exten-bschl     = '50' .
    ls_extension2-structure  = 'ZFI_S_EXTENSION' .
    ls_extension2-valuepart1 = ls_exten .
    APPEND ls_extension2 TO lt_extension2.
    CLEAR ls_extension2.

注意三个必填字段:特殊总账标识umskz需要通过增强字段输入值,特殊总分类帐标志sp_gl_ind = 'E',付款条件代码PMNTTRMS。

一次性供应商赋值

 POST 函数将一次性供应商 的信息放在抬头入参上,业务需要多个一次性供应商一起做凭证时,就满足不了。
抬头入参会把所有行的一次性给一样的名称。
想起之前做的 IF_EX_ACC_DOCUMENT~CHANGE ,于是尝试了一下 ,发现可以解决

IF_EX_ACC_DOCUMENT~CHANGE

  "add by itl_csw 28.04.2023 15:50:49
  TYPES:BEGIN OF ty_accfi,  “c
          posnr TYPE posnr_acc,
          name1 TYPE name1_gp,
          ort01 TYPE ort01_gp,
        END OF ty_ACCFI.
  DATA ls_accfi TYPE ty_accfi.
  DATA lt_accfi TYPE TABLE OF ty_accfi.
  "end by itl_csw 28.04.2023 15:50:49

"add by itl_csw 28.04.2023 15:51:48
  IF c_accfi IS NOT INITIAL.
    IMPORT tab = lt_accfi FROM MEMORY ID 'LT_ACCFI'. “c
*    FREE MEMORY ID 'LT_ACCFI'.  check 会进来一次 不能清  在BAPI结束后再清“c
    IF lt_accfi IS NOT INITIAL.
      LOOP AT c_accfi ASSIGNING FIELD-SYMBOL(<fs_accfi>).
        READ TABLE lt_accfi INTO ls_accfi WITH KEY posnr = <fs_accfi>-posnr.
        IF sy-subrc = 0.
          <fs_accfi>-name1 = ls_accfi-name1.
          <fs_accfi>-ort01 = ls_accfi-ort01.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
  "end by itl_csw 28.04.2023 15:51:48

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值