SAP_ABAP_OO_ALV案例

SAP ABAP顾问能力模型梳理_企业数字化建设者的博客-CSDN博客SAP Abap顾问能力模型https://blog.csdn.net/java_zhong1990/article/details/132469977

一、OO_ ALV ,面向对象开发ALV报表

基于对收款清账平台的开发,解释 OO_ALV开发的程序结构与代码模板参考

1.1 代码部分

sql 复制代码
REPORT  zsd076 .
*******************************************************
*程序名: ZSD076
*程序描述:流水导入 -- > 收款凭证 --> 清账凭证
*----------------------------------------------------------------------
*创建日期     ABAP开发顾问      业务顾问
*20220704    TerryZhong      TerryZhong

*******************************************************

INCLUDE zsd076_global.
INCLUDE zsd076_top.
INCLUDE zsd076_sel.
INCLUDE zsd076_frm.
INCLUDE zsd076_pbo.
INCLUDE zsd076_pai.
INCLUDE zsd076_9001.

SELECTION-SCREEN FUNCTION KEY: 1.

INITIALIZATION.

  gv_init = 'X'.
  PERFORM init.

AT SELECTION-SCREEN OUTPUT.
  PERFORM init_output.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR pa_file.
  PERFORM get_excel.

AT SELECTION-SCREEN.

  CASE sscrfields-ucomm.
    WHEN 'FC01'.
      PERFORM download_template USING '水单导入模板.xlsx' 'ZTSD015'.
    WHEN OTHERS.
  ENDCASE.

START-OF-SELECTION.

  IF p_inp = 'X'.     "导入程序

    PERFORM get_data_for_excel.
    PERFORM check_data_for_excel.
    "Set Index Requence
    LOOP AT gt_data ASSIGNING <fs_data>.
      <fs_data>-zindex = sy-tabix.
    ENDLOOP.

    PERFORM set_catalog.
    PERFORM display_alv.

  ELSEIF p_sel = 'X'. "处理收款


    "添加权限检查
    SELECT t001~bukrs INTO TABLE @gv_auth_bukrs FROM t001 WHERE t001~bukrs IN @so_vkorg.
    IF gv_auth_bukrs IS NOT INITIAL.
      LOOP AT gv_auth_bukrs INTO gs_auth_bukrs.

        AUTHORITY-CHECK OBJECT 'F_KK_ODBUK'
                 ID 'BUKRS' FIELD gs_auth_bukrs-bukrs
                 ID 'ORDERACT' FIELD '03'.
        IF sy-subrc = 4.
          MESSAGE '没有申请' && gs_auth_bukrs-bukrs && '公司的访问权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.LEAVE TO LIST-PROCESSING.EXIT.
        ELSEIF sy-subrc <> 0.
          MESSAGE '没有申请' && gs_auth_bukrs-bukrs && '公司的访问权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.LEAVE TO LIST-PROCESSING.EXIT.
        ENDIF.
      ENDLOOP.
    ENDIF.




    "Get NO
    PERFORM get_data_for_ztsd015.
    "Get ITEM OF Uncleaning INVOICE
    READ TABLE gt_data ASSIGNING <fs_data> INDEX 1. " 获取第一条 ,水单
    IF sy-subrc = 0.
      <fs_data>-checked = 'X'.
      "Added by zhong on 20221012 ,从ZTSD018中获取单据 业务确认过的 。
      SELECT * INTO TABLE @lt_ztsd018 FROM ztsd018 WHERE ztsd018~ztsd015_id = @<fs_data>-zid.
      IF lt_ztsd018 IS NOT INITIAL.
        REFRESH :lt_bsid.
        LOOP AT lt_ztsd018 INTO ls_ztsd018.

          MOVE-CORRESPONDING ls_ztsd018 TO ls_bsid.
          ls_bsid-zid           = ls_ztsd018-ztsd015_id."收款单ID
          ls_bsid-in_wrbtr      = ls_ztsd018-wrbtr_2.   "分配余额
          ls_bsid-oa_no         = ls_ztsd018-oa_no.
          ls_bsid-rstgr         = ls_ztsd018-rstgr.

          ls_bsid-status_inc_a  = icon_locked.
          APPEND ls_bsid TO lt_bsid.

        ENDLOOP.
      ELSE.
        "获取客户 RV 的凭证
*        PERFORM get_data_for_bsid_by2 USING <fs_data>-vkorg <fs_data>-kunnr.
*        PERFORM dear_data_for_bsid    USING <fs_data>-vkorg <fs_data>-kunnr.

      ENDIF.
    ENDIF.

    CALL SCREEN 9001.

  ELSEIF p_sel2 = 'X'."查询

    "添加权限检查
    SELECT t001~bukrs INTO TABLE @gv_auth_bukrs FROM t001 WHERE t001~bukrs IN @so_vkorg.
    IF gv_auth_bukrs IS NOT INITIAL.
      LOOP AT gv_auth_bukrs INTO gs_auth_bukrs.

        AUTHORITY-CHECK OBJECT 'F_KK_ODBUK'
                 ID 'BUKRS' FIELD gs_auth_bukrs-bukrs
                 ID 'ORDERACT' FIELD '03'.
        IF sy-subrc = 4.
          MESSAGE '没有申请' && gs_auth_bukrs-bukrs && '公司的访问权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.LEAVE TO LIST-PROCESSING.EXIT.
        ELSEIF sy-subrc <> 0.
          MESSAGE '没有申请' && gs_auth_bukrs-bukrs && '公司的访问权限,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.LEAVE TO LIST-PROCESSING.EXIT.
        ENDIF.
      ENDLOOP.
    ENDIF.





    "get no
    PERFORM get_data_for_ztsd015.
    PERFORM set_catalog.
    PERFORM display_alv.
  ELSEIF p_3 = 'X'.
    CALL TRANSACTION 'ZSD077'.
  ENDIF.
sql 复制代码
*&---------------------------------------------------------------------*
*& 包含 ZSD076_GLOBAL
*&---------------------------------------------------------------------*

DATA:gv_init TYPE char1.

DATA:lt_ztsd018 TYPE TABLE OF ztsd018.
DATA:ls_ztsd018 TYPE ztsd018.

DATA:gv_auth_bukrs TYPE TABLE OF t001.
DATA:gs_auth_bukrs TYPE t001.
 
 
 


*&---------------------------------------------------------------------*
*&  包含                ZFI068_TOP
*&---------------------------------------------------------------------*
TABLES: sscrfields,vbak,bsis.
TYPE-POOLS: esp1,slis ,icon.
TYPES: BEGIN OF gy_data,
         zindex          TYPE i,           "序号
         checked         TYPE char1,       "勾选框
         status_inc      TYPE char10,      "状态灯
         status          TYPE char2,       "状态
         message         TYPE char255,     "消息文本
         zid             TYPE ztsd015-zid, "ID "收款单ID
         belnr           TYPE bsid-belnr,  "凭证编号
         gjahr           TYPE bsid-gjahr,  "财务年度
         bstat           TYPE bsid-bstat,
         cbelnr          TYPE bsid-belnr,         "清账凭证编号
         vkorg           TYPE ztsd015-vkorg,      "销售机构
         kunnr           TYPE ztsd015-kunnr,      "售达方
         kunnr_desc      TYPE ztsd015-kunnr_desc, "客户名称 - 模板上的客户名称
         kunnr2          TYPE ztsd015-kunnr,      "送达方
         kunnr_desc2     TYPE ztsd015-kunnr_desc, "送达方名称
         kunnr_desc_yh   TYPE ztsd015-kunnr_desc, "客户付款名称
         bstkd           TYPE ztsd015-bstkd,
*         sname           TYPE pa0001-sname,      "业务员
*         pernr           TYPE knvp-pernr,        "业务员编号
         sname           TYPE char50,             "业务员
         pernr           TYPE char50,             "业务员编号
         zname           TYPE ztsd017-zname,      "收款银行
         zaccount        TYPE ztsd017-zaccount,   "收款账号
         hkont           TYPE ztsd017-hkont,      "总帐 - 银行科目
         hkont_in        TYPE ztsd017-hkont_in,   "总帐 - 手续费
         kunnr_akont     TYPE knb1-akont,         "应收统驭科目
         kunnr_akont2    TYPE knb1-akont,         "预收统驭科目
         hkont_in2       TYPE ztsd017-hkont_in2,
         kostl           TYPE bsis-kostl,
         item_text       TYPE ztsd017-item_text,  "行项目文本
         acct_type       TYPE ztsd017-acct_type,  "帐户类型
         doc_type        TYPE ztsd017-doc_type,   "凭证类型
         rstgr           TYPE ztsd017-rstgr,      "原因代码
         rstgr_kunnr     TYPE ztsd017-rstgr,      "原因代码
         xblnr           TYPE ztsd017-xblnr,           "参考
         transactionno   TYPE ztsd015-transactionno,   "交易流水
         transactiontype TYPE ztsd015-transactiontype, "交易类型
         businesstype    TYPE ztsd015-businesstype,    "业务类型
         accountpayer    TYPE ztsd015-accountpayer,    "付款人开户行号
         payer           TYPE ztsd015-payer,           "付款人开户行名
         debitaccount    TYPE ztsd015-debitaccount,    "付款人账号
         payername       TYPE ztsd015-payername,       "付款人名称
         transactiondate TYPE ztsd015-transactiondate, "交易日期
         tradecurrency   TYPE ztsd015-tradecurrency,   "交易货币
         wrbtr           TYPE ztsd015-wrbtr,  "金额
         wrbtr_charge    TYPE ztsd015-wrbtr,  "金额-手续费
         wrbtr_charge2   TYPE ztsd015-wrbtr,  "金额-手续费 业务补充
         wrbtr_2         TYPE ztsd015-wrbtr,  "分配余额
         wrbtr_3         TYPE ztsd015-wrbtr,  "预收
         wrbtr_4         TYPE ztsd015-wrbtr,  "佣金
         budat           TYPE bsis-budat, "过账日期
         trans_date      TYPE bsis-budat, "换算日期
         modifiydate     TYPE ztsd015-modifiydate, "水单记录的日期
         modifiytime     TYPE ztsd015-modifiytime, "水单时间
         modifiedby      TYPE ztsd015-modifiedby,  "水单确认人
         zstatus         TYPE  c, "分配状态
         zin             TYPE ztsd015-zin, "会计确认
         za              TYPE ztsd015-za,  "业务确认
         zp              TYPE ztsd015-zp,  "凭证过账
         zc              TYPE ztsd015-zc,  "凭证清账
         modifiydate_za  TYPE ztsd015-modifiydate_za, "业务确认日期
         modifiytime_za  TYPE ztsd015-modifiytime_za, "业务确认时间
         modifiedby_za   TYPE ztsd015-modifiedby_za,  "业务确认人
         status_inc_i    TYPE char10,      "流水初始确认
         status_inc_a    TYPE char10,      "流水业务员确认
         status_inc_p    TYPE char10,      "凭证过账
         status_inc_c    TYPE char10,      "凭证清账
         ztrue           TYPE char10,      "辅助字段 已匹配到客户关键词 X
         ztimes          TYPE ztsd016-ztimes,    "次数
         bank_bak        TYPE ztsd015-bank_bak, "水单备注
       END OF gy_data.

DATA: gs_data TYPE gy_data,
      gt_data TYPE TABLE OF gy_data.
FIELD-SYMBOLS: <fs_data>  TYPE gy_data.

DATA: gt_fieldcat_lvc TYPE lvc_t_fcat, "ALV:定义一个先显示字段的表
      gs_fieldcat_lvc LIKE LINE OF gt_fieldcat_lvc. "ALV


" ---  bsid  客户未清发票

TYPES:BEGIN OF ly_bsid,
        bukrs        TYPE  bsid-bukrs, "公司代码
        kunnr        TYPE  bsid-kunnr, "客户
        umsks        TYPE  bsid-umsks, "事务类型
        umskz        TYPE  bsid-umskz, "特别总账标识
        augdt        TYPE  bsid-augdt, "结算
        augbl        TYPE  bsid-augbl, "清帐凭证
        zuonr        TYPE  bsid-zuonr, "分配
        gjahr        TYPE  bsid-gjahr, "财年
        belnr        TYPE  bsid-belnr, "凭证编号
        buzei        TYPE  bsid-buzei, "行项目
        budat        TYPE  bsid-budat, "过帐日期
        bldat        TYPE  bsid-bldat, "凭证日期
        cpudt        TYPE  bsid-cpudt, "录入日期
        waers        TYPE  bsid-waers, "货币
        xblnr        TYPE  bsid-xblnr, "参照
        blart        TYPE  bsid-blart, "凭证类型
        monat        TYPE  bsid-monat, "期间
        bschl        TYPE  bsid-bschl, "记帐代码
        zumsk        TYPE  bsid-zumsk, "特别总帐标志
        shkzg        TYPE  bsid-shkzg, "借方/贷方
        gsber        TYPE  bsid-gsber, "业务范围
        mwskz        TYPE  bsid-mwskz, "税码
        dmbtr        TYPE  bsid-dmbtr, "本位币金额
        wrbtr        TYPE  bsid-wrbtr, "金额
        mwsts        TYPE  bsid-mwsts, "LC 税额
        wmwst        TYPE  bsid-wmwst, "税额
        bdiff        TYPE  bsid-bdiff, "估价差额
        bdif2        TYPE  bsid-bdif2, "估价差额 2
        sgtxt        TYPE  bsid-sgtxt, "文本
        projn        TYPE  bsid-projn, "未在使用中的
        aufnr        TYPE  bsid-aufnr, "订单
        anln1        TYPE  bsid-anln1, "资产
        anln2        TYPE  bsid-anln2, "次级编号
        saknr        TYPE  bsid-saknr, "总帐科目
        hkont        TYPE  bsid-hkont, "总帐
        fkont        TYPE  bsid-fkont, "财务预算
        filkd        TYPE  bsid-filkd, "分支
        zfbdt        TYPE  bsid-zfbdt, "基限日期
        zterm        TYPE  bsid-zterm, "付款条件
        zbd1t        TYPE  bsid-zbd1t, "天数 1
        zbd2t        TYPE  bsid-zbd2t, "天数 2
        zbd3t        TYPE  bsid-zbd3t, "天内净额
        zbd1p        TYPE  bsid-zbd1p, "折扣百分比 1
        zbd2p        TYPE  bsid-zbd2p, "折扣百分比 2
        in_wrbtr     TYPE  bsid-wrbtr,  "分配金额
        zid          TYPE  ztsd015-zid, "ID
        oa_no        TYPE ztsd018-oa_no,
        rstgr        TYPE ztsd018-rstgr,
        zmonth       TYPE  num10, "test
        zstatus      TYPE  c, "ID
        status_inc   TYPE char10,      "状态灯
        status_inc_a TYPE char10,      "流水业务员确认
        status_inc_c TYPE char10,      "凭证清账
      END OF ly_bsid.

DATA:ls_bsid TYPE ly_bsid.
DATA:lt_bsid TYPE TABLE OF ly_bsid.
DATA:lt_bsid_temp TYPE TABLE OF ly_bsid.
FIELD-SYMBOLS: <fs_bsid>  TYPE ly_bsid.


"--  ooalv

DATA: gs_layo1 TYPE lvc_s_layo,
      gs_fcat1 TYPE lvc_s_fcat,
      gt_fcat1 TYPE lvc_t_fcat.
* 定义ALV宏
DEFINE add_fcat1.
  gs_fcat1-scrtext_m   = &1."中字段标签
  gs_fcat1-fieldname   = &2."ALV 控制: 内部表字段的字段名称
  gs_fcat1-no_zero     = &3."ALV 控制: 为输出隐藏零
  gs_fcat1-checkbox    = &4."ALV 控制: 作为复选框输出
  gs_fcat1-edit        = &5."设置可编辑模式
  gs_fcat1-outputlen   = &6."输出长度
  gs_fcat1-ref_table   = &7.
  gs_fcat1-ref_field   = &8.
  gs_fcat1-datatype    = &9.
APPEND gs_fcat1 TO gt_fcat1.
CLEAR gs_fcat1.
END-OF-DEFINITION.

DATA: gs_layo2 TYPE lvc_s_layo,
      gs_fcat2 TYPE lvc_s_fcat,
      gt_fcat2 TYPE lvc_t_fcat.
DEFINE add_fcat2.
  gs_fcat2-scrtext_m   = &1."中字段标签
  gs_fcat2-fieldname   = &2."ALV 控制: 内部表字段的字段名称
  gs_fcat2-no_zero     = &3."ALV 控制: 为输出隐藏零
  gs_fcat2-checkbox    = &4."ALV 控制: 作为复选框输出
  gs_fcat2-edit        = &5."设置可编辑模式
  gs_fcat2-outputlen   = &6."输出长度
  gs_fcat2-ref_table   = &7.
  gs_fcat2-ref_field   = &8.
  gs_fcat2-datatype    = &9.
APPEND gs_fcat2 TO gt_fcat2.
CLEAR gs_fcat2.
END-OF-DEFINITION.

DATA con1_ref TYPE REF TO cl_gui_custom_container.
DATA con2_ref TYPE REF TO cl_gui_custom_container.

DATA g_grid1 TYPE REF TO cl_gui_alv_grid.
DATA g_grid2 TYPE REF TO cl_gui_alv_grid.

DATA ok_code TYPE sy-ucomm.
DATA:lv_frist TYPE c.


"----------------------------------------------
" 加入事件定义:
CLASS lcl_event_receiver DEFINITION DEFERRED.
DATA: event_receiver TYPE REF TO lcl_event_receiver.
DATA: ls_stbl TYPE lvc_s_stbl.
*定义是件的属性和方法
CLASS lcl_event_receiver DEFINITION.
*公共事件
  PUBLIC SECTION.
    METHODS:

      handle_double_click
                    FOR EVENT double_click OF cl_gui_alv_grid
        IMPORTING e_row e_column es_row_no,

*按钮处理方法
      handle_toolbar
                    FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object e_interactive,
*用户交互是件处理
      handle_user_command
                    FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING e_ucomm.

    METHODS catch_hotspotclick
                  FOR EVENT hotspot_click OF cl_gui_alv_grid
      IMPORTING e_row_id
                  e_column_id
                  es_row_no.

    METHODS catch_change
                  FOR EVENT data_changed OF cl_gui_alv_grid
      IMPORTING er_data_changed
                  e_onf4
                  e_onf4_before
                  e_onf4_after
                  e_ucomm.

ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION

*实现方法
CLASS lcl_event_receiver IMPLEMENTATION .


  METHOD handle_double_click.

    IF e_column-fieldname = 'BELNR'.
      READ TABLE gt_data INTO gs_data INDEX es_row_no-row_id.
      IF sy-subrc = 0.

**        SET PARAMETER ID 'BLN'   FIELD gs_data-belnr.
**        SET PARAMETER ID 'BUK'   FIELD gs_data-vkorg.
**        SET PARAMETER ID 'GJR'   FIELD gs_data-gjahr.
**        CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.

        SET PARAMETER ID 'BLP'   FIELD gs_data-belnr.
        SET PARAMETER ID 'BUK'   FIELD gs_data-vkorg.
        SET PARAMETER ID 'GJR'   FIELD gs_data-gjahr.
        CALL TRANSACTION 'FBV0' AND SKIP FIRST SCREEN.

      ENDIF.
    ENDIF.

  ENDMETHOD.                    "handle_double_click





*处理按钮事件
  METHOD handle_toolbar.
    DATA:ls_toolbar TYPE stb_button.
    CLEAR ls_toolbar.
*    MOVE 3 TO ls_toolbar-butn_type.
**取工具条接口
*    APPEND ls_toolbar TO e_object->mt_toolbar.
    CLEAR ls_toolbar.
***加入功能码
*    MOVE 'ZSA' TO ls_toolbar-function.
***图标,可以用SHOWICON系统程序查阅需使用的图标
**    MOVE icon_ppe_vnode TO ls_toolbar-icon.
***按钮文本和提示
*    MOVE '全选' TO  ls_toolbar-quickinfo.
*    MOVE '全选'(112) TO  ls_toolbar-text.
*    MOVE '' TO  ls_toolbar-disabled.
*    APPEND ls_toolbar TO e_object->mt_toolbar.
*
    MOVE 'ZCA' TO ls_toolbar-function.
***图标,可以用SHOWICON系统程序查阅需使用的图标
    MOVE icon_ppe_vnode TO ls_toolbar-icon.
***按钮文本和提示
    MOVE '取消全选' TO  ls_toolbar-quickinfo.
    MOVE '取消全选'(112) TO  ls_toolbar-text.
    MOVE '' TO  ls_toolbar-disabled.
    APPEND ls_toolbar TO e_object->mt_toolbar.


***    MOVE 'ZPOST' TO ls_toolbar-function.
*****图标,可以用SHOWICON系统程序查阅需使用的图标
***    MOVE icon_ppe_vnode TO ls_toolbar-icon.
*****按钮文本和提示
***    MOVE '创建收款凭证' TO  ls_toolbar-quickinfo.
***    MOVE '创建收款凭证'(112) TO  ls_toolbar-text.
***    MOVE '' TO  ls_toolbar-disabled.
***    APPEND ls_toolbar TO e_object->mt_toolbar.



  ENDMETHOD.                    "HANDLE_TOOLBAR

*处理功能码事件
  METHOD handle_user_command.

    DATA: lt_rows  TYPE lvc_t_row.
    DATA: lv_total TYPE wrbtr.

    CASE  e_ucomm.
*定义的按钮事件
      WHEN 'ZSA'.
        LOOP AT gt_data ASSIGNING <fs_data>.
          <fs_data>-checked = 'X'.
        ENDLOOP.
      WHEN 'ZCA'.
        LOOP AT gt_data ASSIGNING <fs_data>.
          <fs_data>-checked = ''.
        ENDLOOP.
      WHEN 'ZPOST'.

    ENDCASE.

    ls_stbl-row = 'X'.
    ls_stbl-col = 'X'.

    CALL METHOD g_grid1->refresh_table_display
      EXPORTING
        is_stable = ls_stbl.


  ENDMETHOD.                    "HANDLE_USER_COMMAND



  METHOD catch_hotspotclick.

*    CLEAR: lv_dr_total, lv_dz_total.
*    READ TABLE gt_dz_info ASSIGNING FIELD-SYMBOL(<gs_dz_info>) INDEX e_row_id.
*    IF sy-subrc = 0 .
*      IF <gs_dz_info>-budat_display <> '可分配金额'.
*
*        READ TABLE gt_dz_info ASSIGNING FIELD-SYMBOL(<gs_dz_change>) WITH KEY budat_display = '可分配金额'.
*
*        IF <gs_dz_info>-check_dz = 'X'.
*
*          LOOP AT gt_rv_info INTO gs_rv_info WHERE check_rv = 'X'.
*            lv_dr_total = lv_dr_total + gs_rv_info-zqzje.
*          ENDLOOP.
*
*          LOOP AT gt_dz_info INTO gs_dz_info WHERE check_dz = 'X'.
*            lv_dz_total = lv_dz_total + gs_dz_info-n_wrbtr.
*          ENDLOOP.
*
*          IF lv_dz_total - <gs_dz_info>-n_wrbtr < lv_dr_total AND lv_dr_total <> 0.
*            MESSAGE '不能取消勾选,请先调整发票金额' TYPE 'I'.
*          ELSE.
*
*            CLEAR: <gs_dz_info>-check_dz.
*            <gs_dz_change>-n_wrbtr = <gs_dz_change>-n_wrbtr - <gs_dz_info>-n_wrbtr.
*            CLEAR: <gs_dz_info>-n_wrbtr.
*
*          ENDIF.
*
*        ELSE.
*          <gs_dz_info>-check_dz = 'X'..
*          <gs_dz_info>-n_wrbtr = <gs_dz_info>-wrbtr.
*          <gs_dz_change>-n_wrbtr = <gs_dz_change>-n_wrbtr + <gs_dz_info>-n_wrbtr.
*        ENDIF.
*
*      ENDIF.
*    ENDIF.

    ls_stbl-row = 'X'.
    ls_stbl-col = 'X'.

    CALL METHOD g_grid1->refresh_table_display
      EXPORTING
        is_stable = ls_stbl.

  ENDMETHOD.                    "CATCH_DOUBLECLICK

  METHOD catch_change.

    DATA lv_message TYPE char255.
    FIELD-SYMBOLS:  <fs_value> TYPE any.

    LOOP AT er_data_changed->mt_mod_cells ASSIGNING FIELD-SYMBOL(<ls_mod_cell>) .

      IF <ls_mod_cell>-fieldname = 'CHECKED'.

        LOOP AT gt_data ASSIGNING <fs_data> .
          IF sy-tabix <> <ls_mod_cell>-row_id.
            <fs_data>-checked = ''.
          ELSE.
            <fs_data>-checked = 'X'.
          ENDIF.
        ENDLOOP.

        READ TABLE gt_data INTO gs_data INDEX <ls_mod_cell>-row_id.
        IF sy-subrc EQ 0.

*          ASSIGN COMPONENT <ls_mod_cell>-fieldname OF STRUCTURE gs_data TO <fs_value>.
*          IF sy-subrc EQ 0.
*            CALL METHOD er_data_changed->get_cell_value
*              EXPORTING
*                i_row_id    = <ls_mod_cell>-row_id
*                i_fieldname = <ls_mod_cell>-fieldname
*              IMPORTING
*                e_value     = <fs_value>.
*            <ls_mod_cell>-value = <fs_value>.
*          ENDIF.

          " added by zhong on 20220718 添加未清信息-------------------
*          PERFORM get_data_for_bsid_by2 USING gs_data-vkorg gs_data-kunnr.
*          PERFORM dear_data_for_bsid    USING gs_data-vkorg gs_data-kunnr.

          "Added by zhong on 20221012 ,从ZTSD018中 业务确认过的 ,单据中获取。
          SELECT * INTO TABLE @lt_ztsd018 FROM ztsd018 WHERE ztsd018~ztsd015_id = @gs_data-zid.
          IF lt_ztsd018 IS NOT INITIAL.
            REFRESH :lt_bsid.
            LOOP AT lt_ztsd018 INTO ls_ztsd018.
              MOVE-CORRESPONDING ls_ztsd018 TO ls_bsid.
              ls_bsid-zid           = ls_ztsd018-ztsd015_id.
              ls_bsid-in_wrbtr      = ls_ztsd018-wrbtr_2.
              ls_bsid-status_inc_a  = icon_locked.
              APPEND ls_bsid TO lt_bsid.
            ENDLOOP.
          ELSE.
*            "获取客户 RV 的凭证
*            PERFORM get_data_for_bsid_by2 USING gs_data-vkorg gs_data-kunnr.
*            PERFORM dear_data_for_bsid    USING gs_data-vkorg gs_data-kunnr.
            REFRESH :lt_bsid.
          ENDIF.

          ls_stbl-row = 'X'.
          ls_stbl-col = 'X'.
          CALL METHOD g_grid2->refresh_table_display
            EXPORTING
              is_stable = ls_stbl.
*          " ---------------------------

        ENDIF.
      ENDIF.

    ENDLOOP.


    ls_stbl-row = 'X'.
    ls_stbl-col = 'X'.

    CALL METHOD g_grid1->refresh_table_display
      EXPORTING
        is_stable = ls_stbl.


  ENDMETHOD.
ENDCLASS.



*&---------------------------------------------------------------------*
*& 包含 ZPP066_SEL
*&---------------------------------------------------------------------*
TABLES:ztsd013,lips, bsid,ztsd015,usr02.

SELECTION-SCREEN:BEGIN OF BLOCK b0 WITH FRAME TITLE TEXT-001.

PARAMETERS:p_inp RADIOBUTTON GROUP g1 USER-COMMAND u1 DEFAULT 'X'."导入收款
PARAMETERS:p_sel RADIOBUTTON GROUP g1 . "处理收款
PARAMETERS:p_sel2 RADIOBUTTON GROUP g1 . "查询流水
PARAMETERS:p_3 RADIOBUTTON GROUP g1 . "客户关键词维护

SELECTION-SCREEN SKIP 1.

PARAMETERS:pa_file TYPE rlgrap-filename MODIF ID s01."文件夹上传
SELECT-OPTIONS: so_vkorg FOR ztsd013-vkorg MODIF ID s02.
SELECT-OPTIONS: so_kunnr FOR bsid-kunnr MODIF ID s02.

SELECT-OPTIONS: so_trans FOR ztsd015-transactionno MODIF ID s02.
SELECT-OPTIONS: so_trane FOR ztsd015-transactiondate MODIF ID s02.

SELECT-OPTIONS: so_usr02 FOR usr02-bname MODIF ID s02.



SELECTION-SCREEN SKIP 1.
PARAMETERS:p_0 RADIOBUTTON GROUP g2 DEFAULT 'X' USER-COMMAND u1 MODIF ID s03.
PARAMETERS:p_1 RADIOBUTTON GROUP g2 MODIF ID s03. "
PARAMETERS:p_2 RADIOBUTTON GROUP g2 MODIF ID s03. "

SELECTION-SCREEN:END OF BLOCK b0.



*&---------------------------------------------------------------------*
*&  包含                ZFI068_FRM
*&---------------------------------------------------------------------*

FORM get_excel.
  DATA : l_filetab TYPE filetable,
         l_waftab  LIKE LINE OF l_filetab,
         l_rc      TYPE i.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = '打开文件'
      initial_directory       = 'C:/'
    CHANGING
      file_table              = l_filetab
      rc                      = l_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    EXIT.
  ELSE.
    READ TABLE l_filetab INTO l_waftab INDEX 1.
    pa_file = l_waftab-filename.
    CLEAR: l_filetab,l_waftab.
  ENDIF.

ENDFORM.


FORM init.

  DATA: ls_dyntxt TYPE smp_dyntxt .
  ls_dyntxt-icon_id   = icon_export.
  ls_dyntxt-quickinfo = '模板下载'.
  ls_dyntxt-icon_text = '模板下载'.
  sscrfields-functxt_01 = ls_dyntxt.

  so_usr02-low    = sy-uname.
  so_usr02-high   = ''.
  so_usr02-option = 'BT'.
  so_usr02-sign   = 'I'.
  APPEND  so_usr02 TO so_usr02[].

ENDFORM.



FORM init_output.

  LOOP AT SCREEN.

    IF p_inp  = 'X'.
      IF  screen-group1 = 'S02' OR screen-group1 = 'S03'  OR screen-group1 = 'S04'.
        screen-active = 0. "隐藏
      ENDIF.
      IF screen-group1 = 'S01'.
        screen-active = 1. "显示
      ENDIF.
    ELSEIF p_sel = 'X'.
      IF  screen-group1 = 'S01'  OR screen-group1 = 'S04'.
        screen-active = 0. "隐藏
      ENDIF.
      IF screen-group1 = 'S02' OR screen-group1 = 'S03'.
        screen-active = 1. "显示
      ENDIF.
    ELSEIF p_sel2 = 'X'.
      IF  screen-group1 = 'S01'  OR screen-group1 = 'S04'.
        screen-active = 0. "隐藏
      ENDIF.
      IF screen-group1 = 'S02' OR screen-group1 = 'S03' .
        screen-active = 1. "显示
      ENDIF.
    ELSEIF p_3    = 'X'.
      IF  screen-group1 = 'S01' OR screen-group1 = 'S02' OR screen-group1 = 'S03'  OR screen-group1 = 'S04'.
        screen-active = 0. "隐藏
      ENDIF.
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.

ENDFORM.


FORM get_data_for_excel.
  TYPES: BEGIN OF ly_excel_data,
           zname           TYPE ztsd017-zname,             "收款银行
           zaccount        TYPE ztsd017-zaccount,          "收款账号
           transactiondate TYPE ztsd015-transactiondate,   "交易日期
           transactionno   TYPE ztsd015-transactionno,     "交易流水
           kunnr_desc_yh   TYPE ztsd015-kunnr_desc,        "客户名称 - 模板上的客户名称
           tradecurrency   TYPE ztsd015-tradecurrency,     "交易货币
           wrbtr           TYPE ztsd015-wrbtr,             "金额-到账金额
           wrbtr_charge    TYPE ztsd015-wrbtr,             "金额-手续费
           bank_bak        TYPE ztsd015-bank_bak,          "水单备注

           transactiontype TYPE ztsd015-transactiontype,   "交易类型
           businesstype    TYPE ztsd015-businesstype,      "业务类型
           accountpayer    TYPE ztsd015-accountpayer,      "付款人开户行号
           payer           TYPE ztsd015-payer,             "付款人开户行名
           debitaccount    TYPE ztsd015-debitaccount,      "付款人账号
           payername       TYPE ztsd015-payername,         "付款人名称

         END OF ly_excel_data.
*  DATA: lt_excel      TYPE TABLE OF alsmex_tabline WITH HEADER LINE,
  DATA: lt_excel      TYPE TABLE OF zcom_alsmex_tabline WITH HEADER LINE,
        ls_excel_data TYPE ly_excel_data,
        l_index       LIKE sy-tabix.
  DATA: lv_lines TYPE i.

  FIELD-SYMBOLS: <fs>.
  IF pa_file IS NOT INITIAL.
    CALL FUNCTION 'ZZALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                = pa_file
        i_begin_col             = '1'
        i_begin_row             = '3'
        i_end_col               = '9'
        i_end_row               = '9999'
      TABLES
        intern                  = lt_excel
      EXCEPTIONS
        inconsistent_parameters = 1
        upload_ole              = 2
        OTHERS                  = 3.
    IF sy-subrc = 0.
*&& 将EXCEL格式中的数据导入到内表TAB_LOAD中
      LOOP AT lt_excel.

        ASSIGN COMPONENT lt_excel-col OF STRUCTURE ls_excel_data TO <fs>.
        <fs> = lt_excel-value.
        AT END OF row.
          MOVE-CORRESPONDING ls_excel_data TO gs_data."跟Excel的列一一对应的内表
          APPEND gs_data TO gt_data.
          CLEAR: ls_excel_data,gs_data.
        ENDAT.

      ENDLOOP.

      lv_lines = lines( gt_data ).

      IF lv_lines > 8000.
        MESSAGE  '本次导入数据超过8000,请拆分数据文件!' TYPE 'S'DISPLAY LIKE 'E'.
        STOP.
      ENDIF.
    ENDIF.

  ELSE.
    MESSAGE  '请输入文件路径!' TYPE 'S'DISPLAY LIKE 'E'.
    STOP.
  ENDIF.

ENDFORM.



FORM check_data_for_excel.

  IF gt_data IS NOT INITIAL.

    LOOP AT gt_data ASSIGNING <fs_data>.
      "  1,检查交易流水号在数据库中是否已经存在
      "  2,检查交易流水号是否已经被确认
      "  3,智能匹配销售客户与售达方
      SELECT SINGLE * INTO @DATA(ls_ztsd016)  FROM ztsd016 WHERE ztsd016~kunnr_desc = @<fs_data>-kunnr_desc_yh.

      IF ls_ztsd016 IS NOT INITIAL.

        SELECT SINGLE * INTO @DATA(ls_ztsd017) FROM ztsd017
            WHERE ztsd017~zaccount = @<fs_data>-zaccount AND ztsd017~waers = @<fs_data>-tradecurrency.
        IF sy-subrc = 0.
          <fs_data>-vkorg = ls_ztsd017-vkorg. "销售机构
          CLEAR: ls_ztsd017.
        ELSE.
          CLEAR: ls_ztsd017.
        ENDIF.
*       <fs_data>-vkorg = ls_ztsd016-vkorg. "销售机构
        <fs_data>-kunnr = ls_ztsd016-kunnr. "售达方
        <fs_data>-ztrue = 'X'.
        <fs_data>-ztimes = ls_ztsd016-ztimes.
        SELECT SINGLE kna1~name1 INTO <fs_data>-kunnr_desc FROM kna1 WHERE kna1~kunnr = ls_ztsd016-kunnr.
        CLEAR:ls_ztsd016.

      ELSE.
        CLEAR:ls_ztsd016.
      ENDIF.

      IF <fs_data>-zname IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入收款银行!'.CONTINUE.
      ENDIF.

      IF <fs_data>-zaccount IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入收款账号!'.CONTINUE.
      ENDIF.

      IF <fs_data>-transactionno IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入交易流水!'.CONTINUE.
      ENDIF.

      IF <fs_data>-transactiondate IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入交易日期!'.CONTINUE.
      ENDIF.

      IF <fs_data>-tradecurrency IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入交易货币!'.CONTINUE.
      ENDIF.

      IF <fs_data>-wrbtr IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入交易金额!'.CONTINUE.
      ENDIF.

      IF <fs_data>-kunnr_desc_yh IS INITIAL.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '请输入备注!'.CONTINUE.
      ENDIF.


      SELECT SINGLE * INTO @DATA(ls_check)  FROM ztsd015 WHERE
            ztsd015~transactionno = @<fs_data>-transactionno
        AND ztsd015~zname         = @<fs_data>-zname.
      IF ls_check IS NOT  INITIAL.
        CLEAR:ls_check.
        <fs_data>-status = 'E'.<fs_data>-status_inc = icon_led_red.<fs_data>-message = '交易流水号已存在!'.CONTINUE.
      ELSE.
        CLEAR:ls_check.
      ENDIF.

    ENDLOOP.

  ENDIF.


ENDFORM.


FORM download_template USING pu_filename pu_objid.
*& 下载模版
  DATA: ls_objdata LIKE wwwdatatab.
  DATA: lv_filename TYPE string,
        lv_fullpath TYPE string  VALUE 'C:\',
        lv_path     TYPE  string VALUE 'C:\'.
  DATA: lv_errtxt TYPE string.
  DATA: lv_destination LIKE rlgrap-filename.
  DATA: lv_rc LIKE sy-subrc.

  DATA: lv_fileup LIKE rlgrap-filename.

  lv_filename = pu_filename .
*& 调用保存对话框
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      default_extension    = 'xlsx'
      default_file_name    = lv_filename
      initial_directory    = 'C:\'
    CHANGING
      filename             = lv_filename
      path                 = lv_path
      fullpath             = lv_fullpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc NE 0.
    MESSAGE '不能打开EXCEL' TYPE 'E'.
  ENDIF.
  CHECK lv_fullpath IS NOT INITIAL .
  lv_fileup = lv_fullpath.
  ls_objdata-relid = 'MI' .
  ls_objdata-objid = pu_objid .

  lv_destination = lv_fullpath .
  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      key         = ls_objdata
      destination = lv_destination
    IMPORTING
      rc          = lv_rc.
  IF lv_rc NE 0.
    CONCATENATE '模板文件:' ls_objdata-objid '下载失败' INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'E'.
  ELSE.
    MESSAGE '模版下载成功' TYPE 'S'.
  ENDIF.

ENDFORM.                    " DOWNLOAD_TEMPLATE



FORM set_catalog.
  DATA:lv_position TYPE i VALUE 1.
  CLEAR: lv_position.
  lv_position = lv_position + 1.
* 预定义一个输出模式
  DEFINE df_fieldcat.
    CLEAR gs_fieldcat_lvc.
    gs_fieldcat_lvc-col_pos     = lv_position."ALV 控制: 输出列
    gs_fieldcat_lvc-scrtext_m   = &1."中字段标签
    gs_fieldcat_lvc-fieldname   = &2."ALV 控制: 内部表字段的字段名称
    gs_fieldcat_lvc-no_zero     = &3."ALV 控制: 为输出隐藏零
    gs_fieldcat_lvc-checkbox    = &4."ALV 控制: 作为复选框输出
    gs_fieldcat_lvc-edit        = &5."设置可编辑模式
    gs_fieldcat_lvc-outputlen   = &6."输出长度
    gs_fieldcat_lvc-ref_table   = &7.
    gs_fieldcat_lvc-ref_field   = &8.
    gs_fieldcat_lvc-datatype    = &9.
    APPEND gs_fieldcat_lvc TO gt_fieldcat_lvc.

    ADD 1 TO lv_position.
  END-OF-DEFINITION.
  df_fieldcat:

    '序号' 'ZINDEX' 'X' '' '' '' '' '' '',
    '勾选框' 'CHECKED' 'X' 'X' 'X' '' '' '' '',

    '状态灯' 'STATUS_INC' 'X' '' '' '' '' '' '',
    '状态' 'STATUS' 'X' '' '' '' '' '' '',
    '消息文本' 'MESSAGE' 'X' '' '' '' '' '' '',

     'In' 'STATUS_INC_I' 'X' '' '' '' '' '' '',"流水初始确认
     'A' 'STATUS_INC_A' 'X' '' '' '' '' '' '' ,"流水业务员确认
     'P' 'STATUS_INC_P' 'X' '' '' '' '' '' '', "凭证过账
*     'C' 'STATUS_INC_C' 'X' '' '' '' '' '' '',"凭证清账
    '匹配情况' 'ZTRUE' 'X' 'X' '' '' '' '' '',
    '销售机构' 'VKORG' 'X' '' 'X' '' '' '' '',
    '财务年度' 'GJAHR' 'X' '' '' '' '' '' '',
    '凭证号码' 'BELNR' 'X' '' '' '' '' '' '',
    '凭证状态' 'BSTAT' 'X' '' '' '' '' '' '',
    '售达方'   'KUNNR' 'X' '' 'X' '' '' '' '',
    '客户名称' 'KUNNR_DESC' 'X' '' '' '' '' '' '',
    '客户付款名称' 'KUNNR_DESC_YH' 'X' '' '' '' '' '' '',
    '次数' 'ZTIMES' 'X' '' '' '' '' '' '',
    '收款银行' 'ZNAME' 'X' '' '' '' '' '' '',
    '收款账号' 'ZACCOUNT' 'X' '' '' '' '' '' '',
    '交易流水' 'TRANSACTIONNO' 'X' '' '' '' '' '' '',
    '交易日期' 'TRANSACTIONDATE' 'X' '' '' '' '' '' '',
    '交易货币' 'TRADECURRENCY' 'X' '' '' '' '' '' '',
    '到账金额' 'WRBTR' 'X' '' '' '' '' '' '',
    '手续费' 'WRBTR_CHARGE' 'X' '' '' '' '' '' '',
    '水单备注'   'BANK_BAK' 'X' '' '' '' '' '' '',
    '交易类型' 'TRANSACTIONTYPE' 'X' '' '' '' '' '' '',
    '业务类型' 'BUSINESSTYPE' 'X' '' '' '' '' '' '',
    '付款人开户行号' 'ACCOUNTPAYER' 'X' '' '' '' '' '' '',
    '付款人开户行名' 'PAYER' 'X' '' '' '' '' '' '',
    '付款人账号' 'DEBITACCOUNT' 'X' '' '' '' '' '' '',
    '付款人名称' 'PAYERNAME' 'X' '' '' '' '' '' '',
    '会计确认' 'ZIN' 'X' 'X' '' '' '' '' '',
    '创建日期' 'MODIFIYDATE' 'X' '' '' '' '' '' '',
    '创建时间' 'MODIFIYTIME' 'X' '' '' '' '' '' '',
    '创建人'   'MODIFIEDBY' 'X' '' '' '' '' '' '',
    '收款单ID' 'ZID' 'X' '' '' '' '' '' ''
  .


  IF p_sel2 = 'X' . "查询

    LOOP AT gt_fieldcat_lvc INTO gs_fieldcat_lvc.
      IF
            gs_fieldcat_lvc-fieldname = 'CHECKED'
           OR gs_fieldcat_lvc-fieldname = 'STATUS_INC'
           OR gs_fieldcat_lvc-fieldname = 'STATUS'
           OR gs_fieldcat_lvc-fieldname = 'MESSAGE'
           OR gs_fieldcat_lvc-fieldname = 'ZTRUE'
           OR gs_fieldcat_lvc-fieldname = 'ZTIMES'
    .
        DELETE  gt_fieldcat_lvc.
        CONTINUE.
      ENDIF.

      IF gs_fieldcat_lvc-fieldname = 'VKORG'.
        gs_fieldcat_lvc-edit = ''.
      ENDIF.

      IF gs_fieldcat_lvc-fieldname = 'KUNNR'.
        gs_fieldcat_lvc-edit = ''.
      ENDIF.

      MODIFY gt_fieldcat_lvc FROM gs_fieldcat_lvc.
    ENDLOOP.

  ELSEIF p_inp = 'X' . "导入

    LOOP AT gt_fieldcat_lvc INTO gs_fieldcat_lvc.
      IF     gs_fieldcat_lvc-fieldname = 'STATUS_INC_I'
           OR gs_fieldcat_lvc-fieldname = 'STATUS_INC_A'
           OR gs_fieldcat_lvc-fieldname = 'STATUS_INC_P'
           OR gs_fieldcat_lvc-fieldname = 'STATUS_INC_C'

           OR gs_fieldcat_lvc-fieldname = 'GJAHR'
           OR gs_fieldcat_lvc-fieldname = 'BELNR'
           OR gs_fieldcat_lvc-fieldname = 'BSTAT'

    .
        DELETE  gt_fieldcat_lvc.
        CONTINUE.
      ENDIF.
    ENDLOOP.

  ENDIF.

ENDFORM.


FORM display_alv.
  DATA: ls_layout TYPE lvc_s_layo.
  IF gt_data IS NOT INITIAL.
    ls_layout-zebra      = 'X'.
    ls_layout-cwidth_opt = 'X'.
* 调用ALV function
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
      EXPORTING
        i_callback_program       = sy-repid "这里是调用这个ALV的程序名
        i_callback_pf_status_set = 'PF_STATUS' "设置ALV状态栏的函数
        i_callback_user_command  = 'USER_COMMAND' "获取用户事件的函数
        is_layout_lvc            = ls_layout "显示的布局
        it_fieldcat_lvc          = gt_fieldcat_lvc "设置显示的字段以及字段的功能
        i_save                   = 'A'
      TABLES
        t_outtab                 = gt_data
      EXCEPTIONS
        program_error            = 1.
    IF sy-subrc <> 0.
      MESSAGE '报表生成异常,请联系系统管理员!' TYPE 'S' DISPLAY LIKE 'E'.
    ENDIF.
  ELSE.
* 这个消息用来显示我们是不是获取到了数据,自己用的时候把这个硬代码换成你需要的TEXT-XXX.
    MESSAGE '没有获取到数据,请重新检索!' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE TO LIST-PROCESSING.
    EXIT.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  GET_DATA_FOR_ZTSD015
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_for_ztsd015 .

  SELECT
         ztsd015~zid,"ID
         ztsd015~vkorg,"销售组织
         ztsd015~kunnr,"售达方
*         ztsd015~kunnr_desc,"客户名称
         ztsd015~kunnr_desc_yh,
         ztsd015~modifiydate,"修改记录的日期
         ztsd015~modifiytime,"修改时间
         ztsd015~modifiedby ,"修改人
         ztsd015~transactionno,  "交易流水
         ztsd015~transactiontype,"交易类型
         ztsd015~businesstype,   "业务类型
         ztsd015~accountpayer,   "付款人开户行号
         ztsd015~payer,          "付款人开户行名
         ztsd015~debitaccount,   "付款人账号
         ztsd015~payername,      "付款人名称
         ztsd015~transactiondate,"交易日期
         ztsd015~tradecurrency,  "交易货币
         ztsd015~wrbtr,          "收款金额
         ztsd015~wrbtr_charge,   "手续费
         ztsd015~wrbtr_charge2,  "手续费 - 业务补充
         ztsd015~wrbtr_2,        "分配余额
         ztsd015~wrbtr_3,        "挂预收款
         ztsd015~wrbtr_4,        "挂预收佣金
         ztsd015~bstkd,
         ztsd015~zin,            "会计确认
         ztsd015~za,             "业务确认
         ztsd015~zp,             "凭证过账
         ztsd015~zc,             "凭证清账
         ztsd015~modifiydate_za, "业务确认日期
         ztsd015~modifiytime_za, "业务确认时间
         ztsd015~modifiedby_za,  "业务确认人
         ztsd015~zname,          "收款银行
         ztsd015~zaccount,       "收款账号
         ztsd015~belnr,          "会计凭证号码
         ztsd015~gjahr,          "财务年度
         ztsd015~bank_bak,       "水单备注
         kna1~name1 && kna1~name2 AS  kunnr_desc,
         knb1~akont AS kunnr_akont "客户应收统驭科目
      INTO CORRESPONDING FIELDS OF TABLE @gt_data FROM  ztsd015
         LEFT  JOIN  knb1  ON knb1~kunnr = ztsd015~kunnr AND knb1~bukrs = ztsd015~vkorg
         LEFT  JOIN  kna1  ON kna1~kunnr = knb1~kunnr
    WHERE
        knb1~bukrs  IN @so_vkorg
    AND knb1~kunnr  IN @so_kunnr
    AND ztsd015~transactionno   IN @so_trans
    AND ztsd015~transactiondate IN @so_trane
    AND ztsd015~modifiedby      IN @so_usr02
    .

  "Added by zhong on 20220719 添加 E 锁对象
  LOOP AT gt_data INTO gs_data.
    PERFORM lock_record USING  gs_data-zid.
  ENDLOOP.

  SORT gt_data BY vkorg kunnr ASCENDING transactiondate ASCENDING.
  IF gt_data IS NOT INITIAL.

    SELECT bukrs ,belnr ,gjahr,bstat INTO TABLE @DATA(lt_bkpf) FROM bkpf FOR ALL ENTRIES IN @gt_data
      WHERE bkpf~bukrs = @gt_data-vkorg
        AND bkpf~belnr = @gt_data-belnr
       AND  bkpf~gjahr = @gt_data-gjahr.

    SELECT * FROM knvp INTO TABLE @DATA(lt_knvp) FOR ALL ENTRIES IN @gt_data WHERE  knvp~kunnr = @gt_data-kunnr AND knvp~vkorg = @gt_data-vkorg.
    SORT lt_knvp BY vkorg kunnr parvw.

    LOOP AT gt_data ASSIGNING <fs_data>.

      <fs_data>-budat  = <fs_data>-transactiondate. "过账日期 = 交易日期
      "设置凭证的过账状态
      READ TABLE lt_bkpf INTO DATA(ls_bkpf) WITH  KEY  bukrs = <fs_data>-vkorg belnr = <fs_data>-belnr gjahr = <fs_data>-gjahr .
      IF sy-subrc = 0.
        <fs_data>-bstat = ls_bkpf-bstat.
        IF <fs_data>-bstat = 'V'.
          <fs_data>-status_inc_p = icon_led_yellow.
        ELSE.
          <fs_data>-status_inc_p = icon_led_green.
        ENDIF.
      ENDIF.

      "SET送达方
      READ TABLE lt_knvp INTO DATA(ls_knvp) WITH  KEY  kunnr = <fs_data>-kunnr vkorg = <fs_data>-vkorg parvw = 'WE' BINARY SEARCH.
      IF sy-subrc = 0.
        <fs_data>-kunnr2 = ls_knvp-kunn2.
      ENDIF.

*      "业务员
*      READ TABLE lt_knvp INTO ls_knvp       WITH  KEY  kunnr = <fs_data>-kunnr vkorg = <fs_data>-vkorg parvw = 'VE' BINARY SEARCH.
*      IF sy-subrc = 0.
*        SELECT SINGLE pa0001~sname,pa0001~pernr INTO @DATA(ls_pa0001) FROM pa0001 WHERE pernr = @ls_knvp-pernr.
*        <fs_data>-sname = ls_pa0001-sname.
*        <fs_data>-pernr = ls_pa0001-pernr.
*      ENDIF.

      "SET业务员
      LOOP AT lt_knvp INTO ls_knvp  WHERE kunnr = <fs_data>-kunnr AND vkorg = <fs_data>-vkorg AND parvw = 'VE'.

        SELECT SINGLE pa0001~sname,pa0001~pernr INTO @DATA(ls_pa0001) FROM pa0001 WHERE pernr = @ls_knvp-pernr.

        DATA: len TYPE i.

        CONCATENATE ls_pa0001-sname <fs_data>-sname  INTO <fs_data>-sname SEPARATED BY ','.

        CONCATENATE ls_pa0001-pernr <fs_data>-pernr  INTO <fs_data>-pernr SEPARATED BY ','.

      ENDLOOP.

      CLEAR:len.
      len             = strlen( <fs_data>-sname ).
      len             = len - 1.
      IF <fs_data>-sname IS NOT INITIAL.
        <fs_data>-sname = <fs_data>-sname+0(len).
      ENDIF.

      CLEAR:len.
      len             = strlen( <fs_data>-pernr ).
      len             = len - 1.
      IF <fs_data>-pernr IS NOT INITIAL.
        <fs_data>-pernr = <fs_data>-pernr+0(len).
      ENDIF.

      "SET银行过账科目配置表
      SELECT SINGLE * INTO @DATA(ls_ztsd017) FROM ztsd017
        WHERE ztsd017~vkorg    = @<fs_data>-vkorg
          AND ztsd017~waers    = @<fs_data>-tradecurrency
          AND ztsd017~zaccount = @<fs_data>-zaccount.

      IF sy-subrc = 0.
        <fs_data>-hkont         = ls_ztsd017-hkont.         " 银行科目
        <fs_data>-hkont_in      = ls_ztsd017-hkont_in.      " 财务费用-银行手续费
        <fs_data>-kunnr_akont2  = ls_ztsd017-kunnr_akont2.  " 预收账款-外销
        DATA:lv_string_datetime TYPE syst-msgv1.
        CLEAR:lv_string_datetime.
        CALL FUNCTION 'ZFM_TOOLS_GET_STRINGDATE'
          EXPORTING
            ztype           = 'D'
            datum           = <fs_data>-transactiondate
            uzeit           = sy-uzeit
          IMPORTING
            string_datetime = lv_string_datetime.
        "行项目文本
        CONCATENATE lv_string_datetime <fs_data>-kunnr ls_ztsd017-item_text INTO <fs_data>-item_text SEPARATED BY space.
        <fs_data>-acct_type     = ls_ztsd017-acct_type.   "账户类型
        <fs_data>-doc_type      = ls_ztsd017-doc_type.    "凭证类型
        <fs_data>-rstgr         = ls_ztsd017-rstgr.       "原因代码
        <fs_data>-rstgr_kunnr   = ls_ztsd017-rstgr_kunnr. "客户科目 不需要原因代码
        <fs_data>-xblnr         = ls_ztsd017-xblnr.       "参照
        <fs_data>-hkont_in2     = ls_ztsd017-hkont_in2.
      ENDIF.


      IF sy-mandt = '900'.
        "SET成本中心
        IF <fs_data>-kunnr_desc_yh     IS NOT INITIAL AND <fs_data>-vkorg = '3020'.
          <fs_data>-kostl = '3020999999'.
        ELSEIF <fs_data>-kunnr_desc_yh IS NOT INITIAL AND <fs_data>-vkorg = '1010'.
          <fs_data>-kostl ='1010999999'.
        ENDIF.

      ELSE.

        <fs_data>-kostl = '1010010000'.
      ENDIF.

      "SET STATUS LIGHT
      " 水单确认
      IF <fs_data>-zin = 'X'.
        <fs_data>-status_inc_i = icon_led_green.
      ENDIF.

      " 推送OMS
      IF <fs_data>-za = 'P' .    "审批中
        <fs_data>-status_inc_a = icon_led_yellow.
      ELSEIF <fs_data>-za = 'F' ."审批完成
        <fs_data>-status_inc_a = icon_led_green.
      ENDIF.

      " 凭证创建完成
      IF <fs_data>-zp = 'X' AND <fs_data>-bstat = 'V'.
        <fs_data>-status_inc_p = icon_led_yellow.
      ENDIF.

      " 凭证创建完成
      IF <fs_data>-zp = 'X' AND <fs_data>-bstat = ''.
        <fs_data>-status_inc_p = icon_led_green.
      ENDIF.

      " 清账完成
      IF <fs_data>-zc = 'X'.
        <fs_data>-status_inc_c = icon_led_green.
      ENDIF.

    ENDLOOP.

  ENDIF.

  "SET财务待办单据
  IF p_0 = 'X'.
    DELETE gt_data WHERE zp = 'X'  AND bstat = ''.
    "SET财务凭证已过账单据
  ELSEIF p_1 = 'X'.
    LOOP AT gt_data ASSIGNING <fs_data>.
      IF <fs_data>-zp = 'X' AND <fs_data>-bstat = ''.
      ELSE.
        DELETE  gt_data.
      ENDIF.
    ENDLOOP.
    "SET所有的单据
  ELSEIF p_2 = 'X'.
  ENDIF.

  "Addded by zhong on 20221129 添加排序
  SORT gt_data BY zname transactiondate.

  " SET Index of List
  LOOP AT gt_data ASSIGNING <fs_data>.
    <fs_data>-zindex = sy-tabix.
  ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_FOR_BSID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_for_bsid .

  SELECT
      bsid~bukrs,"公司代码
      bsid~kunnr,"客户
      bsid~umsks,"事务类型
      bsid~umskz,"特别总账标识
      bsid~augdt,"结算
      bsid~augbl,"清帐凭证
      bsid~zuonr,"分配
      bsid~gjahr,"财年
      bsid~belnr,"凭证编号
      bsid~buzei,"行项目
      bsid~budat,"过帐日期
      bsid~bldat,"凭证日期
      bsid~cpudt,"录入日期
      bsid~waers,"货币
      bsid~xblnr,"参照
      bsid~blart,"凭证类型
      bsid~monat,"期间
      bsid~bschl,"记帐代码
      bsid~zumsk,"特别总帐标志
      bsid~shkzg,"借方/贷方
      bsid~gsber,"业务范围
      bsid~mwskz,"税码
      bsid~dmbtr,"本位币金额
      bsid~wrbtr,"金额
      bsid~mwsts,"LC 税额
      bsid~wmwst,"税额
      bsid~bdiff,"估价差额
      bsid~bdif2,"估价差额 2
      bsid~sgtxt,"文本
      bsid~projn,"未在使用中的
      bsid~aufnr,"订单
      bsid~anln1,"资产
      bsid~anln2,"次级编号
      bsid~saknr,"总帐科目
      bsid~hkont,"总帐
      bsid~fkont,"财务预算
      bsid~filkd,"分支
      bsid~zfbdt,"基限日期
      bsid~zterm,"付款条件
      bsid~zbd1t,"天数 1
      bsid~zbd2t,"天数 2
      bsid~zbd3t,"天内净额
      bsid~zbd1p,"折扣百分比 1
      bsid~zbd2p"折扣百分比 2
    INTO CORRESPONDING FIELDS OF TABLE  @lt_bsid  FROM bsid WHERE bsid~bukrs  IN @so_vkorg AND bsid~kunnr  IN @so_kunnr.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA_FOR_BSID_BY2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SO_VKORG_LOW  text
*      -->P_SO_VKORG_HIGH  text
*----------------------------------------------------------------------*
FORM get_data_for_bsid_by2  USING    p_vkorg TYPE vkorg
                                     p_kunnr TYPE kunnr.

  SELECT
     bsid~bukrs,"公司代码
     bsid~kunnr,"客户
     bsid~umsks,"事务类型
     bsid~umskz,"特别总账标识
     bsid~augdt,"结算
     bsid~augbl,"清帐凭证
     bsid~zuonr,"分配
     bsid~gjahr,"财年
     bsid~belnr,"凭证编号
     bsid~buzei,"行项目
     bsid~budat,"过帐日期
     bsid~bldat,"凭证日期
     bsid~cpudt,"录入日期
     bsid~waers,"货币
     bsid~xblnr,"参照
     bsid~blart,"凭证类型
     bsid~monat,"期间
     bsid~bschl,"记帐代码
     bsid~zumsk,"特别总帐标志
     bsid~shkzg,"借方/贷方
     bsid~gsber,"业务范围
     bsid~mwskz,"税码
     bsid~dmbtr,"本位币金额
     bsid~wrbtr,"金额
     bsid~mwsts,"LC 税额
     bsid~wmwst,"税额
     bsid~bdiff,"估价差额
     bsid~bdif2,"估价差额 2
     bsid~sgtxt,"文本
     bsid~projn,"未在使用中的
     bsid~aufnr,"订单
     bsid~anln1,"资产
     bsid~anln2,"次级编号
     bsid~saknr,"总帐科目
     bsid~hkont,"总帐
     bsid~fkont,"财务预算
     bsid~filkd,"分支
     bsid~zfbdt,"基限日期
     bsid~zterm,"付款条件
     bsid~zbd1t,"天数 1
     bsid~zbd2t,"天数 2
     bsid~zbd3t,"天内净额
     bsid~zbd1p,"折扣百分比 1
     bsid~zbd2p"折扣百分比 2
   INTO CORRESPONDING FIELDS OF TABLE  @lt_bsid  FROM bsid WHERE
         bsid~bukrs = @p_vkorg
     AND bsid~kunnr = @p_kunnr
     AND bsid~blart = 'RV'
     .

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  DEAR_DATA_FOR_BSID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_SO_VKORG_LOW  text
*      -->P_SO_KUNNR_HIGH  text
*----------------------------------------------------------------------*
FORM dear_data_for_bsid  USING   p_vkorg TYPE vkorg
                                 p_kunnr TYPE kunnr.
  DATA:lv_exit TYPE c.
  " 清账匹配
  TYPES:BEGIN OF ly_sum_month,
          bukrs   TYPE  bsid-bukrs, "公司代码
          kunnr   TYPE  bsid-kunnr, "客户
          zmonth  TYPE num10,
          wrbtr   TYPE  bsid-wrbtr, "金额
          zstatus TYPE  c, "ID
          zid     TYPE ztsd015-zid, "ID
        END OF ly_sum_month.

  DATA:ls_sum_month TYPE ly_sum_month.
  DATA:lt_sum_month TYPE TABLE OF ly_sum_month.
  FIELD-SYMBOLS: <fs_summ>  TYPE  ly_sum_month.

  SORT lt_bsid BY bukrs kunnr ASCENDING  bldat ASCENDING.

  " 对不同凭证类型的处理 @TODO -----------
  " RV h s 分配号相同冲销
  DATA(lt_bsid_s) = lt_bsid.
  DATA(lt_bsid_h) = lt_bsid.
  REFRESH :lt_bsid.
  DELETE lt_bsid_s WHERE shkzg = 'H'.
  DELETE lt_bsid_h WHERE shkzg = 'S'.
  LOOP AT lt_bsid_s ASSIGNING <fs_bsid> WHERE bukrs = p_vkorg AND kunnr = p_kunnr AND zstatus = '' AND shkzg = 'S'.
    READ TABLE lt_bsid_h ASSIGNING FIELD-SYMBOL(<fs_bsid_h>) WITH  KEY xblnr = <fs_bsid>-xblnr wrbtr = <fs_bsid>-wrbtr.
    IF sy-subrc = 0.
*      <fs_bsid>-zstatus        = 'X'.
      <fs_bsid>-status_inc_c   = icon_led_green.
*      <fs_bsid_h>-zstatus      = 'X'.
      <fs_bsid_h>-status_inc_c = icon_led_green. " 可被清账提示灯
    ENDIF.
    APPEND <fs_bsid> TO lt_bsid.
  ENDLOOP.

*  LOOP AT lt_bsid_h ASSIGNING <fs_bsid> WHERE bukrs = p_vkorg AND kunnr = p_kunnr AND shkzg = 'H'.
*    <fs_bsid>-wrbtr = <fs_bsid>-wrbtr  * -1.
*    <fs_bsid>-dmbtr = <fs_bsid>-dmbtr  * -1.
*    APPEND <fs_bsid> TO lt_bsid.
*  ENDLOOP.
*
*
*  "1,单笔发票金额 = 收款金额
*  LOOP AT lt_bsid ASSIGNING <fs_bsid> WHERE bukrs = p_vkorg AND kunnr = p_kunnr AND zstatus = ''.
*    "检查被锁定的情况
*    SELECT SINGLE * FROM ztsd018 INTO @DATA(ls_ztsd018) WHERE ztsd018~za = 'P'
*      AND ztsd018~bukrs = @p_vkorg
*      AND ztsd018~gjahr = @<fs_bsid>-gjahr
*      AND ztsd018~belnr = @<fs_bsid>-belnr
*      AND ztsd018~buzei = @<fs_bsid>-buzei.
*
*    IF ls_ztsd018 IS NOT INITIAL.
*      <fs_bsid>-status_inc_a = icon_locked.
*      <fs_bsid>-zstatus  = 'X'.
*      <fs_bsid>-zid      = <fs_data>-zid.
*      <fs_bsid>-in_wrbtr = <fs_bsid>-wrbtr.
*      CLEAR:ls_ztsd018.
*      lv_exit = 'R'.
*      CONTINUE.
*    ENDIF.
*  ENDLOOP.
*
*  IF lv_exit = 'R'.
*    CLEAR: lv_exit.
*    RETURN.
*  ENDIF.
*
*
*  SORT lt_bsid BY bukrs kunnr xblnr ASCENDING  bldat ASCENDING.
*  "1,单笔发票金额 = 收款金额
*  LOOP AT lt_bsid ASSIGNING <fs_bsid> WHERE bukrs = p_vkorg AND kunnr = p_kunnr AND zstatus = ''.
*
*    <fs_bsid>-zmonth = <fs_bsid>-budat+0(6).
*
*    READ TABLE gt_data ASSIGNING <fs_data> WITH  KEY checked = 'X' vkorg = <fs_bsid>-bukrs  kunnr = <fs_bsid>-kunnr wrbtr = <fs_bsid>-wrbtr zstatus = ''.
*    IF sy-subrc = 0.
*
*      <fs_bsid>-zstatus  = 'X'.
*      <fs_bsid>-zid      = <fs_data>-zid.
*      <fs_bsid>-in_wrbtr = <fs_bsid>-wrbtr.
*      <fs_bsid>-status_inc_a = icon_unlocked.
*
*      <fs_data>-zstatus  = 'X'.
*      <fs_data>-wrbtr2   = <fs_bsid>-wrbtr.
*      <fs_data>-wrbtr3   = '0'.
*
*    ELSE.
*
*      <fs_bsid>-zmonth      = <fs_bsid>-budat+0(6).
*
*      ls_sum_month-zmonth   = <fs_bsid>-zmonth.
*      ls_sum_month-wrbtr    = <fs_bsid>-wrbtr.
*      ls_sum_month-bukrs    = <fs_bsid>-bukrs.
*      ls_sum_month-kunnr    = <fs_bsid>-kunnr.
*      COLLECT ls_sum_month INTO lt_sum_month.
*    ENDIF.
*
*  ENDLOOP.


*    "2,应收月份 sum(IN) = 单笔流水---
*
*    LOOP AT lt_sum_month ASSIGNING <fs_summ>.
*      READ TABLE gt_data ASSIGNING <fs_data> WITH  KEY vkorg = <fs_summ>-bukrs  kunnr = <fs_summ>-kunnr wrbtr = <fs_summ>-wrbtr zstatus = ''.
*      IF sy-subrc = 0.
*        <fs_summ>-zstatus = 'X'.
*        <fs_summ>-zid     = <fs_data>-zid.
*        <fs_data>-zstatus  = 'X'.
*        <fs_data>-wrbtr2   = <fs_bsid>-wrbtr.
*        <fs_data>-wrbtr3   = '0'.
*      ENDIF.
*    ENDLOOP.
*
*    LOOP AT lt_sum_month ASSIGNING <fs_summ> WHERE zstatus = 'X'.
*      LOOP AT lt_bsid ASSIGNING <fs_bsid> WHERE zmonth = <fs_summ>-zmonth AND bukrs = <fs_summ>-bukrs AND wrbtr = <fs_summ>-wrbtr AND zstatus = ''.
*        <fs_bsid>-zstatus  = 'X'.
*        <fs_bsid>-zid      = <fs_summ>-zid.
*        <fs_bsid>-in_wrbtr = <fs_bsid>-wrbtr.
*
*
*        <fs_data>-zstatus  = 'X'.
*        <fs_data>-wrbtr2   = <fs_bsid>-wrbtr.
*        <fs_data>-wrbtr3   = '0'.
*      ENDLOOP.
*    ENDLOOP.


*  "3,顺冲
*  DATA:lv_wrbtr TYPE bsid-wrbtr.
*
*
*  LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked = 'X' AND zstatus = '' .
*
*    lv_wrbtr = <fs_data>-wrbtr.
*    lv_exit  = ''.
*    DO 20 TIMES.
*
*      LOOP AT lt_bsid ASSIGNING <fs_bsid> WHERE  zstatus = '' AND bukrs = p_vkorg AND kunnr = p_kunnr.
*        IF lv_wrbtr > <fs_bsid>-wrbtr. " 收款金额大于发票金额
*
*          lv_wrbtr = lv_wrbtr - <fs_bsid>-wrbtr.
*          <fs_bsid>-zstatus  = 'X'.
*          <fs_bsid>-zid      = <fs_data>-zid.
*          <fs_bsid>-in_wrbtr = <fs_bsid>-wrbtr.
*
*          <fs_bsid>-status_inc_a = icon_unlocked.
*
*          <fs_data>-wrbtr2   = <fs_bsid>-wrbtr + <fs_data>-wrbtr2.
*          <fs_data>-wrbtr3   = <fs_data>-wrbtr - <fs_data>-wrbtr2.
*
*        ELSEIF   lv_wrbtr = <fs_bsid>-wrbtr. " 收款金额 = 发票金额
*
*          <fs_bsid>-zstatus  = 'X'.
*          <fs_bsid>-zid      = <fs_data>-zid.
*          <fs_bsid>-in_wrbtr = <fs_bsid>-wrbtr.
*
*          <fs_bsid>-status_inc_a = icon_unlocked.
*
*          <fs_data>-zstatus  = 'X'.
*          <fs_data>-wrbtr2   = <fs_bsid>-wrbtr + <fs_data>-wrbtr2.
*          <fs_data>-wrbtr3   = <fs_data>-wrbtr  - <fs_data>-wrbtr2.
*
*        ELSE. " 单笔收款还有剩
*          lv_exit = 'R'.
*          EXIT.
*        ENDIF.
*
*      ENDLOOP.
*
*      IF  lv_exit = 'R'.
*        EXIT.
*      ENDIF.
*
*    ENDDO.
*
*  ENDLOOP.

  SORT lt_bsid BY blart bukrs kunnr bldat belnr buzei  xblnr.



ENDFORM.



FORM  lock_record  USING  p_key .

  DATA : it_seqg3  TYPE  seqg3  OCCURS  01  WITH HEADER LINE .
  DATA : gname LIKE  seqg3-gname,
         garg  LIKE  seqg3-garg.

  DATA : BEGIN OF ls_ztsd015 ,
           mandt TYPE  ztsd015-mandt,
           zid   TYPE  ztsd015-zid,
         END OF  ls_ztsd015 .
*---锁定函数初始化:
  CALL  'C_ENQ_WILDCARD'  ID  'HEX0'  FIELD  ls_ztsd015 .

*---对关键字的赋值
  MOVE  sy-mandt TO ls_ztsd015-mandt .
  MOVE  p_key    TO ls_ztsd015-zid .
  gname  =  'ZTSD015' .
  garg   =  ls_ztsd015 .

*---读取是否已经被锁定
  CALL FUNCTION 'ENQUEUE_READ'
    EXPORTING
      gclient = sy-mandt
      gname   = gname
      garg    = garg
    TABLES
      enq     = it_seqg3.

  IF  sy-subrc <>  0 .
    MESSAGE ID  sy-msgid  TYPE  sy-msgty  NUMBER  sy-msgno  WITH  sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
  ENDIF .

  IF  it_seqg3  IS NOT INITIAL .

    DATA:lt_list_mess  TYPE esp1_message_tab_type  WITH HEADER LINE .
    DATA:lv_verid      TYPE char32.
    SELECT SINGLE  * INTO @DATA(ls_015) FROM ztsd015 WHERE zid = @p_key.

    CONCATENATE  ls_015-transactionno  ' 正由 '  it_seqg3-guname  ' 处理 !'  INTO  lv_verid .
    lt_list_mess-msgty  = 'E' .
    lt_list_mess-msgv1  = lv_verid.
    lt_list_mess-msgid  = 'ZMC01'.
    lt_list_mess-msgno  = '000'.

    APPEND lt_list_mess.

    IF lt_list_mess[] IS NOT INITIAL.

      CALL FUNCTION 'C14Z_MESSAGES_SHOW_AS_POPUP'
        TABLES
          i_message_tab = lt_list_mess.

      STOP.LEAVE TO SCREEN 0.EXIT.

*        DATA: lv_answer TYPE string.              "用于存储用户选择
*        CALL FUNCTION 'POPUP_TO_DECIDE_WITH_MESSAGE'
*          EXPORTING
*            diagnosetext1 = ''  "诊断文本的第一行
*            textline1     = ''         "弹出窗口的第一行,设置文本行内容1
*            text_option1  = '继续打印'      "选项 1 的文本。
*            text_option2  = '退出打印'  "选项 2 的文本。
*            titel         = '提示框'  "设置标题
*          IMPORTING
*            answer        = lv_answer.  "获得用户选择,这里返回的值对应是当前列表NO,比如第一个就返回1,第二个返回2
*
*        IF lv_answer = 'A' OR lv_answer = '2'.
*          STOP.
*          LEAVE TO LIST-PROCESSING.EXIT.
*        ENDIF.

    ENDIF.



  ELSE .
*---开始锁定记录
*加锁时,不管这个表中有没有这个条目,都会加锁成功(即sy-subrc = 0)。加锁后,再操作同一条目,会提示XXX正在处理!
    CALL FUNCTION 'ENQUEUE_EZTSD015'
      EXPORTING
        mode_ztsd015   = 'E'
        mandt          = sy-mandt
        zid            = p_key
        x_zid          = ''
        _scope         = '2'
        _wait          = ''
        _collect       = ''
      EXCEPTIONS
        foreign_lock   = 1
        system_failure = 2
        OTHERS         = 3.
    IF  sy-subrc <>  0 .
      MESSAGE ID  sy-msgid  TYPE  sy-msgty  NUMBER  sy-msgno  WITH  sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 .
    ENDIF .
  ENDIF .
ENDFORM .                     "lock_record

*------------------------------ 解鎖 -------------------------------------
FORM  unlock_record  USING  p_key .

  CALL FUNCTION 'DEQUEUE_EZTSD015'
    EXPORTING
      mode_ztsd015 = 'E'
      mandt        = sy-mandt
      zid          = p_key
      x_zid        = ''
      _scope       = '3'
      _synchron    = ''
      _collect     = ''.

ENDFORM.                    "unlock_record


*&---------------------------------------------------------------------*
*&  包含                ZFI068_PBO
*&---------------------------------------------------------------------*

FORM pf_status USING i_it_extab TYPE slis_t_extab.

  REFRESH:i_it_extab.

  IF p_inp = 'X'. " 导入
    SET TITLEBAR 'ZSTATUS_TITLE'.
*    APPEND 'ZSAVE'  TO i_it_extab.
    APPEND 'ZCSAVE' TO i_it_extab.
    APPEND 'ZDEL'   TO i_it_extab.
*    APPEND 'ZSAL'   TO i_it_extab.
*    APPEND 'ZALL'   TO i_it_extab.
*    APPEND 'ZSAVE1'   TO i_it_extab.
    SET PF-STATUS 'ZSTATUS_001' EXCLUDING i_it_extab.
  ENDIF.


  IF p_sel2 = 'X'."查询
    SET TITLEBAR 'ZSTATUS_TITLE'.
    APPEND 'ZSAVE'  TO i_it_extab.
    APPEND 'ZCSAVE' TO i_it_extab.
    APPEND 'ZDEL'   TO i_it_extab.
    APPEND 'ZSAL'   TO i_it_extab.
    APPEND 'ZALL'   TO i_it_extab.
    APPEND 'ZSAVE1'   TO i_it_extab.
    SET PF-STATUS 'ZSTATUS_001' EXCLUDING i_it_extab.
  ENDIF.



ENDFORM.



*&---------------------------------------------------------------------*
*&  包含                ZFI068_PAI
*&---------------------------------------------------------------------*

FORM user_command USING i_ucomm TYPE sy-ucomm
                            i_wa_selfield TYPE slis_selfield.
  DATA:gwa_edit TYPE lvc_s_styl,
       git_edit TYPE lvc_t_styl.

  DATA lv_length TYPE num10.
  DATA lr_grid TYPE REF TO cl_gui_alv_grid.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.
  CALL METHOD lr_grid->check_changed_data.
  CALL METHOD lr_grid->refresh_table_display.
  i_wa_selfield-refresh = 'X'.


  CASE i_ucomm.

    WHEN  'ZSAVE'. " 流水导入

      DATA:lt_ztsd015 TYPE TABLE OF ztsd015.
      DATA:ls_ztsd015 TYPE  ztsd015.
      DATA:lt_ztsd016 TYPE TABLE OF ztsd016.
      DATA:ls_ztsd016 TYPE  ztsd016.

      LOOP AT gt_data ASSIGNING <fs_data> WHERE checked = 'X' AND status = ''.

        " 1,检查 交易流水号在数据库中是否存在 - 写入前检查 ,第二次预防
        SELECT SINGLE * INTO @DATA(ls_cc) FROM ztsd015 WHERE ztsd015~transactionno = @<fs_data>-transactionno.
        IF sy-subrc = 0.
          <fs_data>-status     = 'E'.
          <fs_data>-status_inc = icon_led_red.
          <fs_data>-message    = '导入失败,交易流水已存在'.
          CONTINUE.
        ENDIF.

        CLEAR:  ls_ztsd015.
        REFRESH:lt_ztsd015.

        <fs_data>-modifiedby  = sy-uname.
        <fs_data>-modifiydate = sy-datum.
        <fs_data>-modifiytime = sy-uzeit.
        <fs_data>-zin         = 'X'.

        CALL METHOD cl_system_uuid=>if_system_uuid_static~create_uuid_c32
          RECEIVING
            uuid = <fs_data>-zid.

        MOVE-CORRESPONDING <fs_data> TO ls_ztsd015.

*        SELECT SINGLE * INTO @DATA(ls_kna1) FROM kna1 WHERE kna1~kunnr = @ls_ztsd015-kunnr.
*
*        ls_ztsd015-kunnr_desc_yh = <fs_data>-kunnr_desc_yh.
*        ls_ztsd015-kunnr_desc    = ls_kna1-name1.

        APPEND ls_ztsd015 TO lt_ztsd015.
        MODIFY ztsd015 FROM TABLE lt_ztsd015.

        IF sy-subrc = 0.
          <fs_data>-status     = 'S'.
          <fs_data>-status_inc = icon_led_green.
          <fs_data>-message    = '导入成功'.
        ELSE.
          <fs_data>-status     = 'E'.
          <fs_data>-status_inc = icon_led_red.
          <fs_data>-message    = '导入失败'.
        ENDIF.

        "2,记录关键词
        IF <fs_data>-ztrue <> 'X'.
          MOVE-CORRESPONDING <fs_data> TO ls_ztsd016.
          ls_ztsd016-kunnr_desc  = <fs_data>-kunnr_desc_yh.
          ls_ztsd016-modifiedby  = sy-uname.
          ls_ztsd016-modifiydate = sy-datum.
          ls_ztsd016-modifiytime = sy-uzeit.
          MODIFY ztsd016 FROM  ls_ztsd016.
        ELSE.
          SELECT SINGLE * INTO ls_ztsd016 FROM ztsd016 WHERE ztsd016~vkorg = <fs_data>-vkorg AND  ztsd016~kunnr = <fs_data>-kunnr
            AND   ztsd016~kunnr_desc = <fs_data>-kunnr_desc_yh .
          ls_ztsd016-ztimes = ls_ztsd016-ztimes + 1.
          MODIFY ztsd016 FROM  ls_ztsd016.
        ENDIF.

      ENDLOOP.


    WHEN 'ZSEND'. "推送OMS 发邮件 外销

      PERFORM send_email USING '1'.

    WHEN 'ZSAVE1'."推送OMS 发邮件 内销

      PERFORM send_email USING '2'.



    WHEN 'ZDEL'.
    WHEN 'ZSAL'.
      LOOP AT gt_data ASSIGNING <fs_data>.
        <fs_data>-checked = ''.
      ENDLOOP.
    WHEN 'ZALL'.
      LOOP AT gt_data ASSIGNING <fs_data>.
        <fs_data>-checked = 'X'.
      ENDLOOP.
    WHEN OTHERS.

  ENDCASE.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  SEND_EMAIL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM send_email USING p_type.

  DATA: obj_exception TYPE REF TO cx_ai_system_fault.
  DATA: lo_zws3co     TYPE REF TO zws3co_create_workflow_service. "CLASS名*

  CREATE OBJECT lo_zws3co. "创建对象
  DATA:in               TYPE  zws2create_worlflow1,
       ls_parameters_in TYPE  zws2create_worlflow.
  DATA:out               TYPE  zws2create_worlflow_response1,
       ls_parameters_out TYPE  zws2create_worlflow_response,
       ls_return         TYPE  zws2create_workflow_vo.
  DATA:json_ser TYPE REF TO cl_trex_json_serializer,
       json_des TYPE REF TO cl_trex_json_deserializer.

  LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked  = 'X'  .

*        MESSAGE '功能开发中' TYPE 'I'.
*        CONTINUE.

    "推送OMS数据准备
    CALL METHOD /ui2/cl_json=>serialize
      EXPORTING
        data   = <fs_data>
      RECEIVING
        r_json = ls_parameters_in-header.

    ls_parameters_in-business_id = 'RECEIPT_EMAIL_ALL'.
    ls_parameters_in-send_time   = sy-datum && sy-uzeit.
    ls_parameters_in-from        = 'SAP'.
    ls_parameters_in-to          = 'OMS'.

    IF p_type = '1'.      "外销
      ls_parameters_in-string2     = 'chengyi.com'.
      ls_parameters_in-string3     = ''.
      ls_parameters_in-string4     = ''.
      ls_parameters_in-string5     = ''.
    ELSEIF p_type = '2'.  "内销
      ls_parameters_in-string2     = 'chengyi.com'.
      ls_parameters_in-string3     = ''.
      ls_parameters_in-string4     = ''.
      ls_parameters_in-string5     = ''.
    ENDIF.

    IF sy-mandt = '300'.

      MESSAGE '300系统不允许发邮件' TYPE 'I' .
      RETURN.

    ENDIF.

    in-parameters                   = ls_parameters_in.


    TRY.
        CALL METHOD lo_zws3co->create_worlflow
          EXPORTING
            create_worlflow          = in
          IMPORTING
            create_worlflow_response = out.
      CATCH cx_ai_system_fault INTO obj_exception.

        " 接口创建失败
        CALL METHOD obj_exception->get_text
          RECEIVING
            result = ls_return-message.

        <fs_data>-status_inc = icon_led_red.
        <fs_data>-status     = 'E'.
        <fs_data>-message    = 'SAP连接OMS异常,请联系管理员|' && ls_return-message.

    ENDTRY.

    "记录推送Log
    DATA:lv_text5 TYPE string.
    DATA:lv_text6 TYPE string.
    CALL METHOD /ui2/cl_json=>serialize
      EXPORTING
        data   = ls_parameters_in-header
      RECEIVING
        r_json = lv_text5.

    CALL FUNCTION 'ZFM_TOOLS_SAVELOG'
      EXPORTING
        programcode = 'ZSD076_2'
*       TCODE       = SY-TCODE
*       CREATEBY    = SY-UNAME
*       CREATEDATE  = SY-DATUM
*       CREATETIME  = SY-UZEIT
        text1       = '付款单邮件通知推送'
*       text2       =
*       TEXT3       =
*       TEXT4       =
        text5       = lv_text5
        text6       = lv_text6.

    IF out IS NOT INITIAL.
      "解析接口返回的信息
      ls_parameters_out   = out-parameters.
      ls_return           = ls_parameters_out-return.
      IF ls_return-status = 'S'." 接口同步成功-单据创建成功
        <fs_data>-status_inc   = icon_led_green.
        <fs_data>-status       = 'S'.
        <fs_data>-message      = '发送成功'.
*            UPDATE ztsd015 SET za = 'P'  WHERE zid = <fs_data>-zid.
      ELSE. " 接口同步成功-单据创建失败
        <fs_data>-status_inc = icon_led_red.
        <fs_data>-status     = ls_return-status.
        <fs_data>-message    = ls_return-message.
      ENDIF.
    ENDIF.

  ENDLOOP.

ENDFORM.



*&---------------------------------------------------------------------*
*&  包含                ZSD076_9001
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.
  SET PF-STATUS 'ZSTATUS_9001'.
  SET TITLEBAR  'ZSTATUS_TITLE'.
ENDMODULE.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

  CASE ok_code.
    WHEN 'EXPORT'.
** 导出特定格式的excel
    WHEN '&F03' OR '&F15' OR '&F13'.

      LOOP AT gt_data INTO gs_data.
        PERFORM unlock_record USING  gs_data-zid.
      ENDLOOP.
      LEAVE TO SCREEN 0.

    WHEN 'ZTOOMS'. " 推送OMS

      DATA: obj_exception TYPE REF TO cx_ai_system_fault.
      DATA: lo_zws3co     TYPE REF TO zws3co_create_workflow_service. "CLASS名*

      CREATE OBJECT lo_zws3co. "创建对象
      DATA:in               TYPE  zws2create_worlflow1,
           ls_parameters_in TYPE  zws2create_worlflow.
      DATA:out               TYPE  zws2create_worlflow_response1,
           ls_parameters_out TYPE  zws2create_worlflow_response,
           ls_return         TYPE  zws2create_workflow_vo.
      DATA:json_ser TYPE REF TO cl_trex_json_serializer,
           json_des TYPE REF TO cl_trex_json_deserializer.


      LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked  = 'X' AND  zin = 'X' AND  za = '' .


        CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
          EXPORTING
            input  = <fs_data>-kunnr
          IMPORTING
            output = <fs_data>-kunnr.


        "推送OMS数据准备
        CALL METHOD /ui2/cl_json=>serialize
          EXPORTING
            data   = <fs_data>
          RECEIVING
            r_json = ls_parameters_in-header.

        ls_parameters_in-business_id = 'RECEIPT'.
        ls_parameters_in-send_time   = sy-datum && sy-uzeit.
        ls_parameters_in-from        = 'SAP'.
        ls_parameters_in-to          = 'OMS'.
        ls_parameters_in-string1     = <fs_data>-pernr. "业务员编号


        IF <fs_data>-modifiedby = 'FI097'.      "外销
          ls_parameters_in-string2     = 'fi25@chengyi.com'.
          ls_parameters_in-string3     = 'Fi5516018'.
          ls_parameters_in-string4     = 'gwmy@chengyi.com,zkyw@chengyi.com'.
          ls_parameters_in-string5     = '黄培芳#联系人:黄培芳#联系电话:2081 / 188-5966-8381'.

        ELSE . "内销
          ls_parameters_in-string2     = 'fi26@chengyi.com'.
          ls_parameters_in-string3     = 'Cy5358979'.
          ls_parameters_in-string4     = 'gwmy@chengyi.com'.
          ls_parameters_in-string5     = '李汝樱#联系人:李汝樱#联系电话:2075'.

        ENDIF.

        in-parameters                = ls_parameters_in.


        TRY.
            CALL METHOD lo_zws3co->create_worlflow
              EXPORTING
                create_worlflow          = in
              IMPORTING
                create_worlflow_response = out.
          CATCH cx_ai_system_fault INTO obj_exception.

            " 接口创建失败
            CALL METHOD obj_exception->get_text
              RECEIVING
                result = ls_return-message.

            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = 'E'.
            <fs_data>-message    = 'SAP连接OMS异常,请联系管理员|' && ls_return-message.

        ENDTRY.


        IF out IS NOT INITIAL.
          "解析接口返回的信息
          ls_parameters_out        = out-parameters.
          ls_return                = ls_parameters_out-return.
          IF ls_return-status = 'S'." 接口同步成功-单据创建成功
            <fs_data>-status_inc   = icon_led_green.
            <fs_data>-status       = ls_return-status.
            "Test by zhong on 20220719
            <fs_data>-status_inc_a = icon_led_yellow.
            <fs_data>-status       = 'S'.
            <fs_data>-message      = '发送成功'.
            UPDATE ztsd015 SET za = 'P'  WHERE zid = <fs_data>-zid.
          ELSE. " 接口同步成功-单据创建失败
            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = ls_return-status.
            <fs_data>-message    = ls_return-message.
          ENDIF.
        ENDIF.


        "记录推送Log
        DATA:lv_text5 TYPE string.
        DATA:lv_text6 TYPE string.
        CALL METHOD /ui2/cl_json=>serialize
          EXPORTING
            data   = ls_parameters_in-header
          RECEIVING
            r_json = lv_text5.

        CALL FUNCTION 'ZFM_TOOLS_SAVELOG'
          EXPORTING
            programcode = 'ZSD076_1'
*           TCODE       = SY-TCODE
*           CREATEBY    = SY-UNAME
*           CREATEDATE  = SY-DATUM
*           CREATETIME  = SY-UZEIT
            text1       = '付款单推送'
*           text2       =
*           TEXT3       =
*           TEXT4       =
            text5       = lv_text5
            text6       = lv_text6.



      ENDLOOP.


    WHEN 'ZREOMS'.

*      DATA: obj_exception TYPE REF TO cx_ai_system_fault.
*      DATA: lo_zws3co     TYPE REF TO zws3co_create_workflow_service. "CLASS名*

      CREATE OBJECT lo_zws3co. "创建对象
*      DATA:in               TYPE  zws2create_worlflow1,
*           ls_parameters_in TYPE  zws2create_worlflow.
*      DATA:out               TYPE  zws2create_worlflow_response1,
*           ls_parameters_out TYPE  zws2create_worlflow_response,
*           ls_return         TYPE  zws2create_workflow_vo.
*      DATA:json_ser TYPE REF TO cl_trex_json_serializer,
*           json_des TYPE REF TO cl_trex_json_deserializer.


      LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked  = 'X' AND  zin = 'X' AND  za = 'F' AND zp = '' .

*        MESSAGE '功能开发中' TYPE 'I'.
*        CONTINUE.

        "推送OMS数据准备
        CALL METHOD /ui2/cl_json=>serialize
          EXPORTING
            data   = <fs_data>
          RECEIVING
            r_json = ls_parameters_in-header.

        ls_parameters_in-business_id = 'RECEIPT_RETURN'.
        ls_parameters_in-send_time   = sy-datum && sy-uzeit.
        ls_parameters_in-from        = 'SAP'.
        ls_parameters_in-to          = 'OMS'.
        ls_parameters_in-string1     = <fs_data>-pernr. "业务员编号

        in-parameters                = ls_parameters_in.


        TRY.
            CALL METHOD lo_zws3co->create_worlflow
              EXPORTING
                create_worlflow          = in
              IMPORTING
                create_worlflow_response = out.
          CATCH cx_ai_system_fault INTO obj_exception.

            " 接口创建失败
            CALL METHOD obj_exception->get_text
              RECEIVING
                result = ls_return-message.

            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = 'E'.
            <fs_data>-message    = 'SAP连接OMS异常,请联系管理员|' && ls_return-message.

        ENDTRY.


*        "记录推送Log
*        DATA:lv_text5 TYPE string.
*        DATA:lv_text6 TYPE string.
        CALL METHOD /ui2/cl_json=>serialize
          EXPORTING
            data   = ls_parameters_in-header
          RECEIVING
            r_json = lv_text5.

        CALL FUNCTION 'ZFM_TOOLS_SAVELOG'
          EXPORTING
            programcode = 'ZSD076_2'
*           TCODE       = SY-TCODE
*           CREATEBY    = SY-UNAME
*           CREATEDATE  = SY-DATUM
*           CREATETIME  = SY-UZEIT
            text1       = '付款单退回'
*           text2       =
*           TEXT3       =
*           TEXT4       =
            text5       = lv_text5
            text6       = lv_text6.


        IF out IS NOT INITIAL.
          "解析接口返回的信息
          ls_parameters_out        = out-parameters.
          ls_return                = ls_parameters_out-return.
          IF ls_return-status = 'S'." 接口同步成功-单据创建成功
            <fs_data>-status_inc   = icon_led_green.
            <fs_data>-status       = ls_return-status.
            "Test by zhong on 20220719
            <fs_data>-status_inc_a = icon_led_yellow.
            <fs_data>-status       = 'S'.
            <fs_data>-message      = '发送成功'.


            UPDATE ztsd015 SET za = 'P'  WHERE zid = <fs_data>-zid.
            DELETE FROM ztsd018  WHERE ztsd015_id = <fs_data>-zid.

          ELSE. " 接口同步成功-单据创建失败
            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = ls_return-status.
            <fs_data>-message    = ls_return-message.
          ENDIF.
        ENDIF.

      ENDLOOP.


    WHEN 'ZPOST'. " 凭证过账
      "1, 创建之前 检查收款流水 是否符合创建凭证
      "2,创建收款凭证
      "3, 3.1 收款银行科目指定 ,3.2 客户统驭科目指定  3.3 文本 内容 3.4 抬头参照

      DATA: gs_documentheader    TYPE bapiache09,   "表头
            gs_customercpd       TYPE bapiacpa09,   "会计记帐: 业务伙伴开票凭证 (可接收负载)
            gs_fica_hd           TYPE bapiaccahd,   "应收和应付附加合同帐户表头行

            gt_accountreceivable TYPE TABLE OF bapiacar09,     "客户项目
            gs_accountreceivable TYPE  bapiacar09,     "客户项目
            gt_accountgl         TYPE TABLE OF bapiacgl09 ,    "总帐科目
            gs_accountgl         TYPE  bapiacgl09 ,    "总帐科目
            gt_accounttax        TYPE TABLE OF bapiactx09 ,    "税务项目
            gs_accounttax        TYPE  bapiactx09 ,    "税务项目
            gt_criteria          TYPE TABLE OF bapiackec9 ,    "会计记帐:CO-PA 科目分配特性
            gs_criteria          TYPE  bapiackec9 ,    "会计记帐:CO-PA 科目分配特性
            gt_valuefield        TYPE TABLE OF bapiackev9 ,    "会计记帐:CO-PA 科目分配值字段
            gs_valuefield        TYPE  bapiackev9 ,    "会计记帐:CO-PA 科目分配值字段
            gt_currencyamount    TYPE TABLE OF bapiaccr09 ,    "货币项目
            gs_currencyamount    TYPE  bapiaccr09 ,    "货币项目
            gt_return            TYPE TABLE OF bapiret2   ,    "返回参数
            gs_return            TYPE  bapiret2   ,    "返回参数
            gt_receivers         TYPE TABLE OF bdi_logsys ,    "传输逻辑系统的结
            gs_receivers         TYPE  bdi_logsys ,    "传输逻辑系统的结
            gt_fica_it           TYPE TABLE OF bapiaccait ,    "应收和应付附加合同帐户行项目
            gs_fica_it           TYPE  bapiaccait ,    "应收和应付附加合同帐户行项目
            gt_accountpayable    TYPE TABLE OF bapiacap09 ,    "供应商项目
            gs_accountpayable    TYPE  bapiacap09 ,    "供应商项目
            gt_paymentcard       TYPE TABLE OF bapiacpc09 ,    "付款卡信息
            gs_paymentcard       TYPE  bapiacpc09 ,    "付款卡信息
            gt_extension1        TYPE TABLE OF bapiacextc ,    "客户退出' 参数的容器
            gs_extension1        TYPE  bapiacextc ,    "客户退出' 参数的容器
            gt_realestate        TYPE TABLE OF bapiacre09 ,    "不动产科目分配数据
            gs_realestate        TYPE  bapiacre09 ,    "不动产科目分配数据
            gt_extension2        TYPE TABLE OF bapiparex  ,    "BAPI 参数 ExtensionIn/ExtensionOut 的参考结构
            gs_extension2        TYPE bapiparex  .    "BAPI 参数 ExtensionIn/ExtensionOut 的参考结构

      DATA: wa_zexten LIKE zexten_fi. "就是刚才se11创建的那个结构

      DATA:lv_type    TYPE c,
           lv_message TYPE char255.

      DATA:lv_posnr_acc TYPE posnr_acc.
      DATA:lv_item_text TYPE ztsd017-item_text.
      DATA:lv_bstat TYPE c.
      DATA:lv_doc_status TYPE c.

      lv_bstat      = 'V'.
      lv_doc_status = '2'.

      " Added by zhong on 20221208
      TYPES:BEGIN OF ly_pos,
              posnr TYPE char2,
            END OF ly_pos.
      DATA:lt_pos TYPE TABLE OF ly_pos.
      DATA:ls_pos TYPE  ly_pos.

      " Added by zhong on 20221208
      TYPES:BEGIN OF ly_pos_for_v,
              posnr TYPE char2,
            END OF ly_pos_for_v.
      DATA:lt_pos_for_v TYPE TABLE OF ly_pos_for_v.
      DATA:ls_pos_for_v TYPE  ly_pos_for_v.


      LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked  = 'X' AND za = 'F' AND  zp <> 'X'.

        CLEAR:  gs_documentheader,gs_customercpd,gs_fica_hd .
        CLEAR:  gs_accountreceivable,gs_accountgl ,  gs_accounttax, gs_criteria  , gs_valuefield , gs_currencyamount,
                gs_return , gs_receivers,  gs_fica_it, gs_accountpayable, gs_paymentcard,  gs_extension1, gs_realestate, gs_extension2.

        REFRESH :  gt_accountreceivable,gt_accountgl ,  gt_accounttax, gt_criteria  , gt_valuefield , gt_currencyamount,
                   gt_return , gt_receivers,  gt_fica_it, gt_accountpayable, gt_paymentcard,  gt_extension1, gt_realestate, gt_extension2.

        REFRESH :lt_pos.

        SELECT SINGLE *
          INTO @DATA(ls_ztsd017)  FROM ztsd017
            WHERE ztsd017~vkorg = @<fs_data>-vkorg AND ztsd017~waers = @<fs_data>-tradecurrency AND ztsd017~zaccount = @<fs_data>-zaccount.

        IF ls_ztsd017 IS INITIAL.
          <fs_data>-status     = 'E'.
          <fs_data>-message    = '账户信息未维护'.
          <fs_data>-status_inc = icon_led_red.
          CONTINUE.
        ENDIF.

        DATA:lv_string_datetime LIKE  syst-msgv1.

        CALL FUNCTION 'ZFM_TOOLS_GET_STRINGDATE'
          EXPORTING
            ztype           = 'D'
*           datum1          =
*           datum2          =
            datum           = <fs_data>-transactiondate
            uzeit           = sy-uzeit
          IMPORTING
            string_datetime = lv_string_datetime.


        lv_item_text = <fs_data>-item_text.
*        lv_item_text = lv_string_datetime && <fs_data>-kunnr && ls_ztsd017-item_text.

        "凭证抬头
        gs_documentheader-doc_status = lv_doc_status.
        gs_documentheader-comp_code  = <fs_data>-vkorg.       "公司代码
        gs_documentheader-doc_date   = <fs_data>-budat.       "凭证日期
        gs_documentheader-pstng_date = <fs_data>-budat.       "过账日期
        gs_documentheader-fis_period = <fs_data>-budat+4(2).  "过账期间

        SELECT SINGLE * INTO @DATA(ls_t001) FROM t001 WHERE t001~bukrs = @<fs_data>-vkorg.

        IF <fs_data>-tradecurrency <> ls_t001-waers.
          gs_documentheader-trans_date = <fs_data>-transactiondate. "换算日期 = 交易日期
        ENDIF.

        gs_documentheader-doc_type   = ls_ztsd017-doc_type .  "证类类型
        gs_documentheader-username   = sy-uname.              "过账人
        gs_documentheader-header_txt = lv_item_text.          "抬头文本
        gs_documentheader-ref_doc_no = <fs_data>-xblnr .      "参照

        IF <fs_data>-wrbtr > 0.

          "银行存款账户
          lv_posnr_acc = 1.
          gs_accountgl-itemno_acc = lv_posnr_acc.       "会计凭证行项目编号 类型POSNR_ACCNUMC10
          gs_accountgl-gl_account = ls_ztsd017-hkont.   "'1002020101'."总分类帐帐目HKONTCHAR10
          gs_accountgl-item_text  = lv_item_text.       "项目文本SGTXTCHAR50
          gs_accountgl-acct_type  = <fs_data>-acct_type."帐户类型KOARTCHAR1
          gs_accountgl-alloc_nmbr = <fs_data>-transactiondate.   "分配号 ACPI_ZUONRCHAR18
          gs_accountgl-value_date = <fs_data>-transactiondate.   "起息日 VALUTDATS8
*        gs_accountgl-de_cre_ind = 'S' .              "标识: 后续借/贷 ACPI_TBTKZCHAR1
          APPEND gs_accountgl TO gt_accountgl.

          CLEAR: wa_zexten.
          wa_zexten-posnr = lv_posnr_acc.            "凭证行项目
          wa_zexten-bschl = '40'.                    "记账码
          wa_zexten-rstgr = <fs_data>-rstgr.         "凭证行项目原因代码
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          CLEAR: gs_currencyamount.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.            "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency. "货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  <fs_data>-wrbtr.         "到账金额  凭证货币金额BAPIDOCCUR|DEC23|4
*        gs_currencyamount-exch_rate = '6.123456'.
          APPEND gs_currencyamount TO gt_currencyamount.

        ENDIF.

        "-- 手续费
        IF <fs_data>-wrbtr_charge > 0 OR <fs_data>-wrbtr_charge2 > 0.

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR: gs_accountgl.
          gs_accountgl-itemno_acc =  lv_posnr_acc.       "会计凭证行项目编号 类型POSNR_ACCNUMC10
          gs_accountgl-gl_account =  <fs_data>-hkont_in. "'5002020101'."总分类帐帐目HKONTCHAR10
          gs_accountgl-item_text  =  lv_item_text.       "项目文本SGTXTCHAR50
          gs_accountgl-acct_type  =  <fs_data>-acct_type."帐户类型KOARTCHAR1
          gs_accountgl-alloc_nmbr =  <fs_data>-transactiondate.          "分配号 ACPI_ZUONRCHAR18
*          gs_accountgl-de_cre_ind = 'S' .               "标识: 后续借/贷 ACPI_TBTKZCHAR1
          APPEND gs_accountgl TO gt_accountgl.

          CLEAR: wa_zexten.
          wa_zexten-bschl = '40'.
          wa_zexten-posnr = lv_posnr_acc.           "凭证行项目
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          CLEAR:gs_currencyamount.
          gs_currencyamount-itemno_acc  =  lv_posnr_acc.            "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency    =  <fs_data>-tradecurrency ."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur  =  <fs_data>-wrbtr_charge + <fs_data>-wrbtr_charge2.  "凭证货币金额BAPIDOCCUR|DEC23|4
*          gs_currencyamount-exch_rate = '6.123456'.
          APPEND gs_currencyamount TO gt_currencyamount.

        ENDIF.

        "-- 收款余额:挂预收款 客户统驭科目
        IF <fs_data>-wrbtr_3 > 0.

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountgl.

          gs_accountreceivable-itemno_acc = lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr.        "客户编号KUNNRCHAR10|0
*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont2."预收 总分类帐帐目HKONTCHAR10|0
          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg.        "信贷控制范围
          gs_accountreceivable-alloc_nmbr = <fs_data>-transactiondate.               "分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text.           "项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.        "行项目的参考码

          gs_accountreceivable-bline_date = <fs_data>-transactiondate."到期日计算的基限日期ACPI_ZFBDTDATS8|0

*          gs_accountreceivable-paymt_ref  = ''."付款参考码

          APPEND gs_accountreceivable TO gt_accountreceivable.

          CLEAR: wa_zexten.
          wa_zexten-posnr = lv_posnr_acc.                "凭证行项目
          wa_zexten-umskz = '1'.                         "特别总账标识
          wa_zexten-bschl = '19'.                        "记账码 19 特别总账标识
          wa_zexten-bstat = lv_bstat.
          wa_zexten-rstgr = ls_ztsd017-rstgr_in2.        "原因代码 14
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          CLEAR:gs_currencyamount.
          gs_currencyamount-itemno_acc  =  lv_posnr_acc.           " 会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency    =  <fs_data>-tradecurrency." 货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur  =  <fs_data>-wrbtr_3 * -1. " 余额 凭证货币金额BAPIDOCCUR|DEC23|4
          APPEND gs_currencyamount TO gt_currencyamount.

          " Added by zhong on 20221221
          ls_pos_for_v-posnr = lv_posnr_acc+8(2).
          APPEND ls_pos_for_v TO lt_pos_for_v.

        ENDIF.

        "-- 收款余额:挂预佣金 客户统驭科目
        IF <fs_data>-wrbtr_4 > 0.

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountgl.
          gs_accountgl-itemno_acc =  lv_posnr_acc."会计凭证行项目编号 类型POSNR_ACCNUMC10
          gs_accountreceivable-itemno_acc = lv_posnr_acc.          "会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr.       "客户编号KUNNRCHAR10|0

*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont2."预收 总分类帐帐目HKONTCHAR10|0
          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg.        "信贷控制范围
          gs_accountreceivable-alloc_nmbr = sy-datum.               "分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text.           "项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.
          gs_accountreceivable-bline_date = <fs_data>-transactiondate."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          gs_accountreceivable-paymt_ref  = ''."付款参考码

          APPEND gs_accountreceivable TO gt_accountreceivable.

          CLEAR: wa_zexten.
          wa_zexten-posnr = lv_posnr_acc.            "凭证行项目
          wa_zexten-umskz = '9'.                     "特别总账标识
          wa_zexten-bschl = '19'.                    "记账码 19 特别总账标识
          wa_zexten-bstat = lv_bstat.
          wa_zexten-rstgr = ls_ztsd017-rstgr_in2.     "原因代码 15
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          CLEAR:gs_currencyamount.
          gs_currencyamount-itemno_acc  =  lv_posnr_acc.           " 会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency    =  <fs_data>-tradecurrency." 货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur  =  <fs_data>-wrbtr_4 * -1. " 余额 凭证货币金额BAPIDOCCUR|DEC23|4
          APPEND gs_currencyamount TO gt_currencyamount.


          " Added by zhong on 20221221
          ls_pos_for_v-posnr = lv_posnr_acc+8(2).
          APPEND ls_pos_for_v TO lt_pos_for_v.

        ENDIF.

        "-- 预收 冲 应收
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no = '' AND  rstgr = '14' ." other condition

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountreceivable ,gs_currencyamount,wa_zexten.
          "客户统驭科目
          gs_accountreceivable-itemno_acc = lv_posnr_acc.   "会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr."客户编号KUNNRCHAR10|0
*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont."总分类帐帐目HKONTCHAR10|0
          gs_accountreceivable-alloc_nmbr = ls_bsid-zuonr."分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text."项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.
          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg."信贷控制范围

*          gs_accountreceivable-bline_date = sy-datum."到期日计算的基限日期ACPI_ZFBDTDATS8|0

          SELECT SINGLE * INTO @DATA(ls_bsid_1) FROM bsid
               WHERE   bukrs = @<fs_data>-vkorg AND kunnr = @<fs_data>-kunnr
                   AND gjahr = @ls_bsid-gjahr AND belnr = @ls_bsid-belnr  AND buzei = @ls_bsid-buzei .
          IF sy-subrc = 0.
            gs_accountreceivable-bline_date = ls_bsid_1-zfbdt."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          ENDIF.
          CLEAR:ls_bsid_1.

*         gs_accountreceivable-ref_key_3  = .  "行项目的参考码XREF3CHAR20|0
          APPEND gs_accountreceivable TO gt_accountreceivable.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  ls_bsid-in_wrbtr .  "分配金额  凭证货币金额BAPIDOCCUR|DEC23|4
          APPEND gs_currencyamount TO gt_currencyamount.
          wa_zexten-posnr = lv_posnr_acc.             " 凭证行项目
          wa_zexten-bschl = '09'.                     " 特别总账标识 借方
          wa_zexten-umskz = '1'.                      " 特别总账标识                         "
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

        ENDLOOP.

        "-- 佣金 冲 应收
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no = '' AND  rstgr = '15' ." other condition

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountreceivable ,gs_currencyamount,wa_zexten.
          "客户统驭科目
          gs_accountreceivable-itemno_acc = lv_posnr_acc."会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr."客户编号KUNNRCHAR10|0

*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont."总分类帐帐目HKONTCHAR10|0

          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg."信贷控制范围

          gs_accountreceivable-alloc_nmbr = ls_bsid-zuonr."分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text. "项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.

*          gs_accountreceivable-bline_date = sy-datum."到期日计算的基限日期ACPI_ZFBDTDATS8|0

          SELECT SINGLE * INTO @ls_bsid_1 FROM bsid
            WHERE   bukrs = @<fs_data>-vkorg AND kunnr = @<fs_data>-kunnr
                  AND gjahr = @ls_bsid-gjahr AND belnr = @ls_bsid-belnr   AND buzei = @ls_bsid-buzei .
          IF sy-subrc = 0.
            gs_accountreceivable-bline_date = ls_bsid_1-zfbdt."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          ENDIF.
          CLEAR:ls_bsid_1.

*         gs_accountreceivable-ref_key_3  = .  "行项目的参考码XREF3CHAR20|0
          APPEND gs_accountreceivable TO gt_accountreceivable.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  ls_bsid-in_wrbtr .  "分配金额  凭证货币金额BAPIDOCCUR|DEC23|4
          APPEND gs_currencyamount TO gt_currencyamount.
          wa_zexten-posnr = lv_posnr_acc.            "凭证行项目
          wa_zexten-bschl = '09'.                    "特别总账标识 借方
          wa_zexten-umskz = '9'.                     "特别总账标识                         "
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

        ENDLOOP.

        "-- (OA)折扣冲应收 ,走主营业务收入折扣
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no <> ''  ." other condition

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR: gs_accountgl.
          gs_accountgl-itemno_acc =  lv_posnr_acc.       "会计凭证行项目编号 类型POSNR_ACCNUMC10
          gs_accountgl-gl_account =  ls_ztsd017-hkont_in2. "''.折扣科目
          gs_accountgl-item_text  =  lv_item_text.       "项目文本SGTXTCHAR50
          gs_accountgl-acct_type  =  <fs_data>-acct_type."帐户类型KOARTCHAR1

          gs_accountgl-alloc_nmbr =  ls_bsid-oa_no .      "分配号 ACPI_ZUONRCHAR18
          gs_accountgl-costcenter = <fs_data>-kostl.

*          gs_accountgl-value_date =  sy-datum."起息日 VALUTDATS8
*          gs_accountgl-de_cre_ind = 'S' ."标识: 后续借/贷 ACPI_TBTKZCHAR1
*          gs_accountgl-sales_grp  = '1015'."销售组
*          gs_accountgl-sales_off  = '110'. "销售办事处

          APPEND gs_accountgl TO gt_accountgl.

          CLEAR: wa_zexten.
          wa_zexten-bschl = '40'.
          wa_zexten-posnr = lv_posnr_acc.           "凭证行项目
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          CLEAR:gs_currencyamount.
          gs_currencyamount-itemno_acc  =  lv_posnr_acc.            "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency    =  <fs_data>-tradecurrency ."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur  =  ls_bsid-in_wrbtr.  "凭证货币金额BAPIDOCCUR|DEC23|4

          APPEND gs_currencyamount TO gt_currencyamount.

          ls_pos-posnr = lv_posnr_acc+8(2).
          APPEND ls_pos TO lt_pos.

        ENDLOOP.

        "-- 手工凭证,被冲
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no = '' AND rstgr = '13'.

          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountreceivable ,gs_currencyamount,wa_zexten.
          "客户统驭科目
          gs_accountreceivable-itemno_acc = lv_posnr_acc."会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr."客户编号KUNNRCHAR10|0

*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont."总分类帐帐目HKONTCHAR10|0
          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg.        "信贷控制范围
          gs_accountreceivable-alloc_nmbr = ls_bsid-zuonr."分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text."项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.

          SELECT SINGLE * INTO @ls_bsid_1 FROM bsid
                         WHERE   bukrs = @<fs_data>-vkorg AND kunnr = @<fs_data>-kunnr
                             AND gjahr = @ls_bsid-gjahr AND belnr = @ls_bsid-belnr  AND buzei = @ls_bsid-buzei .
          IF sy-subrc = 0.
            gs_accountreceivable-bline_date = ls_bsid_1-zfbdt."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          ENDIF.
          CLEAR:ls_bsid_1.

*         gs_accountreceivable-ref_key_3  = .  "行项目的参考码XREF3CHAR20|0
          APPEND gs_accountreceivable TO gt_accountreceivable.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  ls_bsid-in_wrbtr * -1.  "分配金额  凭证货币金额BAPIDOCCUR|DEC23|4
          APPEND gs_currencyamount TO gt_currencyamount.
          wa_zexten-posnr = lv_posnr_acc.                  "凭证行项目
          wa_zexten-bschl = '11'.                          "
          wa_zexten-rstgr = <fs_data>-rstgr_kunnr.         "原因代码
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          " Added by zhong on 20221221
          ls_pos_for_v-posnr = lv_posnr_acc+8(2).
          APPEND ls_pos_for_v TO lt_pos_for_v.

        ENDLOOP.

        "-- 应收发票,被冲
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no = '' AND rstgr = '' AND blart = 'RV'." other condition
          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountreceivable ,gs_currencyamount,wa_zexten.
          "客户统驭科目
          gs_accountreceivable-itemno_acc = lv_posnr_acc."会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr."客户编号KUNNRCHAR10|0

*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont."总分类帐帐目HKONTCHAR10|0

          gs_accountreceivable-alloc_nmbr = ls_bsid-zuonr."分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text."项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.

          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg.        "信贷控制范围


          SELECT SINGLE * INTO @ls_bsid_1 FROM bsid
               WHERE   bukrs = @<fs_data>-vkorg AND kunnr = @<fs_data>-kunnr
                   AND gjahr = @ls_bsid-gjahr AND belnr = @ls_bsid-belnr  AND buzei = @ls_bsid-buzei .
          IF sy-subrc = 0.
            gs_accountreceivable-bline_date = ls_bsid_1-zfbdt."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          ENDIF.
          CLEAR:ls_bsid_1.

          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg."信贷控制范围

*         gs_accountreceivable-ref_key_3  = .  "行项目的参考码XREF3CHAR20|0
          APPEND gs_accountreceivable TO gt_accountreceivable.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  ls_bsid-in_wrbtr * -1.  "分配金额  凭证货币金额BAPIDOCCUR|DEC23|4

*          gs_currencyamount-exch_rate = '6.123456'.

          APPEND gs_currencyamount TO gt_currencyamount.
          wa_zexten-posnr = lv_posnr_acc.                  "凭证行项目
          wa_zexten-bschl = '11'.                          "
          wa_zexten-rstgr = <fs_data>-rstgr_kunnr.         "原因代码
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.

          " Added by zhong on 20221221
          ls_pos_for_v-posnr = lv_posnr_acc+8(2).
          APPEND ls_pos_for_v TO lt_pos_for_v.

        ENDLOOP.


        " Added by zhong on 20221102 退货发票被冲
        "-- 应收发票,被冲
        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid AND  oa_no = '' AND rstgr = 'ZZ' AND blart = 'RV'." other condition
          lv_posnr_acc = lv_posnr_acc + 1.
          CLEAR:gs_accountreceivable ,gs_currencyamount,wa_zexten.
          "客户统驭科目
          gs_accountreceivable-itemno_acc = lv_posnr_acc."会计凭证行项目编号 POSNR_ACCNUMC10|0
          gs_accountreceivable-customer   = <fs_data>-kunnr."客户编号KUNNRCHAR10|0

*          gs_accountreceivable-gl_account = <fs_data>-kunnr_akont."总分类帐帐目HKONTCHAR10|0

          gs_accountreceivable-alloc_nmbr = ls_bsid-zuonr."分配号 ACPI_ZUONRCHAR18|0
          gs_accountreceivable-item_text  = lv_item_text."项目文本SGTXTCHAR50|0
          gs_accountreceivable-ref_key_3  = <fs_data>-kunnr.


          SELECT SINGLE * INTO @ls_bsid_1 FROM bsid
               WHERE   bukrs = @<fs_data>-vkorg AND kunnr = @<fs_data>-kunnr
                   AND gjahr = @ls_bsid-gjahr AND belnr = @ls_bsid-belnr  AND buzei = @ls_bsid-buzei .
          IF sy-subrc = 0.
            gs_accountreceivable-bline_date = ls_bsid_1-zfbdt."到期日计算的基限日期ACPI_ZFBDTDATS8|0
          ENDIF.
          CLEAR:ls_bsid_1.

          gs_accountreceivable-c_ctr_area = <fs_data>-vkorg."信贷控制范围

*         gs_accountreceivable-ref_key_3  = .  "行项目的参考码XREF3CHAR20|0
          APPEND gs_accountreceivable TO gt_accountreceivable.
          gs_currencyamount-itemno_acc   =  lv_posnr_acc.           "会计凭证行项目编号 POSNR_ACC|NUMC10|0
          gs_currencyamount-currency     =  <fs_data>-tradecurrency."货币码 WAERS|CUKY5|0
          gs_currencyamount-amt_doccur   =  ls_bsid-in_wrbtr.  "分配金额  凭证货币金额BAPIDOCCUR|DEC23|4

*          gs_currencyamount-exch_rate = '6.123456'.

          APPEND gs_currencyamount TO gt_currencyamount.
          wa_zexten-posnr = lv_posnr_acc.                  "凭证行项目
          wa_zexten-bschl = '01'.                          "
          wa_zexten-rstgr = '10'.         "原因代码
          wa_zexten-bstat = lv_bstat.
          gs_extension2-structure  = 'ZEXTEN_FI'.
          gs_extension2-valuepart1 = wa_zexten.
          APPEND gs_extension2 TO gt_extension2.
        ENDLOOP.




        "CHECK 凭证 -----------
        CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
          EXPORTING
            documentheader    = gs_documentheader
*           CUSTOMERCPD       = CUSTOMERCPD
*           CONTRACTHEADER    = CONTRACTHEADER
          TABLES
            accountgl         = gt_accountgl
            accountreceivable = gt_accountreceivable
            accountpayable    = gt_accountpayable
            accounttax        = gt_accounttax
            currencyamount    = gt_currencyamount
*           CRITERIA          = GT_CRITERIA
*           VALUEFIELD        =
*           EXTENSION1        =
            return            = gt_return
*           PAYMENTCARD       =
*           CONTRACTITEM      =
            extension2        = gt_extension2
*           REALESTATE        =
*           ACCOUNTWT         =
          .
        IF sy-subrc = 0.
          CLEAR:lv_message,lv_type.
          LOOP AT gt_return INTO gs_return.
            <fs_data>-status     = gs_return-type.
            <fs_data>-message    = gs_return-message.
            <fs_data>-status_inc = icon_led_green.
            IF gs_return-type = 'E'.
              lv_type    = gs_return-type.
              lv_message = lv_message && '|' && gs_return-message.
            ENDIF.
          ENDLOOP.

          IF lv_type = 'E'.
            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = lv_type.
            <fs_data>-message    = lv_message.
            CONTINUE.

          ENDIF.
        ENDIF.


        SELECT SINGLE * INTO @DATA(ls_ztsd010) FROM ztsd010 WHERE ztsd010~id = 'ZSD076'.
        IF sy-subrc = 0 AND ls_ztsd010-status = 'X'.
        ELSE.
          <fs_data>-status_inc = icon_led_red.
          <fs_data>-status     = 'E'.
          <fs_data>-message    = '凭证创建功能未启用'.
          CONTINUE.

        ENDIF.


        CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
          EXPORTING
            documentheader    = gs_documentheader
*           CUSTOMERCPD       = CUSTOMERCPD
*           CONTRACTHEADER    = CONTRACTHEADER
          TABLES
            accountgl         = gt_accountgl
            accountreceivable = gt_accountreceivable
            accountpayable    = gt_accountpayable
            accounttax        = gt_accounttax
            currencyamount    = gt_currencyamount
            criteria          = gt_criteria
*           VALUEFIELD        =
*           EXTENSION1        =
            return            = gt_return
*           PAYMENTCARD       =
*           CONTRACTITEM      =
            extension2        = gt_extension2
*           REALESTATE        =
*           ACCOUNTWT         =
          .

        IF sy-subrc = 0.

          CLEAR:lv_message,lv_type.

          LOOP AT gt_return INTO gs_return.
            <fs_data>-status  = gs_return-type.
            <fs_data>-message = gs_return-message.
            IF gs_return-type = 'E'.
              lv_type    = gs_return-type.
              lv_message = lv_message && '|' && gs_return-message.
            ENDIF.
          ENDLOOP.

          IF lv_type <> 'E'.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.

            READ TABLE gt_return INTO gs_return WITH  KEY type = 'S'.
            IF sy-subrc = 0.

              <fs_data>-status       = gs_return-type.
              <fs_data>-message      = gs_return-message.
              <fs_data>-zin          = 'X'.
              <fs_data>-gjahr        = gs_return-message_v2+14(4).
              <fs_data>-belnr        = gs_return-message_v2+0(10).
              <fs_data>-status_inc_p = icon_led_yellow.
              <fs_data>-status_inc   = icon_led_green.
              <fs_data>-bstat        = 'V'.

              UPDATE ztsd015 SET zp = 'X'  belnr = <fs_data>-belnr  gjahr = <fs_data>-gjahr  WHERE zid = <fs_data>-zid.
              "Added by zhong on 20221212
              UPDATE ztsd018 SET zp = 'X'  WHERE ztsd015_id = <fs_data>-zid.

              "Added by zhong on 20221208 修改预制凭证-----------------------------
              DATA:lv_fvkorg TYPE bdcdata-fval.
              DATA:lv_fbelnr TYPE bdcdata-fval.
              DATA:lv_fgjahr TYPE bdcdata-fval.

              IF lt_pos IS NOT INITIAL.

                LOOP AT lt_pos INTO ls_pos.

                  CLEAR:lv_fvkorg,lv_fbelnr,lv_fgjahr.

                  lv_fvkorg = <fs_data>-vkorg.
                  lv_fbelnr = <fs_data>-belnr.
                  lv_fgjahr = <fs_data>-gjahr.

                  CALL FUNCTION 'ZFM_EX_SD011'
                    EXPORTING
*                     CTU       = 'X'
*                     MODE      = 'N'
*                     UPDATE    = 'L'
*                     GROUP     =
*                     USER      =
*                     KEEP      =
*                     HOLDDATE  =
*                     NODATA    = '/'
                      bukrs_001 = lv_fvkorg
                      belnr_002 = lv_fbelnr
                      gjahr_003 = lv_fgjahr
*                     XBLNR_004 = '1'
*                     BKTXT_005 = '11/19 HA021 入中行'
*                     WRBTR_006 = '50.00'
*                     DMBTR_007 = '336.25'
*                     ZUONR_008 = '10001'
*                     SGTXT_009 = '11/19 HA021 入中行1'
*                     FMORE_010 = 'X'
*                     KOSTL_011 = ''
                      char2     = ls_pos-posnr
*             IMPORTING
*                     SUBRC     =
*             TABLES
*                     MESSTAB   =
                    .
                ENDLOOP.
              ENDIF.

              IF lt_pos_for_v IS NOT INITIAL.

                LOOP AT lt_pos_for_v INTO ls_pos_for_v.

                  CLEAR:lv_fvkorg,lv_fbelnr,lv_fgjahr.
                  lv_fvkorg = <fs_data>-vkorg.
                  lv_fbelnr = <fs_data>-belnr.
                  lv_fgjahr = <fs_data>-gjahr.

                  CALL FUNCTION 'ZFM_EX_SD012_1'
                    EXPORTING
*                     CTU       = 'X'
*                     MODE      = 'N'
*                     UPDATE    = 'L'
*                     GROUP     =
*                     USER      =
*                     KEEP      =
*                     HOLDDATE  =
*                     NODATA    = '/'
                      bukrs_001 = lv_fvkorg
                      belnr_002 = lv_fbelnr
                      gjahr_003 = lv_fgjahr
*                     XBLNR_004 = '1'
*                     BKTXT_005 = '日期HA021入中行'
*                     WRBTR_006 = '10.00'
*                     DMBTR_007 = '67.25'
*                     ZFBDT_008 = '2022.11.19'
*                     REBZG_009 = ''
*                     ZUONR_010 = '20221121'
*                     SGTXT_011 = '日期HA021入中行'
                      char2     = ls_pos_for_v-posnr
*                 IMPORTING
*                     SUBRC     =
*                 TABLES
*                     MESSTAB   =
                    .
                ENDLOOP.

              ENDIF.

            ENDIF.

            FREE: lt_pos_for_v ,lt_pos.

          ELSE.
            <fs_data>-status_inc = icon_led_red.
            <fs_data>-status     = lv_type.
            <fs_data>-message    = lv_message.
          ENDIF.
        ENDIF.

      ENDLOOP.




    WHEN 'ZCLOSE1'.

      READ TABLE gt_data INTO gs_data WITH  KEY checked  = 'X'.
      IF sy-subrc = 0.


        SET PARAMETER ID 'BUK'   FIELD gs_data-vkorg.
        SET PARAMETER ID 'KUN'   FIELD gs_data-kunnr.
*        SET PARAMETER ID 'X_KUNNR'   FIELD 'X'.
*        SET PARAMETER ID 'X_TESTL'   FIELD ''.

        CALL TRANSACTION 'F.13' .
*        CALL TRANSACTION 'F.13' AND SKIP FIRST SCREEN.

      ENDIF.

    WHEN 'ZCLOSE'. " 清账

      READ TABLE gt_data INTO gs_data WITH  KEY checked  = 'X'.
      IF sy-subrc = 0.

        SELECT SINGLE * INTO @DATA(ls_ztsd015) FROM ztsd015 WHERE ztsd015~zid = @gs_data-zid.

        IF ls_ztsd015-za = '' AND ls_ztsd015-zin = 'X'.
          DELETE  FROM ztsd015 WHERE zid = gs_data-zid.
          MESSAGE '删除成功' TYPE 'I'.
        ENDIF.


      ENDIF.
**    WHEN 'ZCLOSE'. " 清账
**
**
**      DATA: lv_f_vkorg  LIKE  bdcdata-fval, "  '1010'  公司代码
**
**            lv_f_gjahr  LIKE  bdcdata-fval , " '2022'  年度
**
**            x_kunnr_003 LIKE  bdcdata-fval , "  'X' 选择客户
**            lv_f_kunnr  LIKE  bdcdata-fval , "  'BC004' 客户编号
**            lv_f_augdt  LIKE  bdcdata-fval , "  '2022.07.18'  清账日期
**            lv_f_zuonr  LIKE  bdcdata-fval , "     分配号
**            x_testl_006 LIKE  bdcdata-fval . "  ''  选择执行
**
**      DATA:lt_messtab  TYPE TABLE OF bdcmsgcoll .
**
**      DATA:lv_vkorg TYPE ztsd015-vkorg.
**      DATA:lv_kunnr TYPE bsid-kunnr.
**
**      LOOP AT  gt_data ASSIGNING <fs_data> WHERE checked  = 'X'.
**        lv_vkorg =  <fs_data>-vkorg.
**        lv_kunnr =  <fs_data>-kunnr.
**
**        LOOP AT lt_bsid INTO ls_bsid WHERE zid = <fs_data>-zid." other condition
***
**          lv_f_vkorg = <fs_data>-vkorg.
**          lv_f_gjahr = ls_bsid-gjahr.
***          CLEAR: lv_f_gjahr .
**          lv_f_kunnr = <fs_data>-kunnr.
***          CLEAR:  lv_f_zuonr .
**          CLEAR:  lv_f_zuonr .
**
**          lv_f_zuonr  = ls_bsid-zuonr.
**          lv_f_augdt = sy-datum.
**
******          CALL FUNCTION 'ZFM_EX_SD007'
******            EXPORTING
*******             CTU          = 'X'
*******             MODE         = 'N'
*******             UPDATE       = 'L'
*******             GROUP        =
*******             USER         =
*******             KEEP         =
*******             HOLDDATE     =
*******             NODATA       = '/'
******              low_001      = lv_f_vkorg
******              low_002      = lv_f_gjahr
******              x_kunnr_003  = 'X'
******              low_004      = lv_f_kunnr
******              augdt_005    = lv_f_augdt
******              so_zuonr_low = lv_f_zuonr
******              x_testl_006  = ''
******              xausbel_007  = 'X'
******              xnausbel_008 = 'X'
******              x_fehler_009 = 'X'
*******           IMPORTING
*******             SUBRC        =
*******             STATUS       =
*******             MESSAGE      =
*******             BELNR        =
******            TABLES
******              messtab      = lt_messtab.
**
**
**          READ TABLE lt_messtab INTO DATA(ls_1) WITH  KEY msgtyp = 'S'.
**          IF sy-subrc = 0.
**
**            LOOP AT lt_messtab INTO DATA(ls_messtab).
**              CLEAR: lv_message.
**              CALL FUNCTION 'MESSAGE_TEXT_BUILD'
**                EXPORTING
**                  msgid               = ls_messtab-msgid
**                  msgnr               = ls_messtab-msgnr
**                  msgv1               = ls_messtab-msgv1
**                  msgv2               = ls_messtab-msgv2
**                  msgv3               = ls_messtab-msgv3
**                  msgv4               = ls_messtab-msgv4
**                IMPORTING
**                  message_text_output = lv_message.
**            ENDLOOP.
**            MESSAGE lv_message TYPE 'I'.
**          ENDIF.
**
**        ENDLOOP.
**
**      ENDLOOP.

*      PERFORM get_data_for_bsid_by2 USING lv_vkorg lv_kunnr.
*      PERFORM dear_data_for_bsid    USING lv_vkorg lv_kunnr.


    WHEN OTHERS.

  ENDCASE.


  ls_stbl-row = 'X'.
  ls_stbl-col = 'X'.
  CALL METHOD g_grid1->refresh_table_display
    EXPORTING
      is_stable = ls_stbl.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  INIT_CON  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE init_con OUTPUT.

*  BREAK cyit5.
  IF gv_init = 'X'.
    CLEAR:gv_init.
    "显示第一个ALV-------------------------------------------------------------------------------------------------
    IF con1_ref IS INITIAL.
      gs_layo1-cwidth_opt = 'X'.
      gs_layo1-grid_title = '客户收款流水明细'.
      gs_layo1-zebra      = 'X'.
    ENDIF.

    add_fcat1:

       '序号' 'ZINDEX' 'X' '' '' '' '' '' '',
       '选框' 'CHECKED' 'X' 'X' 'X' '' '' '' '',
       'In' 'STATUS_INC_I' 'X' '' '' '' '' '' '', "流水初始确认
       'A' 'STATUS_INC_A' 'X' '' '' '' '' '' '',  "流水业务员确认
       'P' 'STATUS_INC_P' 'X' '' '' '' '' '' '',  "凭证过账
*       'C' 'STATUS_INC_C' 'X' '' '' '' '' '' '', "凭证清账
       'EV' 'STATUS_INC' 'X' '' '' '' '' '' '',
       '凭证编号' 'BELNR' 'X' '' '' '' '' '' '',
       '财年'     'GJAHR' 'X' '' '' '' '' '' '',
       '凭证状态' 'BSTAT' 'X' '' '' '' '' '' '',
       '销售机构' 'VKORG' 'X' '' '' '' '' '' '',
       '售达方'   'KUNNR' 'X' '' '' '' '' '' '',
       '送达方'   'KUNNR2' 'X' '' '' '' '' '' '',
       '售达方名称' 'KUNNR_DESC' 'X' '' '' '' '' '' '',
       '客户付款名称I' 'KUNNR_DESC_YH' 'X' '' '' '' '' '' '',
*     '送达方名称' 'KUNNR_DESC2' 'X' '' '' '' '' '' '',
       '业务员编号' 'PERNR' 'X' '' '' '' '' '' '',
       '业务员'     'SNAME' 'X' '' '' '' '' '' '',
       '交易日期I' 'TRANSACTIONDATE' 'X' '' '' '' '' '' '',
       '交易货币I' 'TRADECURRENCY' 'X' '' '' '' '' '' '',
       '到账金额I' 'WRBTR' 'X' '' '' '' '' '' '',
       '手续费 I' 'WRBTR_CHARGE' '' '' '' '' '' '' '',
       '手续费2'  'WRBTR_CHARGE2' '' '' '' '' '' '' '',
       '分配余额' 'WRBTR_2' '' '' '' '' '' '' '',
       '挂预收'   'WRBTR_3' '' '' '' '' '' '' '',
       '挂佣金'   'WRBTR_4' '' '' '' '' '' '' '',
       'P/I号'    'BSTKD' '' '' '' '' '' '' '',
       '水单备注|'   'BANK_BAK' 'X' '' '' '' '' '' '',
*       '分配状态' 'ZSTATUS' 'X' 'X' '' '' '' '' '',
       '+银行科目'   'HKONT' '' '' '' '' '' '' '',
       '原因(银行)' 'RSTGR' '' '' 'X' '' '' '' '',
       '+损益科目'   'HKONT_IN' '' '' '' '' '' '' '',
       '-应收科目'   'KUNNR_AKONT' '' '' '' '' '' '' '',
       '原因(客户)' 'RSTGR_KUNNR' '' '' 'X' '' '' '' '',
       '-+预收科目'   'KUNNR_AKONT2' '' '' '' '' '' '' '',
       '+主营*折扣'   'HKONT_IN2' '' '' 'X' '' '' '' '',
*       '成本中心'     'KOSTL' '' '' 'X' '' '' '' '',
       '帐户类型'   'ACCT_TYPE' '' '' '' '' '' '' '',
       '凭证类型'   'DOC_TYPE' '' '' '' '' '' '' '',
       '过账日期'   'BUDAT' '' '' 'X' '' '' '' '',
*       '换算日期'   'TRANS_DATE' '' '' 'X' '' '' '' '',
       '参照'         'XBLNR' '' '' '' '' '' '' '',
       '行项目文本'   'ITEM_TEXT' '' '' 'X' '' '' '' '',
*       '交易流水 I' 'TRANSACTIONTYPE' 'X' '' '' '' '' '' '',
*       '交易类型 I' 'TRANSACTIONTYPE' 'X' '' '' '' '' '' '',
*       '业务类型 I' 'BUSINESSTYPE' 'X' '' '' '' '' '' '',
*       '付款人开户行号 I' 'ACCOUNTPAYER' 'X' '' '' '' '' '' '',
*       '付款人开户行名 I' 'PAYER' 'X' '' '' '' '' '' '',
*       '付款人账号 I' 'DEBITACCOUNT' 'X' '' '' '' '' '' '',
*       '付款人名称 I' 'PAYERNAME' 'X' '' '' '' '' '' '',
*       '会计确认' 'ZIN' 'X' 'X' '' '' '' '' '',
*       '业务确认' 'ZA' 'X' '' '' '' '' '' '',
*       '清账凭证' 'ZBELNR' 'X' '' '' '' '' '' '',

       '水单确认日期' 'MODIFIYDATE' 'X' '' '' '' '' '' '',
       '水单确认时间' 'MODIFIYTIME' 'X' '' '' '' '' '' '',
       '水单确认人'   'MODIFIEDBY'  'X' '' '' '' '' '' '',
       '业务确认日期' 'MODIFIYDATE_ZA' 'X' '' '' '' '' '' '',
       '业务确认时间' 'MODIFIYTIME_ZA' 'X' '' '' '' '' '' '',
       '业务确认人'   'MODIFIEDBY_ZA' 'X' '' '' '' '' '' '',
       'EV状态'   'STATUS' 'X' '' '' '' '' '' '',
       '消息文本' 'MESSAGE' 'X' '' '' '' '' '' '',
       '交易流水I' 'TRANSACTIONNO' 'X' '' '' '' '' '' '',
       '收款银行I' 'ZNAME' 'X' '' '' '' '' '' '',
       '收款单ID' 'ZID' 'X' '' '' 'X' '' '' ''
      .



    CREATE OBJECT con1_ref
      EXPORTING
        container_name = 'CON1'.

    CREATE OBJECT g_grid1
      EXPORTING
        i_parent = con1_ref.

    CREATE OBJECT event_receiver. "创建事件
    SET HANDLER event_receiver->handle_user_command FOR g_grid1.     "将用户交互事件分配ALV
    SET HANDLER event_receiver->handle_toolbar      FOR g_grid1.     "将按扭事件分配ALV
    SET HANDLER event_receiver->catch_hotspotclick  FOR g_grid1.     "将按扭事件分配ALV
    SET HANDLER event_receiver->catch_change        FOR g_grid1.     "将按扭事件分配ALV
    SET HANDLER event_receiver->handle_double_click  FOR g_grid1.     "将按扭事件分配ALV

    CALL METHOD g_grid1->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified.

    CALL METHOD g_grid1->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.



    CALL METHOD g_grid1->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layo1
      CHANGING
        it_outtab       = gt_data
        it_fieldcatalog = gt_fcat1.




    "显示第二个ALV-------------------------------------------------------------------------------------------------
    IF con2_ref IS INITIAL.
      gs_layo2-cwidth_opt = 'X'.
      gs_layo2-grid_title = '客户发票未清明细'.
      gs_layo2-zebra      = 'X'.
    ENDIF.

    add_fcat2:

      'A' 'STATUS_INC_A' 'X' '' '' '' '' '' '',"流水业务员确认
*      'C' 'STATUS_INC_C' 'X' '' '' '' '' '' '',"凭证清账
      '财务年度' 'GJAHR' 'X' '' '' '' '' '' '',
      '公司代码' 'BUKRS' 'X' '' '' '' '' '' '',
      '客户编号' 'KUNNR' 'X' '' '' '10' '' '' '',
*    '事务类型' 'UMSKS' 'X' '' '' '' '' '' '',
*    '结算' 'AUGDT' 'X' '' '' '' '' '' '',
*    '清帐凭证' 'AUGBL' 'X' '' '' '' '' '' '',
      '_凭证编号_' 'BELNR' 'X' '' '' '' '' '' '',
      '行项目' 'BUZEI' 'X' '' '' '' '' '' '',
      '_过帐日期_' 'BUDAT' 'X' '' '' '' '' '' '',
*      '期间' 'MONAT' 'X' '' '' '' '' '' '',
*    '凭证日期' 'BLDAT' 'X' '' '' '' '' '' '',
*    '录入日期' 'CPUDT' 'X' '' '' '' '' '' '',
*      '参照' 'XBLNR' 'X' '' '' '' '' '' '',
      '凭证类型' 'BLART' 'X' '' '' '' '' '' '',
*      '记帐代码' 'BSCHL' 'X' '' '' '' '' '' '',
*      '特别总账标识' 'UMSKZ' 'X' '' '' '' '' '' '',
*    '特别总帐标志' 'ZUMSK' 'X' '' '' '' '' '' '',
      '借方/贷方' 'SHKZG' 'X' '' '' '' '' '' '',
*      '业务范围' 'GSBER' 'X' '' '' '' '' '' '',
*      '文本' 'SGTXT' 'X' '' '' '' '' '' '',
      '__分配号__' 'ZUONR' 'X' '' '' '' '' '' '',
*    '税码' 'MWSKZ' 'X' '' '' '' '' '' '',
*      '总帐科目' 'SAKNR' 'X' '' '' '' '' '' '',
*      '本币' 'WAERS' 'X' '' '' '' '' '' '',
*      '本位金额 I' 'DMBTR' 'X' '' '' '' '' '' '',
      '交易货币' 'WAERS' 'X' '' '' '' '' '' '',
      '凭证金额' 'WRBTR' 'X' '' '' '' '' '' '',
*    'LC 税额' 'MWSTS' 'X' '' '' '' '' '' '',
*    '税额' 'WMWST' 'X' '' '' '' '' '' '',
*    '估价差额' 'BDIFF' 'X' '' '' '' '' '' '',
*    '估价差额 2' 'BDIF2' 'X' '' '' '' '' '' '',
*    '未在使用中的' 'PROJN' 'X' '' '' '' '' '' '',
*    '订单' 'AUFNR' 'X' '' '' '' '' '' '',
*    '资产' 'ANLN1' 'X' '' '' '' '' '' '',
*    '次级编号' 'ANLN2' 'X' '' '' '' '' '' '',
*    '总帐' 'HKONT' 'X' '' '' '' '' '' '',
*    '财务预算' 'FKONT' 'X' '' '' '' '' '' '',
*    '分支' 'FILKD' 'X' '' '' '' '' '' '',
*    '基限日期' 'ZFBDT' 'X' '' '' '' '' '' '',
*    '付款条件' 'ZTERM' 'X' '' '' '' '' '' '',
*    '天数 1' 'ZBD1T' 'X' '' '' '' '' '' '',
*    '天数 2' 'ZBD2T' 'X' '' '' '' '' '' '',
*    '天内净额' 'ZBD3T' 'X' '' '' '' '' '' '',
*    '折扣百分比 1' 'ZBD1P' 'X' '' '' '' '' '' '',
*    '折扣百分比 2' 'ZBD2P' 'X' '' '' '' '' '' '',
      '分配金额' 'IN_WRBTR' 'X' '' '' '' '' '' '',
*      '分配状态' 'ZSTATUS' 'X' 'X' '' '' '' '' ''
*      'PID' 'ZID' 'X' '' '' '' '' '' ''.
     '原因代码' 'RSTGR' 'X' '' '' '' '' '' '',
     'OA流程编号' 'OA_NO' 'X' '' '' '' '' '' ''
        .


    CREATE OBJECT con2_ref
      EXPORTING
        container_name = 'CON2'.

    CREATE OBJECT g_grid2
      EXPORTING
        i_parent = con2_ref.

    CALL METHOD g_grid2->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layo2
      CHANGING
        it_outtab       = lt_bsid
        it_fieldcatalog = gt_fcat2.
  ENDIF.








ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  CANCEL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE cancel INPUT.
  BREAK cyit5.
  IF 1 = 1.

  ENDIF.

ENDMODULE.



PROCESS BEFORE OUTPUT.

 MODULE status_9001.
 MODULE init_con.

 PROCESS AFTER INPUT.

 MODULE cancel AT EXIT-COMMAND.
 MODULE user_command_9001.

1.2 屏幕绘制

1.3 实现效果

相关推荐
东莞梦幻网络科技软件开发公司1 小时前
开发体育赛事直播平台防止数据泄露的技术安全方案
经验分享·安全
售后宝3 小时前
服务机器人三甲坎德拉:用智能化开启售后服务新篇章
经验分享·制造
志-AOX3 小时前
Python编程艺术:优雅与实用的完美平衡(推导式)
经验分享
LZXCyrus4 小时前
【杂记】vLLM如何指定GPU单卡/多卡离线推理
人工智能·经验分享·python·深度学习·语言模型·llm·vllm
志-AOX4 小时前
AI安全:从现实关切到未来展望
经验分享
yigan_Eins8 小时前
【数论】莫比乌斯函数及其反演
c++·经验分享·算法
布说在见12 小时前
个人实施工作的一天 —— 繁琐的数据输入与未来的句里录数据
经验分享·实习实施
梅见十柒12 小时前
wsl2中kali linux下的docker使用教程(教程总结)
linux·经验分享·docker·云原生
管家婆客服中心13 小时前
提成制是什么?如何高效管理提成制?
经验分享·管家婆软件
zy张起灵19 小时前
48v72v-100v转12v 10A大功率转换电源方案CSM3100SK
经验分享·嵌入式硬件·硬件工程