F-47

*&---------------------------------------------------------------------*
*&   F-47过账
*&---------------------------------------------------------------------*
    DATA ls_bapiheader        TYPE bapiache09.                    " DOCUMENTHEADER
    DATA ls_zbseg             TYPE zbseg.                         " 增强结构   记账码 原因代码 反记账标识
    DATA is_extension2        TYPE bapiparex  .                   " BAPI 参数 xtensionIn/ExtensionOut 的参考结构
    DATA it_extension2        TYPE STANDARD TABLE OF bapiparex  . " BAPI 参数 ExtensionIn/ExtensionOut 的参考结构
    DATA is_return2           TYPE bapiret2   . " 返回参数
    DATA it_return2           TYPE STANDARD TABLE OF bapiret2   . " 返回参数
    DATA is_currencyamount    TYPE bapiaccr09.                    " 货币项目
    DATA it_currencyamount    TYPE STANDARD TABLE OF bapiaccr09 . " 货币项目
    DATA it_accountpayable    TYPE STANDARD TABLE OF bapiacap09 . " 供应商项目
    DATA is_accountpayable    TYPE bapiacap09 . " 供应商项目

" HEADER
              ls_bapiheader-doc_date   = <fs_input>-is_header-budat.        " 凭证中的凭证日期
              ls_bapiheader-pstng_date = <fs_input>-is_header-budat.        " 凭证中的过帐日期
              ls_bapiheader-fisc_year  = <fs_input>-is_header-budat+0(4).   " 财年
              ls_bapiheader-fis_period = <fs_input>-is_header-budat+4(2).   " 会计期间
              ls_bapiheader-bus_act  = 'RFST'.                              " 业务事务
              ls_bapiheader-doc_type = 'KZ'.

   " ITEM
              LOOP AT <fs_input>-it_table INTO ls_table.

                " 10
                lv_index = lv_index + 10.
                " 增强结构
                CLEAR: is_extension2.
                CLEAR: ls_zbseg.
                ls_zbseg-posnr = lv_index .
                ls_zbseg-bschl = '39'.                " 过账码
                ls_zbseg-numpg = <fs_input>-is_header-numpg. " 发票的页数
                ls_zbseg-umskz = 'F'.                 " 特殊总账标识
                ls_zbseg-xref1 = '201'.
                ls_zbseg-xref2 = 'SSF'.
                is_extension2-structure  = 'ZBSEG'.
                is_extension2-valuepart1 = ls_zbseg.
                APPEND is_extension2 TO it_extension2.

                " 货币项目
                CLEAR is_currencyamount.
                is_currencyamount-itemno_acc = lv_index .
                is_currencyamount-currency   = 'RMB'.     " 货币
                is_currencyamount-amt_doccur = ls_table-dmbtr * -1.
                is_currencyamount-exch_rate  = ''.                            " 汇率
                APPEND is_currencyamount TO it_currencyamount.

                " 供应商项目
                CLEAR is_accountpayable.
                is_accountpayable-comp_code  = <fs_input>-is_header-bukrs.    " 公司代码
                is_accountpayable-itemno_acc = lv_index .                     " 会计凭证行项目编号
                is_accountpayable-vendor_no  = ls_table-hkont.                " 供应商或债权人的帐号
                is_accountpayable-vendor_no  = |{ is_accountpayable-vendor_no ALPHA = IN }|.    " 供应商或债权人的帐号
                SELECT SINGLE name1 FROM lfa1 INTO ls_table-ref03 WHERE lifnr = is_accountpayable-vendor_no. " 供应商描述
                is_accountpayable-profit_ctr = ls_table-prctr.                                  " 利润中心
                is_accountpayable-profit_ctr = |{ is_accountpayable-profit_ctr ALPHA = IN }|.   " 利润中心
                SELECT SINGLE prctr FROM zcwgx_conf_002
                INTO @lv_prctr WHERE zprctr = @is_accountpayable-profit_ctr.
                IF lv_prctr IS NOT INITIAL.
                  is_accountpayable-profit_ctr = |{ lv_prctr ALPHA = IN }|.
                ENDIF.
                is_accountpayable-item_text  = ls_table-ref01 && ',' && <fs_input>-is_header-ref01 && '请付' && ls_table-ref03 && ls_table-ref02.  " 项目文本
                is_accountpayable-sp_gl_ind  = 'F'.            " 特殊总分类帐标志
                IF ls_table-zlsch = 'ZKF02'.
                  is_accountpayable-pymt_meth = 'B'.           " 支付方式
                ELSEIF ls_table-zlsch = 'ZFK01'.
                  is_accountpayable-pymt_meth = 'I'.           " 支付方式
                ENDIF.
                is_accountpayable-bline_date = ls_table-zfbdt. " 到期付款日期
                is_accountpayable-alloc_nmbr = ls_table-zuonr. " 分配号
                APPEND is_accountpayable TO it_accountpayable.

                CLEAR ls_table.
              ENDLOOP.

" 过账
                CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
                  EXPORTING
                    documentheader    = ls_bapiheader
                  TABLES
                    accountgl         = it_accountgl
                    accountpayable    = it_accountpayable
                    accountreceivable = it_accountreceivable
                    currencyamount    = it_currencyamount
                    return            = it_return
                    extension2        = it_extension2.

                CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
                  EXPORTING
                    wait = 'X'.

 

上一篇:LeetCode刷题记69-47. 全排列 II


下一篇:2020.12.14vj补题