生成会记凭证

作者: Mmm_余安 | 来源:发表于2017-07-07 09:36 被阅读141次

    前台T-CODE:FB01
    调用BAPI : BAPI_ACC_DOCUMENT_POST

    • BAPI 行项目字段增强

    T-CODE SE11 创建结构,该结构包含了要增强的字段和行项目(该字段必须有)

    Paste_Image.png

    然后 T-CODE SE19 开始进行增强实施(有字段是BAPI里面没有需要新增时,需要建结构存储。例:反记账编码,记账码...)
    在 SE19 创建典型 BADI 输入 ACC_DOCUMENT 步骤如图

    Paste_Image.png

    进入以下界面点击增加,然后选会计凭证:

    Paste_Image.png

    点击保存后进入以下界面点击新建

    Paste_Image.png

    然后

    Paste_Image.png

    选中刚创建的


    Paste_Image.png

    然后回到 T-CODE SE19 界面,编辑实施界面输入刚才创建的实施名称,点更改

    Paste_Image.png

    进去后在实施累中双击第一个方法,将如下代码复制进去。

    Paste_Image.png Paste_Image.png

    传值要加前导0

    DATA: wa_extension TYPE bapiparex,
    ext_value(960) TYPE c, wa_accit TYPE accit,
    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>.
    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.
    ENDLOOP. ```
    
    到此增强部分就做完了,剩下的只要在 BAPI_ACC_DOCUMENT_POST 中的扩展表将参考结构和
    参考结构建的工作区(里面存放了要增强的字段的数据)分别赋给即可。
    
    * 调用代码
    
    ```DATA:
    GD_DOCUMENTHEADER LIKE BAPIACHE09,
    GD_CUSTOMERCPD LIKE BAPIACPA09,
    GD_FICA_HD LIKE BAPIACCAHD,
    IT_ACCOUNTRECEIVABLE LIKE TABLE OF BAPIACAR09 WITH HEADER LINE, "客户
    IT_ACCOUNTGL LIKE TABLE OF BAPIACGL09 WITH HEADER LINE, "总账科目
    IT_ACCOUNTTAX LIKE TABLE OF BAPIACTX09 WITH HEADER LINE, "税务项目
    IT_CRITERIA LIKE TABLE OF BAPIACKEC9 WITH HEADER LINE, "计记帐:CO-PA 科目
    分配特性
    IT_VALUEFIELD LIKE TABLE OF BAPIACKEV9 WITH HEADER LINE, "会计记帐:CO-PA 科
    目分配值字段
    IT_CURRENCYAMOUNT LIKE TABLE OF BAPIACCR09 WITH HEADER LINE, "货币项目
    IT_RETURN LIKE TABLE OF BAPIRET2 WITH HEADER LINE, "返回参数
    IT_RETURN1 LIKE TABLE OF BAPIRET2 WITH HEADER LINE, "返回参数
    IT_RECEIVERS LIKE TABLE OF BDI_LOGSYS WITH HEADER LINE, "传输逻辑系统的结
    构
    IT_FICA_IT LIKE TABLE OF BAPIACCAIT WITH HEADER LINE, "应收和应付附加合
    同帐户
    IT_ACCOUNTPAYABLE LIKE TABLE OF BAPIACAP09 WITH HEADER LINE, "供应商
    IT_PAYMENTCARD LIKE TABLE OF BAPIACPC09 WITH HEADER LINE, "付款卡信息
    IT_EXT LIKE TABLE OF BAPIACEXTC WITH HEADER LINE, "客户退出 参数的容器
    IT_RE LIKE TABLE OF BAPIACRE09 WITH HEADER LINE, "不动产科目分配数据
    IT_EXT2 LIKE TABLE OF BAPIPAREX WITH HEADER LINE, "扩展字段数据
    IT_EXTENSION LIKE TABLE OF BAPIACEXTC WITH HEADER LINE. "客户退出参数的容
    器
    DATA IT_EXTENSION2 LIKE BAPIPAREX OCCURS 0 WITH HEADER LINE. "扩展数据工作区
    DATA: WA_ZEXTEN LIKE ZEXTEN. "ZEXTEN 就是刚才 SE11 创建的
    那个结构```
    
    ```"抬头
    GD_DOCUMENTHEADER-USERNAME = SY-UNAME.
    GD_DOCUMENTHEADER-HEADER_TXT = '抬头文本'. "抬头文本
    GD_DOCUMENTHEADER-COMP_CODE = '2110'. "公司代码
    GD_DOCUMENTHEADER-DOC_DATE = '20161002'. "凭证日期
    GD_DOCUMENTHEADER-PSTNG_DATE = '20161002'. "过账日期
    GD_DOCUMENTHEADER-DOC_TYPE = 'KA'. "凭证类型
    GD_DOCUMENTHEADER-BUS_ACT = 'RFBU'. "业务事务
    GD_DOCUMENTHEADER-FIS_PERIOD = '10'. "会计期间
    GD_DOCUMENTHEADER-REF_DOC_NO = ''. "参考凭证编号
    "供应商
    IT_ACCOUNTPAYABLE-ITEMNO_ACC = '1'. "行项目编号
    IT_ACCOUNTPAYABLE-VENDOR_NO = '0110100023'. "科目
    IT_ACCOUNTPAYABLE-SP_GL_IND = '8'. "特殊总账
    IT_ACCOUNTPAYABLE-PMNTTRMS = 'Z030'. "付款条件
    IT_ACCOUNTPAYABLE-BLINE_DATE = '20161002'. "付款基准日期
    IT_ACCOUNTPAYABLE-ALLOC_NMBR = ''. "分配编号
    IT_ACCOUNTPAYABLE-ITEM_TEXT = '1'. "项目文本
    APPEND IT_ACCOUNTPAYABLE.
    * "客户(客户与供应商类似,有客户的就往客户内表增加值)
    * IT_ACCOUNTRECEIVABLE-ITEMNO_ACC = ''.
    * IT_ACCOUNTRECEIVABLE-CUSTOMER = ''.
    * IT_ACCOUNTRECEIVABLE-GL_ACCOUNT = ''.
    * IT_ACCOUNTRECEIVABLE-SP_GL_IND = ''.
    * IT_ACCOUNTRECEIVABLE-PMNTTRMS = ''.
    * IT_ACCOUNTRECEIVABLE-BLINE_DATE = ''.
    * IT_ACCOUNTRECEIVABLE-ALLOC_NMBR = ''.
    * IT_ACCOUNTRECEIVABLE-ITEM_TEXT = ''.
    * APPEND IT_ACCOUNTRECEIVABLE.
    "总账科目
    IT_ACCOUNTGL-ITEMNO_ACC = '2'. "行项目编号
    IT_ACCOUNTGL-GL_ACCOUNT = '1001000000'. "科目号
    IT_ACCOUNTGL-COSTCENTER = ''. "成本中心
    IT_ACCOUNTGL-TAX_CODE = ''. "税码
    IT_ACCOUNTGL-ALLOC_NMBR = ''. "分配编号
    IT_ACCOUNTGL-ITEM_TEXT = ''. "项目文本
    IT_ACCOUNTGL-ORDERID = ''. "销售订单号
    IT_ACCOUNTGL-WBS_ELEMENT = ''. "WBS 元素
    APPEND IT_ACCOUNTGL.
    
    "总账科目
    IT_ACCOUNTGL-ITEMNO_ACC = '3'. "行项目编号
    IT_ACCOUNTGL-GL_ACCOUNT = '8022000000'. "科目号
    IT_ACCOUNTGL-COSTCENTER = '0021100501'. "成本中心
    IT_ACCOUNTGL-TAX_CODE = 'J1'. "税码
    IT_ACCOUNTGL-ALLOC_NMBR = ''. "分配编号
    IT_ACCOUNTGL-ITEM_TEXT = ''. "项目文本
    IT_ACCOUNTGL-ORDERID = ''. "销售订单号
    IT_ACCOUNTGL-WBS_ELEMENT = ''. "WBS 元素
    APPEND IT_ACCOUNTGL.
    "货币
    IT_CURRENCYAMOUNT-ITEMNO_ACC ='1'. "项目编号
    IT_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货比码
    IT_CURRENCYAMOUNT-AMT_DOCCUR = '100'. "金额
    IT_CURRENCYAMOUNT-EXCH_RATE =''. "汇率
    APPEND IT_CURRENCYAMOUNT.
    "货币
    IT_CURRENCYAMOUNT-ITEMNO_ACC ='2'. "项目编号
    IT_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货比码
    IT_CURRENCYAMOUNT-AMT_DOCCUR = '-200'. "金额
    IT_CURRENCYAMOUNT-EXCH_RATE =''. "汇率
    APPEND IT_CURRENCYAMOUNT.
    "货币
    IT_CURRENCYAMOUNT-ITEMNO_ACC ='3'. "项目编号
    IT_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货比码
    IT_CURRENCYAMOUNT-AMT_DOCCUR = '100'. "金额
    IT_CURRENCYAMOUNT-EXCH_RATE ='0'. "汇率
    APPEND IT_CURRENCYAMOUNT.
    "税额
    DATA T_TAX_INFO TYPE STANDARD TABLE OF RTAX1U15 WITH HEADER LINE. "税务代码的
    税率和税收金额
    DATA:L_INDEX TYPE SY-TABIX. "内部表的行索引
    DATA:L_DMBTR LIKE BSEG-DMBTR. "金额
    DATA ZJE TYPE BSEG-DMBTR .
    ZJE = 100 .
    CALL FUNCTION 'CALCULATE_TAX_FROM_GROSSAMOUNT'
    EXPORTING
    I_BUKRS = '2110' "公司代码
    
    I_MWSKZ = 'J1' "税码
    I_WAERS = 'CNY' "币种
    I_WRBTR = ZJE "金额
    TABLES
    T_MWDAT = T_TAX_INFO. "税务代码的税率和税收金额
    DATA LS_CURRENCYAMOUNT LIKE LINE OF IT_CURRENCYAMOUNT. "货币项目
    DATA LS_ACCOUNTTAX LIKE LINE OF IT_ACCOUNTTAX. "税务项目
    DESCRIBE TABLE IT_CURRENCYAMOUNT LINES L_INDEX. "计算货币项目行数
    LOOP AT T_TAX_INFO.
    "向税额表中填充数据
    CLEAR LS_ACCOUNTTAX. "税务项目
    LS_ACCOUNTTAX-ITEMNO_ACC = '4'. "会计凭证行项目编号(有税的会
    自动新增一行行项目)
    LS_ACCOUNTTAX-TAX_CODE = 'J1'. "税码
    LS_ACCOUNTTAX-ACCT_KEY = T_TAX_INFO-KTOSL. "事务关键字
    LS_ACCOUNTTAX-COND_KEY = T_TAX_INFO-KSCHL. "条件类型
    LS_ACCOUNTTAX-TAXJURCODE = T_TAX_INFO-TXJCD. "地区税务代码
    LS_ACCOUNTTAX-TAXJURCODE_DEEP = T_TAX_INFO-TXJCD_DEEP. "地区税务代码
    LS_ACCOUNTTAX-TAXJURCODE_LEVEL = T_TAX_INFO-TXJLV. "税务法规级别
    APPEND LS_ACCOUNTTAX TO IT_ACCOUNTTAX. "税务项目
    "向金额表中填入相应的税额
    CLEAR LS_CURRENCYAMOUNT. "货币项目
    LS_CURRENCYAMOUNT-ITEMNO_ACC = LS_ACCOUNTTAX-ITEMNO_ACC. "会计凭证行项目编号
    LS_CURRENCYAMOUNT-CURRENCY = 'CNY'. "货币码
    LS_CURRENCYAMOUNT-AMT_DOCCUR = T_TAX_INFO-WMWST. "用凭证货币表示的税收金
    额
    LS_CURRENCYAMOUNT-AMT_BASE = T_TAX_INFO-KAWRT. "条件基价
    APPEND LS_CURRENCYAMOUNT TO IT_CURRENCYAMOUNT. "货币项目
    L_DMBTR = L_DMBTR + T_TAX_INFO-KAWRT. "金额 = 金额 + 条件基价
    ENDLOOP.
    "修正自动计算税额行的金额(由于实际计算出的不含税金额与系统计算会出现误
    差,故手工计算不含税金额)
    READ TABLE IT_CURRENCYAMOUNT INTO LS_CURRENCYAMOUNT WITH KEY ITEMNO_ACC = 1.
    IF SY-SUBRC = 0.
    LS_CURRENCYAMOUNT-AMT_DOCCUR = L_DMBTR. "金额
    MODIFY IT_CURRENCYAMOUNT FROM LS_CURRENCYAMOUNT INDEX SY-TABIX.
    ENDIF.
    "增强字段
    WA_ZEXTEN-POSNR = '2'. "凭证行项目
    WA_ZEXTEN-RSTGR = '111'. "凭证行项目原因代码
    WA_ZEXTEN-SKFBT = '100' . "折扣
    
    IT_EXTENSION2-STRUCTURE = 'ZEXTEN'.
    IT_EXTENSION2-VALUEPART1 = WA_ZEXTEN.
    APPEND IT_EXTENSION2.
    DATA: L_TYPE LIKE GD_DOCUMENTHEADER-OBJ_TYPE,
    L_KEY LIKE GD_DOCUMENTHEADER-OBJ_KEY,
    L_SYS LIKE GD_DOCUMENTHEADER-OBJ_SYS.
    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
    EXPORTING
    DOCUMENTHEADER = GD_DOCUMENTHEADER
    CUSTOMERCPD = GD_CUSTOMERCPD
    CONTRACTHEADER = GD_FICA_HD
    TABLES
    ACCOUNTGL = IT_ACCOUNTGL
    ACCOUNTRECEIVABLE = IT_ACCOUNTRECEIVABLE
    ACCOUNTPAYABLE = IT_ACCOUNTPAYABLE
    ACCOUNTTAX = IT_ACCOUNTTAX
    CURRENCYAMOUNT = IT_CURRENCYAMOUNT
    CRITERIA = IT_CRITERIA
    VALUEFIELD = IT_VALUEFIELD " EXTENSION1 = IT_EXTENSION
    EXTENSION2 = IT_EXTENSION2
    RETURN = IT_RETURN
    PAYMENTCARD = IT_PAYMENTCARD
    CONTRACTITEM = IT_FICA_IT
    REALESTATE = IT_RE.```
    
    
    *  备注
    1、根据情况对应的去传值
    2、在调用该 BAPI 之前,可以调用相应的检查函数看看错误 BAPI_ACC_DOCUMENT_CHECK。
    3、每有计算税的行项目,就需要额外产生一行税的项目,在批导循环的时候记得判断并计算相应
    的税。
    4、当特别总账为 W、X、Y、Z、U、V 时,该 BAPI 无效,此时可以用函数 POSTING_INTERFACE_DOCUMENT
    批量创建会计

    相关文章

      网友评论

        本文标题:生成会记凭证

        本文链接:https://www.haomeiwen.com/subject/loekhxtx.html