文章目录
- 主要程序
- 创建程序
- 程序
- 代码解析
- 变量定义
- 抬头和项目初始值
- 表头赋值
- 调用BAPI
- 其他的子例程
- 核心内表
- 增强部分
- LFACIF5D程序
- FI_DOCUMENT_CHECK
- 完整程序
- BADI增强
主要程序
创建程序
程序
&---------------------------------------------------------------------*
*& Report Z_TEST_LHY
*& Description:测试调用BAPI 创建预制凭证和会计凭证
*& Create On:2024年6月4日
*& Creater:Liuhongyu
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_test_lhy.
TYPES: BEGIN OF typ_head,bldat TYPE bkpf-bldat, "凭证日期budat TYPE bkpf-budat, "过账日期blart TYPE bkpf-blart, "凭证类型bukrs TYPE bkpf-bukrs, "公司代码monat TYPE bkpf-monat, "过账期间waers TYPE bkpf-waers, "币种bktxt TYPE bkpf-bktxt, "凭证抬头文本kursf TYPE bkpf-kursf, "汇率numpg TYPE bkpf-numpg, "发票的页数num TYPE char10, "索引END OF typ_head.
TYPES: BEGIN OF typ_item,num TYPE char10, "凭证顺序号bschl TYPE bseg-bschl, "记账码 "系统根据金额正负自动设置hkont TYPE bseg-hkont, "科目umskz TYPE bseg-umskz, "特别总账标识rstgr TYPE bseg-rstgr, "原因代码 "RSTGRkkber TYPE bseg-kkber, "信贷控制范围wrbtr TYPE bseg-wrbtr, "原币金额dmbtr TYPE bseg-dmbtr, "本币金额mwskz TYPE bseg-mwskz, "税码
* dmbtr TYPE bapiaccr09-amt_doccur, "本币金额zterm TYPE bseg-zterm, "付款条件kostl TYPE bseg-kostl, "成本中心aufnr TYPE bseg-aufnr, "内部订单prctr TYPE bseg-prctr, "利润中心zfbdt TYPE bseg-zfbdt, "收付款基准日期* zzwwjsh TYPE char10, "外围结算号xref1 TYPE bseg-xref1,zuonr TYPE bseg-zuonr, "分配/外围单号sgtxt TYPE bseg-sgtxt, "凭证行项目文本xnegp TYPE bseg-xnegp, "反记账
* wname TYPE bsed-wname, "收票人 "没有写进bapi
* wbzog TYPE bsed-wbzog, "出票人 "没有写进bapi* menge TYPE bseg_add-menge, "数量
* meins TYPE bseg_add-meins, "单位wdate TYPE bsed-wdate, "汇票签发日 "没有写进bapiprojk TYPE char24, "工作分解结构元素 (WBS 元素)zbd1t TYPE bseg-zbd1t, "现金折旧天数hkont_a TYPE bseg-hkont, "备选总账科目??netdt TYPE acdoca-netdt, "到期日期wstat TYPE t031t-txt30, "汇票状态
* wdate TYPE bsed-wdate, "签发日期wname TYPE bsed-wname, "收款人wort2 TYPE bsed-wort2, "收票人城市wbzog TYPE bsed-wbzog, "付款人wort1 TYPE bsed-wort1, "出票人城市matnr TYPE char18, "bseg-matnr, "物料号vbel2 TYPE bseg-vbel2, "销售订单CHENYL 20211018posn2 TYPE bseg-posn2, "销售订单CHENYL 20211018anln1 TYPE bseg-anln1, "资产-,CHENYLebeln TYPE bseg-ebeln, "采购凭证CHENYLebelp TYPE bseg-ebelp, "采购凭证CHENYLkunnr TYPE kna1-kunnr,werks TYPE werks_d,vkorg TYPE vbrk-vkorg, "销售组织vtweg TYPE vbak-vtweg, "分销渠道bewar TYPE bseg-bewar, "事务类型END OF typ_item.
DATA: gs_head TYPE typ_head,gt_head TYPE TABLE OF typ_head.
DATA: gs_item TYPE typ_item,gt_item TYPE TABLE OF typ_item.
DATA: gs_t001 TYPE t001,gt_t001 LIKE TABLE OF gs_t001.
DATA: gs_tbsl TYPE tbsl,gt_tbsl LIKE TABLE OF gs_tbsl.
DATA: gs_documentheader LIKE bapiache09. "表头
DATA: gs_accountgl LIKE bapiacgl09,gt_accountgl LIKE TABLE OF bapiacgl09, "总帐科目项gs_currencyamount LIKE bapiaccr09,gt_currencyamount LIKE TABLE OF bapiaccr09, "货币项目gs_return LIKE bapiret2,gt_return LIKE TABLE OF bapiret2,gs_extension2 LIKE bapiparex,gt_extension2 LIKE TABLE OF bapiparex,gs_accountreceivable LIKE bapiacar09, "客户项目gt_accountreceivable LIKE TABLE OF bapiacar09,gs_accountpayable LIKE bapiacap09, "供应商项目gt_accountpayable LIKE TABLE OF bapiacap09.DATA: ls_zfidoc TYPE zfis002. "定义增强点结构DATA: ls_head LIKE gs_head.
DATA: BEGIN OF ls_bsed,wdate TYPE bsed-wdate, "汇票签发日wstat TYPE t031t-txt30, "汇票状态wname TYPE bsed-wname, "收款人wort2 TYPE bsed-wort2, "收票人城市wbzog TYPE bsed-wbzog, "付款人wort1 TYPE bsed-wort1, "出票人城市END OF ls_bsed.
DATA: lt_bsed LIKE TABLE OF ls_bsed.
DATA: BEGIN OF gt_anbwa OCCURS 0,posnr LIKE accit-posnr,bschl LIKE bseg-bschl,anbwa LIKE accit-anbwa,END OF gt_anbwa.
* ============================★ 应付类 START ★==============================
"应付类可以生成成功
* "如需要使用该抬头可以取消注释
*"-------------应付类抬头赋值 START $-------------------------------
*
*gs_head = VALUE #( bldat = '20240725' "凭证日期
* budat = '20240725' "过账日期
* blart = 'KZ' "凭证类型
* bukrs = '1000' "公司代码
* monat = '7' "期间
* waers = 'CNY' "币种
* bktxt = '支付联星焊接30%发货款-Z_TEST_LHY程序创建' "抬头文本
* numpg = '000'
* num = '1'
* ).
*APPEND gs_head TO gt_head.
*"-------------应付类抬头赋值 END $--------------------------------
*
*
*"项目赋值
**------应付类项目3 START $--------------*
*"原来是项目3的,现在换成项目1 ,因为这样才有收款人等信息!!!!
*gs_item-bschl = '19'. "记账码
*gs_item-hkont = |{ '100961' ALPHA = IN }|. "总账科目
*gs_item-umskz = 'W'. "特别总账标识
*gs_item-wrbtr = '500'. "金额
*gs_item-sgtxt = '支付联星焊接30%发货款-Z_TEST_LHY程序创建'."项目文本
*gs_item-wdate = '20240501'. "签发日期
*gs_item-netdt = '20240825'. "到期日期
*gs_item-wname = '珠海市联星焊接设备有限公司'. "收款人
*gs_item-wort2 = '中国光大银行股份有限公司XXXX支行'. "汇票受票人所在的城市
*gs_item-wbzog = '广东XXXX铝材股份有限公司'. "付款人
*gs_item-wort1 = '123456789123456789'. "汇票出票人所在的城市
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应付类项目3 END $--------------*
*
**------应付类项目1 START $--------------*
*gs_item-bschl = '29'. "记账码
*gs_item-hkont = |{ '100026' ALPHA = IN }|. "总账科目
*gs_item-umskz = 'A'. "特别总账标识
*gs_item-wrbtr = '1000'. "金额
*gs_item-sgtxt = '支付联星焊接30%发货款-Z_TEST_LHY程序创建'."项目文本
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应付类项目1 END $--------------*
*
**------应付类项目2 START $--------------*
*gs_item-bschl = '50'. "记账码
*gs_item-hkont = |{ '10020005' ALPHA = IN }|. "总账科目
*gs_item-wrbtr = '500'. "金额
*gs_item-rstgr = '220'. "原因代码
*gs_item-sgtxt = '支付联星焊接30%发货款-Z_TEST_LHY程序创建'."项目文本
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应付类项目2 END $--------------*
* ============================★ 应付类 END ★==============================* ============================★ 报销类 START ★==============================
"对应的文档:D:\File\Self\任务\20240725_SAP自动生成凭证所需字段V5.0_lhy.xlsx TIME: AT 2024.07.30*"-------------报销类抬头赋值 START $-------------------------------gs_head = VALUE #( bldat = '20240531' "凭证日期budat = '20240531' "过账日期blart = 'SA' "凭证类型bukrs = '1000' "公司代码monat = '5' "期间waers = 'CNY' "币种bktxt = '支付张三费用报销-Z_TEST_LHY程序创建' "抬头文本numpg = '000'num = '1').
APPEND gs_head TO gt_head.
*"-------------报销类抬头赋值 END $--------------------------------*"-------------报销类项目赋值 START $-------------------------------
"对应的文档:D:\File\Self\任务\20240725_SAP自动生成凭证所需字段V5.0_lhy.xlsx TIME: AT 2024.07.30*------报销类项目1 START $--------------*
gs_item-bschl = '40'. "记账码
gs_item-hkont = |{ '66010034' ALPHA = IN }|. "总账科目
gs_item-wrbtr = '1769.91'. "金额
gs_item-mwskz = 'J0'. "税码
gs_item-kostl = |{ '100011007' ALPHA = IN }|. "成本中心100011007
gs_item-sgtxt = '支付张三费用报销-Z_TEST_LHY程序创建'."项目文本
APPEND gs_item TO gt_item.
CLEAR gs_item.
*------报销类项目1 END $--------------**------报销类项目2 START $--------------*
gs_item-bschl = '40'. "记账码
gs_item-hkont = |{ '66010035' ALPHA = IN }|. "总账科目
gs_item-wrbtr = '3000'. "金额
gs_item-mwskz = 'J0'. "税码
gs_item-kostl = |{ '100011007' ALPHA = IN }|. "成本中心100011007
gs_item-sgtxt = '支付张三费用报销-Z_TEST_LHY程序创建'."项目文本
APPEND gs_item TO gt_item.
CLEAR gs_item.
*------报销类项目2 END $--------------**------报销类项目3 START $--------------*
gs_item-bschl = '40'. "记账码
gs_item-hkont = |{ '22210001' ALPHA = IN }|. "总账科目
gs_item-wrbtr = '230.09'. "金额
gs_item-sgtxt = '支付张三费用报销-Z_TEST_LHY程序创建'."项目文本
APPEND gs_item TO gt_item.
CLEAR gs_item.
*------报销类项目3 END $--------------**------报销类项目4 START $--------------*
gs_item-bschl = '34'. "记账码
gs_item-hkont = |{ '200020' ALPHA = IN }|. "科目,后面会放到供应商字段
gs_item-hkont_a = |{ '12210001' ALPHA = IN }|. "科目,备选总账科目?
gs_item-wrbtr = '1000'. "金额
gs_item-sgtxt = '支付张三费用报销-Z_TEST_LHY程序创建'."项目文本
APPEND gs_item TO gt_item.
CLEAR gs_item.
*------报销类项目4 END $--------------**------报销类项目5 START $--------------*
gs_item-bschl = '50'. "记账码
gs_item-hkont = |{ '10020005' ALPHA = IN }|. "总账科目10020005
gs_item-wrbtr = '4000'. "金额
gs_item-rstgr = '251'. "原因代码
gs_item-sgtxt = '支付张三费用报销-Z_TEST_LHY程序创建'."项目文本
APPEND gs_item TO gt_item.
CLEAR gs_item.
*------报销类项目5 END $--------------***"-------------报销类项目赋值 END $-------------------------------* ============================★ 应收类 END ★==============================* ============================★ 应收类 START ★==============================
"应收类可以生成成功
**"-------------应收类抬头赋值 START $-------------------------------
*
*gs_head = VALUE #( bldat = '20240531' "凭证日期
* budat = '20240531' "过账日期
* blart = 'DZ' "凭证类型
* bukrs = '1000' "公司代码
* monat = '5' "期间
* waers = 'CNY' "币种
* bktxt = '收到客户3月货款-Z_TEST_LHY程序创建' "抬头文本
* numpg = '000'
* num = '1'
* ).
*APPEND gs_head TO gt_head.
**"-------------应收类抬头赋值 END $--------------------------------
*
**"-------------应收类项目赋值 START $-------------------------------
**------应收类项目1 START $--------------*
*gs_item-bschl = '09'. "记账码
*gs_item-hkont = |{ '100961' ALPHA = IN }|. "总账科目
*gs_item-umskz = 'W'. "特别总账标识
*gs_item-wrbtr = ' 10000.00 '. "金额
*gs_item-sgtxt = '收到客户3月货款-Z_TEST_LHY程序创建'."项目文本
*gs_item-wdate = '20240501'. "签发日期
*gs_item-netdt = '20240825'. "到期日期
*gs_item-wname = '广东XXXX铝材股份有限公司'. "收款人
*gs_item-wort2 = '中国光大银行股份有限公司XXXX支行'. "汇票受票人所在的城市
*gs_item-wbzog = '广东长盈精密技术有限公司'. "付款人
*gs_item-wort1 = '123456789123456789'. "汇票出票人所在的城市
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应收类项目1 END $--------------*
*
**------应收类项目2 START $--------------*
*gs_item-bschl = '40'. "记账码
*gs_item-hkont = |{ '10020005' ALPHA = IN }|. "总账科目
*gs_item-wrbtr = '40000'. "金额
*gs_item-rstgr = '120'. "原因代码
*gs_item-sgtxt = '收到客户3月货款-Z_TEST_LHY程序创建'."项目文本
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应收类项目2 END $--------------*
*
**------应收类项目3 START $--------------*
*gs_item-bschl = '11'. "记账码
*gs_item-hkont = |{ '100961' ALPHA = IN }|. "总账科目
*gs_item-wrbtr = '50000'. "金额
*gs_item-sgtxt = '收到客户3月货款-Z_TEST_LHY程序创建'."项目文本
*APPEND gs_item TO gt_item.
*CLEAR gs_item.
**------应收类项目3 END $--------------*
**"-------------应收类项目赋值 END $-------------------------------* ============================★ 应收类 END ★==============================*------会计凭证表头 START $--------------*
gs_documentheader-username = sy-uname. "用户名
gs_documentheader-comp_code = gs_head-bukrs. "公司代码
gs_documentheader-doc_type = gs_head-blart. "凭证类型
gs_documentheader-doc_date = gs_head-bldat. "凭证日期
gs_documentheader-pstng_date = gs_head-budat. "过账日期
gs_documentheader-fis_period = COND #( WHEN gs_head-monat = 13 THEN 13WHEN gs_head-monat = 14 THEN 14WHEN gs_head-monat = 15 THEN 15WHEN gs_head-monat = 16 THEN 16ELSE gs_head-budat+4(2) ).
gs_documentheader-header_txt = gs_head-bktxt. "凭证抬头文本
*------会计凭证表头 END $--------------*DATA: lv_no TYPE char10.
DATA: i_s_log TYPE bal_s_log. "应用日志: 日志标题数据
DATA: i_s_msg TYPE bal_s_msg. "应用日志: 消息数据
DATA: e_log_handle TYPE balloghndl."应用程序日志:日志处理
DATA: l_s_display_profile TYPE bal_s_prof."应用日志: 日志输出格式参数文件PERFORM get_tbsl. "查询TBSL,获取过账码的数据
PERFORM get_t001. "查询t001,获取公司代码和货币码CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'. "重置整个应用程序日志内存(=>FM文档)
CALL FUNCTION 'BAL_LOG_CREATE' "创建日志EXPORTINGi_s_log = i_s_logIMPORTINGe_log_handle = e_log_handleEXCEPTIONSlog_header_inconsistent = 1OTHERS = 2.
LOOP AT gt_item INTO gs_item.DATA: lv_umskz(1) TYPE c.ls_head = gs_head.ADD 1 TO lv_no.IF gs_item-umskz = 'W' OR gs_item-umskz = 'S'. " 特别总账标识W、Slv_umskz = gs_item-umskz.MOVE-CORRESPONDING gs_item TO ls_bsed.APPEND ls_bsed TO lt_bsed.CLEAR ls_bsed.ENDIF.PERFORM add_front_0 USING lv_no.
*------------ 总帐科目项 START --------------------*IF gs_item-bschl BETWEEN '40' AND '50'.CLEAR gs_accountgl.PERFORM add_front_0 USING lv_no.gs_accountgl-itemno_acc = lv_no. "序号gs_accountgl-item_text = gs_item-sgtxt."项目文本PERFORM add_front_0 USING gs_item-hkont.gs_accountgl-gl_account = gs_item-hkont. "科目gs_accountgl-acct_type = 'S'. "科目类型gs_accountgl-doc_type = ls_head-blart. "凭证类型gs_accountgl-comp_code = ls_head-bukrs. "公司代码gs_accountgl-fis_period = COND #( WHEN ls_head-monat = 13 THEN 13 "期间WHEN ls_head-monat = 14 THEN 14WHEN ls_head-monat = 15 THEN 15WHEN ls_head-monat = 16 THEN 16ELSE ls_head-budat+4(2) ).gs_accountgl-fisc_year = ls_head-budat+0(4). "年度gs_accountgl-pstng_date = ls_head-budat. "过账日期PERFORM add_front_0 USING gs_item-kostl.gs_accountgl-costcenter = gs_item-kostl. "成本中心PERFORM add_front_0 USING gs_item-prctr.gs_accountgl-profit_ctr = gs_item-prctr. "利润中心PERFORM add_front_0 USING gs_item-aufnr.gs_accountgl-orderid = gs_item-aufnr. "订单(内部订单)gs_accountgl-material_long = gs_item-matnr."物料编码gs_accountgl-asset_no = gs_item-anln1."资产编号chenyl 20211018gs_accountgl-sales_ord = gs_item-vbel2."销售订单chenyl 20211018gs_accountgl-s_ord_item = gs_item-posn2."销售订单行项目chenyl 20211018gs_accountgl-po_number = gs_item-ebeln."采购订单chenyl 20211018gs_accountgl-po_item = gs_item-ebelp."采购订单行项目chenyl 20211018
*
*gs_accountgl-alloc_nmbr = gs_item-zuonr. "分配(外围单号)gs_accountgl-tax_code = gs_item-mwskz. "税代码gs_accountgl-ref_key_1 = gs_item-xref1. "税代码"客户编码gs_accountgl-customer = |{ gs_item-kunnr ALPHA = IN }|.gs_accountgl-plant = gs_item-werks.gs_accountgl-salesorg = gs_item-vkorg.gs_accountgl-distr_chan = gs_item-vtweg.APPEND gs_accountgl TO gt_accountgl.ELSEIF gs_item-bschl BETWEEN '70' AND '75'.CLEAR gt_anbwa.gt_anbwa-posnr = lv_no.gt_anbwa-bschl = gs_item-bschl.gt_anbwa-anbwa = gs_item-bewar. "事务类型APPEND gt_anbwa.CLEAR gs_accountgl.PERFORM add_front_0 USING lv_no.gs_accountgl-itemno_acc = lv_no. "序号gs_accountgl-item_text = gs_item-sgtxt."项目文本IF gs_item-hkont IS INITIAL.SELECT SINGLE ktogr INTO @DATA(lv_ktogr) FROM anla WHERE bukrs = @gs_head-bukrsAND anln1 = @gs_item-anln1.IF sy-subrc EQ 0.SELECT SINGLE ktansw INTO @DATA(lv_ktansw) FROM t095 WHERE ktogr = @lv_ktogr.ENDIF.PERFORM add_front_0 USING lv_ktansw.gs_accountgl-gl_account = lv_ktansw. "科目ENDIF.gs_accountgl-acct_type = 'A'.gs_accountgl-doc_type = ls_head-blart. "凭证类型gs_accountgl-comp_code = ls_head-bukrs. "公司代码* MOD 20230424 By JTliudi DV8K903943gs_accountgl-fis_period = COND #( WHEN ls_head-monat = 13 THEN 13WHEN ls_head-monat = 14 THEN 14WHEN ls_head-monat = 15 THEN 15WHEN ls_head-monat = 16 THEN 16ELSE ls_head-budat+4(2) )."GS_ACCOUNTGL-FIS_PERIOD = LS_HEAD-BUDAT+4(2). "期间
* MOD 20230424 By JTliudi DV8K903943gs_accountgl-fisc_year = ls_head-budat+0(4). "年度gs_accountgl-pstng_date = ls_head-budat. "过账日期PERFORM add_front_0 USING gs_item-kostl.gs_accountgl-costcenter = gs_item-kostl. "成本中心PERFORM add_front_0 USING gs_item-prctr.gs_accountgl-profit_ctr = gs_item-prctr. "利润中心PERFORM add_front_0 USING gs_item-aufnr.gs_accountgl-orderid = gs_item-aufnr. "订单(内部订单)gs_accountgl-material_long = gs_item-matnr."物料编码gs_accountgl-asset_no = gs_item-anln1."资产编号chenyl 20211018gs_accountgl-sales_ord = gs_item-vbel2."销售订单chenyl 20211018gs_accountgl-s_ord_item = gs_item-posn2."销售订单行项目chenyl 20211018gs_accountgl-po_number = gs_item-ebeln."采购订单chenyl 20211018gs_accountgl-po_item = gs_item-ebelp."采购订单行项目chenyl 20211018* PERFORM add_front_0 USING gs_item-vbund.
* gs_accountgl-trade_id = gs_item-vbund. "贸易伙伴gs_accountgl-alloc_nmbr = gs_item-zuonr. "分配(外围单号)gs_accountgl-tax_code = gs_item-mwskz. "税代码gs_accountgl-ref_key_1 = gs_item-xref1. "税代码"客户编码gs_accountgl-customer = |{ gs_item-kunnr ALPHA = IN }|.gs_accountgl-plant = gs_item-werks.gs_accountgl-salesorg = gs_item-vkorg.gs_accountgl-distr_chan = gs_item-vtweg."GS_ACCOUNTGL-CS_TRANS_T = GS_ITEM-BEWAR. "事务类型 假的没有,不要尝试APPEND gs_accountgl TO gt_accountgl.ENDIF.
*------------- 总帐科目项 END --------------------**------------- 读取借贷标识 START --------------------*READ TABLE gt_tbsl INTO gs_tbsl WITH KEY bschl = gs_item-bschl.IF sy-subrc = 0.IF gs_tbsl-shkzg = 'H'.MULTIPLY gs_item-wrbtr BY -1. "原币金额,相当于dobj2 = dobj2 / dobj1.MULTIPLY gs_item-dmbtr BY -1. "本币金额ENDIF.ENDIF.
*------------- 读取借贷标识 END --------------------**------------- 货币项目 START ----------------------*READ TABLE gt_t001 INTO gs_t001 WITH KEY bukrs = ls_head-bukrs.IF sy-subrc = 0.IF gs_t001-waers = ls_head-waers.CLEAR gs_currencyamount.PERFORM add_front_0 USING lv_no.gs_currencyamount-itemno_acc = lv_no. "序号gs_currencyamount-curr_type = '00'. "货币类型:凭证货币gs_currencyamount-currency = ls_head-waers. "货币码(币种)gs_currencyamount-amt_doccur = gs_item-wrbtr. "交易货币金额" gs_currencyamount-exch_rate = ls_head-kursf. "汇率APPEND gs_currencyamount TO gt_currencyamount.ELSE.CLEAR gs_currencyamount.PERFORM add_front_0 USING lv_no.gs_currencyamount-itemno_acc = lv_no. "序号gs_currencyamount-curr_type = '00'. "货币类型:凭证货币gs_currencyamount-currency = ls_head-waers. "货币码(币种)gs_currencyamount-amt_doccur = gs_item-wrbtr. "交易货币金额gs_currencyamount-exch_rate = ls_head-kursf. "汇率
* GS_CURRENCYAMOUNT-EXCH_RATE_V = LS_HEAD-KURSF. "汇率APPEND gs_currencyamount TO gt_currencyamount.CLEAR gs_currencyamount.PERFORM add_front_0 USING lv_no.gs_currencyamount-itemno_acc = lv_no. "序号gs_currencyamount-curr_type = '10'. "货币类型:凭证货币gs_currencyamount-currency = gs_t001-waers. "货币码(币种)gs_currencyamount-exch_rate = ls_head-kursf. "汇率
* GS_CURRENCYAMOUNT-EXCH_RATE_V = LS_HEAD-KURSF. "汇率gs_currencyamount-amt_doccur = gs_item-dmbtr. "交易货币金额" gs_currencyamount-exch_rate = ls_head-kursf. "汇率APPEND gs_currencyamount TO gt_currencyamount.ENDIF.ENDIF.*------------- 货币项目 END ---------------------**------------ 增强结构 START ------------------*CLEAR: gs_extension2.CLEAR: ls_zfidoc.ls_zfidoc-posnr = lv_no. "凭证行项目ls_zfidoc-bschl = gs_item-bschl. "记账代码ls_zfidoc-xnegp = gs_item-xnegp. "反记账ls_zfidoc-rstgr = gs_item-rstgr. "原因代码ls_zfidoc-ps_psp_pnr = gs_item-projk. "工作分解结构元素ls_zfidoc-numpg = gs_head-numpg. "凭证顺序号IF gs_item-bschl = '19' OR gs_item-bschl = '09' OR gs_item-bschl = '29' OR gs_item-bschl = '39'.ls_zfidoc-umskz = gs_item-umskz .ENDIF.
* ls_zfidoc-wdate = gs_item-wdate. " 签发日期
* ls_zfidoc-wname = gs_item-wname. " 汇票收款人
* ls_zfidoc-wort2 = gs_item-wort2. " 汇票受票人的城市
* ls_zfidoc-wbzog = gs_item-wbzog. " 汇票付款人
* ls_zfidoc-wort1 = gs_item-wort1. " 出票人城市"ls_zfidoc-status_new = '2'. "2,代表预制凭证*------------ 增强结构 END ------------------*gs_extension2-structure = 'ZFIS002'.gs_extension2-valuepart1 = ls_zfidoc."增强字段APPEND gs_extension2 TO gt_extension2.CLEAR: gs_extension2.CLEAR: ls_zfidoc.*------------ 客户项目 START ------------------*IF gs_item-bschl BETWEEN '01' AND '19'.CLEAR gs_accountreceivable.gs_accountreceivable-itemno_acc = lv_no."凭证行gs_accountreceivable-item_text = gs_item-sgtxt."项目文本PERFORM add_front_0 USING gs_item-hkont.gs_accountreceivable-customer = gs_item-hkont."客户IF gs_item-hkont_a IS NOT INITIAL .gs_accountreceivable-gl_account = |{ gs_item-hkont_a ALPHA = IN }|."科目ENDIF .gs_accountreceivable-sp_gl_ind = gs_item-umskz."SGL(特别总账标志)gs_accountreceivable-pmnttrms = gs_item-zterm."基准日期(付款条件)gs_accountreceivable-bline_date = gs_item-zfbdt."基准日期(收付款基准日期)gs_accountreceivable-dsct_days1 = gs_item-zbd1t."现金折扣天数" gs_accountreceivable-profit_ctr = gs_item-prctr."利润中心gs_accountreceivable-alloc_nmbr = gs_item-zuonr."分配gs_accountreceivable-c_ctr_area = gs_item-kkber."信用gs_accountreceivable-bline_date = gs_item-netdt. "到期日期APPEND gs_accountreceivable TO gt_accountreceivable.ENDIF.
*------------ 客户项目 END ------------------**------------ 供应商项目 START ------------------*"IF gs_item-bschl BETWEEN '21' AND '39'.CLEAR gs_accountpayable.gs_accountpayable-itemno_acc = lv_no."凭证行gs_accountpayable-item_text = gs_item-sgtxt."项目文本PERFORM add_front_0 USING gs_item-hkont.gs_accountpayable-vendor_no = gs_item-hkont. "供应商,使用的是原始值的hkont字段IF gs_item-hkont_a IS NOT INITIAL .gs_accountpayable-gl_account = |{ gs_item-hkont_a ALPHA = IN }|. "备选总账科目??ENDIF .gs_accountpayable-sp_gl_ind = gs_item-umskz. "特别总账标识
* gs_accountpayable-comp_code = ls_head-bukrs.gs_accountpayable-pmnttrms = gs_item-zterm."付款条件码gs_accountpayable-bline_date = gs_item-zfbdt."基准日gs_accountpayable-dsct_days1 = gs_item-zbd1t."现金折扣天数PERFORM add_front_0 USING gs_item-prctr." gs_accountpayable-profit_ctr = gs_item-prctr."利润中心gs_accountpayable-alloc_nmbr = gs_item-zuonr."分配gs_accountpayable-bline_date = gs_item-netdt. "到期日期APPEND gs_accountpayable TO gt_accountpayable.ENDIF.
*------------ 供应商项目 END ------------------*
ENDLOOP.* 特别总账标识特殊处理( 详见LFACIF5D 、FI_DOCUMENT_CHECK )
IF lv_umskz = 'W' OR lv_umskz = 'S'.FREE MEMORY ID 'ZFIU001'.EXPORT lv_umskz TO MEMORY ID 'ZFIU001'.CLEAR lv_umskz.FREE MEMORY ID 'ZFIU001_ED'.EXPORT lt_bsed TO MEMORY ID 'ZFIU001_ED'."CLEAR lt_bsed.
ENDIF.DATA: obj_key LIKE bapiache02-obj_key,obj_type LIKE bapiache02-obj_type,obj_sys LIKE bapiache02-obj_sys.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'EXPORTINGdocumentheader = gs_documentheader "表头
* CUSTOMERCPD =
* CONTRACTHEADER =
* IMPORTING
* OBJ_TYPE =
* OBJ_KEY =
* OBJ_SYS =TABLESaccountgl = gt_accountgl "总帐科目项accountreceivable = gt_accountreceivable "客户项目accountpayable = gt_accountpayable "供应商项目
* ACCOUNTTAX =currencyamount = gt_currencyamount "货币项目
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =return = gt_return
* PAYMENTCARD =
* CONTRACTITEM =extension2 = gt_extension2
* REALESTATE =
* ACCOUNTWT =.IF sy-subrc = 0.READ TABLE gt_return INTO gs_return WITH KEY type = 'E'.IF sy-subrc <> 0.*---------原本顾问这里是没有的,但是要再次将ZFIU001这个内存ID赋值,否则无法创建特殊总账标识为W的凭证!!!! ADD BY LHY 20240726 START $ -----
* ★----核心函数:FI_DOCUMENT_CHECK的第9行和第10行的增强,因为在使用完BAPI_ACC_DOCUMENT_CHECK之后,会删除ZFIU001内存,
* ★----导致创建会计凭证的时候再去执行FI_DOCUMENT_CHECK,就会不通过,就会报错!!!!lv_umskz = 'W'. "手动赋值为W,一定要有!* 特别总账标识特殊处理( 详见LFACIF5D 、FI_DOCUMENT_CHECK )IF lv_umskz = 'W' OR lv_umskz = 'S'.FREE MEMORY ID 'ZFIU001'.EXPORT lv_umskz TO MEMORY ID 'ZFIU001'.CLEAR lv_umskz.FREE MEMORY ID 'ZFIU001_ED'.EXPORT lt_bsed TO MEMORY ID 'ZFIU001_ED'.CLEAR lt_bsed.ENDIF.
*---------原本顾问这里是没有的,但是要再次将ZFIU001这个内存ID赋值,否则无法创建特殊总账标识为W的凭证!!!! ADD BY LHY 20240726 END $ -----"传递事务类型EXPORT t1 = gt_anbwa TO MEMORY ID 'GT_ANBWA'.REFRESH gt_return.CLEAR gs_return.CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'EXPORTINGdocumentheader = gs_documentheader
* CUSTOMERCPD =
* CONTRACTHEADER =
* IMPORTING
* obj_type =
* obj_key =
* obj_sys =TABLESaccountgl = gt_accountgl "总帐科目项accountreceivable = gt_accountreceivableaccountpayable = gt_accountpayable
* ACCOUNTTAX =currencyamount = gt_currencyamount
* CRITERIA =
* VALUEFIELD =
* EXTENSION1 =return = gt_return
* PAYMENTCARD =
* CONTRACTITEM =extension2 = gt_extension2
* REALESTATE =
* ACCOUNTWT =.ENDIF.
ENDIF.READ TABLE gt_return INTO gs_return WITH KEY type = 'E'.
IF sy-subrc = 0 .ROLLBACK WORK .LOOP AT gt_return INTO gs_return.i_s_msg-msgty = gs_return-type.i_s_msg-msgid = gs_return-id.i_s_msg-msgno = gs_return-number.i_s_msg-msgv1 = gs_return-message_v1.i_s_msg-msgv2 = gs_return-message_v2.i_s_msg-msgv3 = gs_return-message_v3.i_s_msg-msgv4 = gs_return-message_v4.CALL FUNCTION 'BAL_LOG_MSG_ADD'EXPORTINGi_log_handle = e_log_handlei_s_msg = i_s_msg.ENDLOOP.CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'IMPORTINGe_s_display_profile = l_s_display_profileEXCEPTIONSOTHERS = 1.l_s_display_profile-use_grid = 'X'.l_s_display_profile-disvariant-report = sy-repid.l_s_display_profile-disvariant-handle = 'LOG'.CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'EXPORTINGi_s_display_profile = l_s_display_profileEXCEPTIONSOTHERS = 1.STOP .
ELSE .CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'EXPORTINGwait = 'X'.IF sy-langu = '1'."DATA: msgtext TYPE string.MESSAGE s000(zfi_msg) WITH '数据导入成功!!!' .ELSE.MESSAGE s000(zfi_msg) WITH 'Data import is successful!!!' .ENDIF.LOOP AT gt_return INTO gs_return.i_s_msg-msgty = gs_return-type.i_s_msg-msgid = gs_return-id.i_s_msg-msgno = gs_return-number.i_s_msg-msgv1 = gs_return-message_v1.i_s_msg-msgv2 = gs_return-message_v2.i_s_msg-msgv3 = gs_return-message_v3.i_s_msg-msgv4 = gs_return-message_v4.CALL FUNCTION 'BAL_LOG_MSG_ADD'EXPORTINGi_log_handle = e_log_handlei_s_msg = i_s_msg.ENDLOOP."MESSAGE gs_return-message TYPE 'S'.CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'IMPORTINGe_s_display_profile = l_s_display_profileEXCEPTIONSOTHERS = 1.l_s_display_profile-use_grid = 'X'.l_s_display_profile-disvariant-report = sy-repid.l_s_display_profile-disvariant-handle = 'LOG'.CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'EXPORTINGi_s_display_profile = l_s_display_profileEXCEPTIONSOTHERS = 1.
ENDIF.
*&---------------------------------------------------------------------*
*& Form add_front_0:添加前导0
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> LV_NO
*&---------------------------------------------------------------------*
FORM add_front_0 USING string.CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'EXPORTINGinput = stringIMPORTINGoutput = string.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_T001:获取公司代码和货币码
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_t001 .CHECK gt_head IS NOT INITIAL.DATA: ls_head LIKE gs_head,lt_head LIKE gt_head.lt_head = gt_head.SORT lt_head BY bukrs.DELETE ADJACENT DUPLICATES FROM lt_head COMPARING bukrs.CHECK lt_head IS NOT INITIAL.SELECT bukrs waers FROM t001 "获取公司代码和货币码INTO CORRESPONDING FIELDS OF TABLE gt_t001FOR ALL ENTRIES IN lt_headWHERE bukrs = lt_head-bukrs.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_TBSL:获取过帐码
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM get_tbsl .SELECT * FROM tbsl INTO TABLE gt_tbsl.
ENDFORM.
代码解析
变量定义
抬头和项目初始值
表头赋值
调用BAPI
其他的子例程
核心内表
EXPORTINGdocumentheader = gs_documentheader "表头TABLESaccountgl = gt_accountgl "总帐科目项accountreceivable = gt_accountreceivable "客户项目accountpayable = gt_accountpayable "供应商项目
* ACCOUNTTAX =currencyamount = gt_currencyamount "货币项目
增强部分
LFACIF5D程序
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Form FI_DOCUMENT_PREPARE, End A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1 ZFIE001. "active version
*ADD BY JT-XZH BY 2022.06.13
DATA: BEGIN OF ls_bsed,wdate TYPE bsed-wdate, "汇票签发日wstat TYPE t031t-txt30, "汇票状态wname TYPE bsed-wname, "收款人wort2 TYPE bsed-wort2, "收票人城市wbzog TYPE bsed-wbzog, "付款人wort1 TYPE bsed-wort1, "出票人城市"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(5) Form FI_DOCUMENT_PREPARE, End, Enhancement ZFIE001, Struct. LS_BSED, End S"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(5) Form FI_DOCUMENT_PREPARE, End, Enhancement ZFIE001, Struct. LS_BSED, End SEND OF ls_bsed.
DATA: lt_bsed LIKE TABLE OF ls_bsed.IMPORT lt_bsed FROM MEMORY ID 'ZFIU001_ED'.
FREE MEMORY ID 'ZFIU001_ED'.LOOP AT xbseg WHERE umsks = 'W' OR umsks = 'S'. " OR umsks = 'S'l_tabix = sy-tabix.READ TABLE lt_bsed INTO ls_bsed INDEX l_tabix. " 会计凭证汇票明细赋值IF sy-subrc = 0.MOVE-CORRESPONDING ls_bsed TO xbsed.MOVE-CORRESPONDING xbseg TO xbsed.APPEND xbsed.CLEAR ls_bsed.ENDIF.ENDLOOP.
*END BY JT-XZH BY 2022.06.13
ENDENHANCEMENT.
*$*$-End: (1)---------------------------------------------------------------------------------$*$*
ENDFORM. "FI_DOCUMENT_PREPARE
FI_DOCUMENT_CHECK
完整程序
FUNCTION fi_document_check.
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(1) Function Module FI_DOCUMENT_CHECK, Start A
*$*$-Start: (1)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 2 ZFIE001. "active version* ADD BY JT-XZH BY 2022.06.13
DATA: lv_umskz TYPE char1.IMPORT lv_umskz FROM MEMORY ID 'ZFIU001'.
FREE MEMORY ID 'ZFIU001'.IF lv_umskz IS NOT INITIAL.char_w = 'U'.
ENDIF.
* ADD BY JT-XZH BY 2022.06.13ENDENHANCEMENT.
*$*$-End: (1)---------------------------------------------------------------------------------$*$*
*"----------------------------------------------------------------------
*"*"Globale Schnittstelle:
*" TABLES
*" T_ACCHD STRUCTURE ACCHD
*" T_ACCIT STRUCTURE ACCIT
*" T_ACCCR STRUCTURE ACCCR
*" T_ACCDA STRUCTURE ACCDA OPTIONAL
*" T_ACCFI STRUCTURE ACCFI OPTIONAL
*" T_ACCTX STRUCTURE ACCBSET OPTIONAL
*" T_ACCWT STRUCTURE ACCIT_WT OPTIONAL
*" T_AUSZ2 STRUCTURE AUSZ2 OPTIONAL
*" T_AUSZ_CLR STRUCTURE AUSZ_CLR OPTIONAL
*" EXCEPTIONS
*" SYSTEM_ERROR
*"----------------------------------------------------------------------* Stop in case of preliminary postings with GLVOR = RFBVprocess = char_x.PERFORM check_pp CHANGING process.CHECK process EQ char_x.
*
* Initialisierung aller Daten
*PERFORM init_all.PERFORM init_iban.
*
* Schnittstellentabellen werden für Credit Card Processing angereichert
*PERFORM credit_card_complete.
*
* Schnittstellentabellen werden nach interne FI-Tabellen kopiert
*PERFORM document_read.
*
* Nur weiter, wenn FI-relevante Zeilen
*DESCRIBE TABLE accit_fi LINES sy-tfill.
* Start of note 1626962CLEAR acc_fi_no_comp.IF sy-tfill = 0.acc_fi_no_comp = 'X'.PERFORM complete_statistical_items. "note 3073796RETURN.ENDIF.
* End of note 1626962PERFORM document_read_clearing USING '1'.
*
* checks in case of change of parked documents
*PERFORM check_change_pp.
*
* FI-Prüfung der Eingaben des RW-Belegkopfes (jeweils für echt buchen,
* vorerfassen und vollständig setzen)
*PERFORM check_acchd.PERFORM check_accit.PERFORM check_acccr.* Schnittstellentabellen werden aus internen FI-Tabellen zurückkopiert
*PERFORM document_save.
* delete line items with amount 0PERFORM delete_zero_items. "notes 2071657 & 2338494PERFORM complete_statistical_items. "note 3073796
* Compression of internal tablesPERFORM compression_acc.CLEAR flg_rgurec."""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""$"$\SE:(2) Function Module FI_DOCUMENT_CHECK, End A
*$*$-Start: (2)---------------------------------------------------------------------------------$*$*
ENHANCEMENT 1 ZFIE002. "active version
* ADD BY JT-XZH BY 2022.06.13IF lv_umskz = 'W'.char_w = 'W'.ELSEIF lv_umskz = 'S'.char_w = 'S'.ENDIF.CLEAR lv_umskz .* ADD BY JT-XZH BY 2022.06.13
ENDENHANCEMENT.
*$*$-End: (2)---------------------------------------------------------------------------------$*$*
ENDFUNCTION.
BADI增强
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,L_REF TYPE REF TO DATA,LS_ACCIT TYPE ACCIT.DATA: BEGIN OF GS_ANBWA,POSNR TYPE ACCIT-POSNR,BSCHL TYPE BSEG-BSCHL,ANBWA TYPE ACCIT-ANBWA,END OF GS_ANBWA.DATA: GT_ANBWA LIKE TABLE OF GS_ANBWA..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-VALUEPART2WA_EXTENSION-VALUEPART3 WA_EXTENSION-VALUEPART4INTO 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."预制凭证DATA ZEXT_DATA TYPE ZFIS002.READ TABLE C_EXTENSION2 INTO DATA(LS_EXTE) WITH KEY STRUCTURE = 'ZFIS002'.IF SY-SUBRC = 0.ZEXT_DATA = LS_EXTE-VALUEPART1.MOVE ZEXT_DATA-STATUS_NEW TO C_ACCHD-STATUS_NEW.ENDIF."判断事务类型IF SY-CPROG = 'ZFIU001'.IMPORT T1 = GT_ANBWA FROM MEMORY ID 'GT_ANBWA'.LOOP AT C_ACCIT INTO LS_ACCIT.IF LS_ACCIT-BSCHL BETWEEN 70 AND 75.CLEAR GS_ANBWA.READ TABLE GT_ANBWA INTO GS_ANBWA WITH KEY POSNR = LS_ACCIT-POSNR.IF SY-SUBRC EQ 0.LS_ACCIT-ANBWA = GS_ANBWA-ANBWA.ENDIF.LS_ACCIT-ANLN2 = '0000'.MODIFY C_ACCIT FROM LS_ACCIT TRANSPORTING ANBWA ANLN2.ENDIF.ENDLOOP.ENDIF.ENDMETHOD.