• ABAP表抛FTP通用程序


    主要功能:

    1、支持R3所有表(标准、自建)下传,下传方式为FTP

    2、支持输出字段选择及顺序调整

    3、支持动态条件,不同的表会有不同的选择条件,根据不同的条件选择需要下传的数据

    4、支持单表、多表、以及输出数据再次加工(需自己写输出逻辑扩展程序,可参考YTEMPLET

    5、支持多表查询,及多表查询的动态选择条件

    6、支持大数据量表分批取数、以及分批下传(已通过BSEG大数据量表测试)

    7、支持单文件下传(只生产一个文件,默认是分批下传,会产生多个文件)

    8、其它支持参看选择屏幕

     
     

    程序创建好后,请将屏幕代码下载下来,再通过ABAP编辑器程序中的上传功能,即可创建屏幕,而不需要手动画:屏幕代码下载

    Code listing for: YR3TABLE2FTP

    Description: ABAP表抛FTP通用程序

    REPORT YR3TABLE2FTP.
    *&---------------------------------------------------------------------*
    *& INCLUDE
    *&---------------------------------------------------------------------*
    include YR3TABLE2FTP_TOP.
    include YR3TABLE2FTP_SELSCR.
    include YR3TABLE2FTP_FORM.

    *&---------------------------------------------------------------------*
    *& 初始化处理
    *&---------------------------------------------------------------------*
    INITIALIZATION.
      but1 = '输出字段配置'.
      but2 = 'HIVE-TABLE-SQL'.
      but3 = '输出逻辑扩展程序模板'.
      IF sy-sysid = 'DEV' OR sy-sysid = 'QAS' OR sy-sysid = 'PRE'.
        p_user = 'adssa'.
        p_pwd = 'fdsssdf'.
        p_host = '32.21.32.123'.
      ELSEIF sy-sysid = 'PRD'.
        p_user = 'fsfwewrew'.
        p_pwd  = 'fsfsfs'.
        p_host = '34.11.53.132'.
      ENDIF.

    *&---------------------------------------------------------------------*
    *& 选择屏幕控制
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN OUTPUT.
      IF p_prog IS NOT INITIAL.
        PERFORM frm_find_table USING 'X'.
        PERFORM frm_find_sel.
      ENDIF.

      CLEAR:p_snam1,p_snam2,p_snam3,p_snam4,p_snam5,
            s_asist1,s_asist2,s_asist3,s_asist4,s_asist5,
            s_asist1[],s_asist2[],s_asist3[],s_asist4[],s_asist5[].

      LOOP AT SCREEN.
        IF screen-name = 'P_PWD'.
          screen-invisible = '1'.
        ELSEIF screen-name = 'P_SNAM1' OR
               screen-name = 'P_SNAM2' OR
               screen-name = 'P_SNAM3' OR
               screen-name = 'P_SNAM4' OR
               screen-name = 'P_SNAM5' OR
               screen-name = 'S_ASIST1-LOW' OR screen-name = 'S_ASIST1-HIGH' OR
               screen-name = 'S_ASIST2-LOW' OR screen-name = 'S_ASIST2-HIGH' OR
               screen-name = 'S_ASIST3-LOW' OR screen-name = 'S_ASIST3-HIGH' OR
               screen-name = 'S_ASIST4-LOW' OR screen-name = 'S_ASIST4-HIGH' OR
               screen-name = 'S_ASIST5-LOW' OR screen-name = 'S_ASIST5-HIGH'.
          screen-input = 0.
          LOOP AT sel_flds.
            READ TABLE gt_vrm_values WITH KEY key = sel_flds-fld.
            CASE  sel_flds-p_snam.
              WHEN 's_asist1'.
                IF screen-name = 'S_ASIST1-LOW' OR screen-name = 'S_ASIST1-HIGH'.
                  screen-input = 1.
                  p_snam1 =  gt_vrm_values-text.
                ENDIF.
              WHEN 's_asist2'.
                IF screen-name = 'S_ASIST2-LOW' OR screen-name = 'S_ASIST2-HIGH'.
                  screen-input = 1.
                  p_snam2 =  gt_vrm_values-text.
                ENDIF.
              WHEN 's_asist3'.
                IF screen-name = 'S_ASIST3-LOW' OR screen-name = 'S_ASIST3-HIGH'.
                  screen-input = 1.
                  p_snam3 =  gt_vrm_values-text.
                ENDIF.
              WHEN 's_asist4'.
                IF screen-name = 'S_ASIST4-LOW' OR screen-name = 'S_ASIST4-HIGH'.
                  screen-input = 1.
                  p_snam4 =  gt_vrm_values-text.
                ENDIF.
              WHEN 's_asist5'.
                IF screen-name = 'S_ASIST5-LOW' OR screen-name = 'S_ASIST5-HIGH'.
                  screen-input = 1.
                  p_snam5 =  gt_vrm_values-text.
                ENDIF.
            ENDCASE.
          ENDLOOP.
        ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
      CLEAR:gt_vrm_values,gt_vrm_values[].
      gt_vrm_values-key = 'GBK'.
      gt_vrm_values-text = gt_vrm_values-key.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'UTF-8'.
      gt_vrm_values-text = gt_vrm_values-key.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'GB2312'.
      gt_vrm_values-text = gt_vrm_values-key.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'UTF-16BE'.
      gt_vrm_values-text = gt_vrm_values-key.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'UTF-16LE'.
      gt_vrm_values-text = gt_vrm_values-key.
      APPEND gt_vrm_values.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_encodi'
          values = gt_vrm_values[].


      CLEAR:gt_vrm_values,gt_vrm_values[].
      gt_vrm_values-key = '_NNNNNN'.
      gt_vrm_values-text = '_NNNNNN'.
      APPEND gt_vrm_values.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_fileno'
          values = gt_vrm_values[].

      CLEAR:gt_vrm_values,gt_vrm_values[].
      gt_vrm_values-key = 'YYYYMMDD'.
      gt_vrm_values-text = 'YYYYMMDD'.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'YYYYMM'.
      gt_vrm_values-text = 'YYYYMM'.
      APPEND gt_vrm_values.
      gt_vrm_values-key = 'YYYYMMDDHHMMSS'.
      gt_vrm_values-text = 'YYYYMMDDHHMMSS'.
      APPEND gt_vrm_values.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_ymd'
          values = gt_vrm_values[].


      CHECK p_table <> g_last_tbname.
      g_last_tbname = p_table.
      CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[],rtables,rtables[].
      PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING ''.


      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name1'
          values = gt_vrm_values_dt.
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name2'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name3'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name4'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name5'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name6'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name7'
          values = gt_vrm_values[].
      CALL FUNCTION 'VRM_SET_VALUES'
        EXPORTING
          id     = 'p_name8'
          values = gt_vrm_values[].

      IF flg2 = 'X'.
        CONCATENATE p_table `_` INTO p_fil_px.
        CLEAR: p_name1,p_name2,p_name3,p_name4,p_name5,p_name6,p_name7,p_name8,
               s_val1,s_val2,s_val3,s_val4,s_val5,s_val6,s_val7,s_val8,
               s_val1[],s_val2[],s_val3[],s_val4[],s_val5[],s_val6[],s_val7[],s_val8[].
        LOOP AT gt_dd03l WHERE keyflag = 'X' .
          CASE sy-tabix.
            WHEN 1.
              p_name2 = gt_dd03l-fieldname.
            WHEN 2.
              p_name3 = gt_dd03l-fieldname.
            WHEN 3.
              p_name4 = gt_dd03l-fieldname.
            WHEN 4.
              p_name5 = gt_dd03l-fieldname.
            WHEN 5.
              p_name6 = gt_dd03l-fieldname.
            WHEN 6.
              p_name7 = gt_dd03l-fieldname.
            WHEN 7.
              p_name8 = gt_dd03l-fieldname.
          ENDCASE.
        ENDLOOP.
      ENDIF.
      CLEAR:flg2.

    AT SELECTION-SCREEN ON p_table.
      flg2 = 'X'.
      SELECT SINGLE * FROM dd02l WHERE tabname = p_table AND ( tabclass = 'TRANSP' OR tabclass = 'CLUSTER' ) .
      IF sy-subrc <> 0.
        MESSAGE '表不存在' TYPE 'E'.
      ENDIF.

    AT SELECTION-SCREEN ON p_fil_px.


    AT SELECTION-SCREEN ON p_split.
      IF p_split = ''.
        MESSAGE '列分隔符不能为空' TYPE 'E'.
      ENDIF.

    AT SELECTION-SCREEN ON p_counts.
      IF p_counts <= 0.
        MESSAGE '每文件最大条目数需大于0' TYPE 'E'.
      ENDIF.

    AT SELECTION-SCREEN ON p_prog.
      IF  p_prog <> ''.
        SELECT SINGLE * FROM progdir WHERE name = p_prog.
        IF sy-subrc <> 0.
          MESSAGE '输出逻辑扩展程序不存在' TYPE 'E'.
        ENDIF.
      ENDIF.
    *&---------------------------------------------------------------------*
    *& 参数输入检查
    *&---------------------------------------------------------------------*
    AT SELECTION-SCREEN ON BLOCK b11.
      CLEAR: gt_name[].

      IF p_name1 IS NOT INITIAL AND s_val1[] IS NOT INITIAL.
        gt_name-name = p_name1.
        APPEND gt_name.
      ENDIF.

      IF p_name2 IS NOT INITIAL AND s_val2[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name2.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name2.
        APPEND gt_name.
      ENDIF.

      IF p_name3 IS NOT INITIAL AND s_val3[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name3.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name3.
        APPEND gt_name.
      ENDIF.

      IF p_name4 IS NOT INITIAL AND s_val4[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name4.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name4.
        APPEND gt_name.
      ENDIF.

      IF p_name5 IS NOT INITIAL AND s_val5[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name5.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name5.
        APPEND gt_name.
      ENDIF.

      IF p_name6 IS NOT INITIAL AND s_val6[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name6.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name6.
        APPEND gt_name.
      ENDIF.

      IF p_name7 IS NOT INITIAL AND s_val7[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name7.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name7.
        APPEND gt_name.
      ENDIF.

      IF p_name8 IS NOT INITIAL AND s_val8[] IS NOT INITIAL.
        READ TABLE gt_name WITH KEY name = p_name8.
        IF sy-subrc = 0.
          MESSAGE '条件字段重复,请检查输入条件' TYPE 'E'.
        ENDIF.
        gt_name-name = p_name8.
        APPEND gt_name.
      ENDIF.

    AT SELECTION-SCREEN.
      CASE sy-ucomm.
        WHEN 'CLI1'.
          CALL SCREEN 1001 STARTING AT 37 1
                          ENDING   AT 99 20.
        WHEN 'CLI2'.
          CALL SCREEN 1002 STARTING AT 37 1
                          ENDING   AT 97 20.
        WHEN 'CLI3'.
          CALL SCREEN 1003 STARTING AT 30 1
                          ENDING   AT 150 20.
      ENDCASE.
    *&---------------------------------------------------------------------*
    *& 程序开始处理
    *&---------------------------------------------------------------------*
    START-OF-SELECTION.
      CONDENSE p_fil_px.
      IF p_fil_px = ''.
        MESSAGE '文件名不能为空' TYPE 'S' DISPLAY LIKE 'E'.
        EXIT.
      ENDIF.

      PERFORM f_get_data. "取数逻辑

    *&---------------------------------------------------------------------*
    *& 程序结束处理
    *&---------------------------------------------------------------------*
    END-OF-SELECTION.
    *  PERFORM xxxxxxx.

    *GUI Texts
    *----------------------------------------------------------
    * 1001 --> 输出字段配置
    * 1002 --> HIVE-TABLE-SQL查看
    * 1003 --> 输出逻辑扩展程序样例

    *Text elements
    *----------------------------------------------------------
    * 001 源表配置
    * 002 目标FTP
    * 003 条件1
    * 004 条件2
    * 005 条件3
    * 006 条件4
    * 007 条件5
    * 008 主表名
    * 009 输完表名请回车
    * 010 条件6
    * 011 条件7
    * 012 条件8
    * 013 字段分隔符
    * 014 若为Tab请输入 ;换行符固定为 不可指定(首次转到FTP为 ,但HIVE接过去时为 )
    * 016 1、条件1为日期类型,可用于按日期增量,支持变式里的动态日期
    * 017 文件名
    * 018 最终文件存放路径:路径+文件夹日期,文件夹日期可以不输入
    * 021 主表选择条件
    * 022 输出字段
    * 023 输出字段选择
    * 028  NNNNNN为文件编号,留空时将只产生一个文件
    * 030 关联表选择条件
    * 031 2、除条件1外如果是日期类型,请按YYYMMDD格式输入,不带日期格式
    * 032 dddd
    * 033 .
    * 071 文件夹日期
    * 112 输出逻辑扩展程序
    * 114 
    * 118 当上面文件名中有YYYYMMDD(或YYYYMM),且文件日期留空时,取当前日期
    * 121 是否生成标记文件
    * 122 是否生成时间戳字段(ZTIMESTAMPL)
    * 123 是否带表头
    * 124 文件名是否带编号
    * 125 如去掉,则主表会一次查出所有数据后下传,文件名不会带 _NNNNNN 编号
    * 126 默认不带。表头每列信息由字段名+字段描述+长度(字段名:字段描述(长度))组成
    * 127 SQL性能日志
    * 128 生成的表头里是否带 表字段名+字段长度 信息
    * 129 抽取时间戳(YYYYMMDDhhmmss.mmmuuun)
    * 132 文件字符编码
    * 133 标记文件扩展名
    * 140 
    * 213 表头是否带技术信息
    * 231 _YYYYMMDD
    * 771 文件日期
    * 900 输完程序名请回车


    *Selection texts
    *----------------------------------------------------------
    * FTP_PATH         路径
    * PFLGFILE         标记文件
    * P_COUNTS         主表分批查询记录数
    * P_DIR_DT         文件夹日期
    * P_ENCODI         文件字符编码
    * P_EXTENS         数据文件扩展名
    * P_FIL_PX         数据文件名
    * P_FLG_FL         标记文件名
    * P_HEADER         是否带表头
    * P_HOST         主机IP
    * P_NAME1         条件1字段名
    * P_NAME2         条件2字段名
    * P_NAME3         条件3字段名
    * P_NAME4         条件4字段名
    * P_NAME5         条件5字段名
    * P_NAME6         条件6字段名
    * P_NAME7         条件7字段名
    * P_NAME8         条件8字段名
    * P_PROG         输出扩展逻辑程序名
    * P_PWD         密码
    * P_SNAM1         关联表选择条件名1
    * P_SNAM2         关联表选择条件名2
    * P_SNAM3         关联表选择条件名3
    * P_SNAM4         关联表选择条件名4
    * P_SNAM5         关联表选择条件名5
    * P_SPLIT         列分隔符
    * P_TABLE         主表名
    * P_USER         用户名
    * P_VARUSR         变式创建者
    * S_ASIST1         关联表选择条件值1
    * S_ASIST2         关联表选择条件值2
    * S_ASIST3         关联表选择条件值3
    * S_ASIST4         关联表选择条件值4
    * S_ASIST5         关联表选择条件值5
    * S_VAL1         条件1值
    * S_VAL2         条件2值
    * S_VAL3         条件3值
    * S_VAL4         条件4值
    * S_VAL5         条件5值
    * S_VAL6         条件6值
    * S_VAL7         条件7值
    * S_VAL8         条件8值


    *Messages
    *----------------------------------------------------------
    *
    * Message class: Hard coded
    *   请输入内容

    Code listing for: YR3TABLE2FTP_FORM

    Description: Include YR3TABLE2FTP_FORM

    *&---------------------------------------------------------------------*
    *&  包括              YR3TABLE2FTP_FORM
    *&---------------------------------------------------------------------*


    *&---------------------------------------------------------------------*
    *&      Form  f_get_data
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM f_get_data .
      FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                     <dyn_table_new> TYPE STANDARD TABLE,
                     <dyn_wa>.
      DATA: dy_table TYPE REF TO data,
            dy_line TYPE REF TO data.
      DATA: str TYPE string.
      DATA: lv_selflds TYPE string.

      IF p_ymd = 'YYYYMMDD'.
        IF p_ymd2 IS NOT INITIAL.
          CONCATENATE p_fil_px p_ymd2 INTO p_fil_px2.
        ELSE.
          CONCATENATE p_fil_px sy-datum INTO p_fil_px2.
        ENDIF.
      ELSEIF p_ymd = 'YYYYMM'.
        IF p_ymd2 IS NOT INITIAL.
          CONCATENATE p_fil_px p_ymd2+0(6) INTO p_fil_px2.
        ELSE.
          CONCATENATE p_fil_px sy-datum+0(6) INTO p_fil_px2.
        ENDIF.
      ELSEIF p_ymd = 'YYYYMMDDHHMMSS'.
        IF p_ymd2 IS NOT INITIAL.
          CONCATENATE p_fil_px p_ymd2 sy-uzeit INTO p_fil_px2.
        ELSE.
          CONCATENATE p_fil_px sy-datum sy-uzeit INTO p_fil_px2.
        ENDIF.
      ELSE.
        p_fil_px2 = p_fil_px.
      ENDIF.

      CLEAR: gt_YTEST300,gt_YTEST300[].
      SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
      struct_type ?= cl_abap_typedescr=>describe_by_name( p_table ).
      comp_tab[] = struct_type->get_components( ).
      PERFORM frm_comp_tab TABLES comp_tab.

      IF gt_YTEST300[] IS NOT INITIAL.
        CLEAR:comp_tab2[].
        LOOP AT gt_YTEST300.
          READ TABLE comp_tab WITH KEY name = gt_YTEST300-fldname.
          MOVE-CORRESPONDING comp_tab TO comp_tab2.
          APPEND comp_tab2.
          CONCATENATE lv_selflds ` ` gt_YTEST300-fldname INTO lv_selflds.
        ENDLOOP.
        comp_tab[] = comp_tab2[].


        IF timestmp = 'X'.
          comp_tab-name = 'ZTIMESTAMPL'.
          comp_tab-type = cl_abap_elemdescr=>get_c( 22 ).
          APPEND comp_tab.
        ENDIF.

        struct_type = cl_abap_structdescr=>create( comp_tab[] ).
      ELSE.
        LOOP AT comp_tab.
          CONCATENATE lv_selflds ` ` comp_tab-name INTO lv_selflds.
        ENDLOOP.

        IF timestmp = 'X'.
          comp_tab-name = 'ZTIMESTAMPL'.
          comp_tab-type = cl_abap_elemdescr=>get_c( 22 ).
          APPEND comp_tab.
          struct_type = cl_abap_structdescr=>create( comp_tab[] ).
        ENDIF.

      ENDIF.

      table_type = cl_abap_tabledescr=>create( struct_type ).

      CREATE DATA dy_table TYPE HANDLE table_type.
      ASSIGN dy_table->* TO <dyn_table>.
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.

      DATA: cond TYPE string,orderby TYPE string.

      CLEAR:cond .
      IF p_name1 IS NOT INITIAL AND s_val1[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name1 ` in s_val1 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name1 ` in s_val1` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name2 IS NOT INITIAL AND s_val2[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name2 ` in s_val2 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name2 ` in s_val2` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name3 IS NOT INITIAL AND s_val3[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name3 ` in s_val3 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name3 ` in s_val3` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name4 IS NOT INITIAL AND s_val4[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name4 ` in s_val4 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name4 ` in s_val4` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name5 IS NOT INITIAL AND s_val5[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name5 ` in s_val5 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name5 ` in s_val5` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name6 IS NOT INITIAL AND s_val6[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name6 ` in s_val6 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name6 ` in s_val6` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name7 IS NOT INITIAL AND s_val7[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name7 ` in s_val7 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name7 ` in s_val7` INTO cond.
        ENDIF.
      ENDIF.

      IF p_name8 IS NOT INITIAL AND s_val8[] IS NOT INITIAL.
        IF cond = ''.
          CONCATENATE  p_name8 ` in s_val8 ` INTO cond.
        ELSE.
          CONCATENATE cond ` and ` p_name8 ` in s_val8` INTO cond.
        ENDIF.
      ENDIF.

      DATA: str_len TYPE i.
      str_len = STRLEN( ftp_path ).
      str_len = str_len - 1.
      REPLACE ALL OCCURRENCES OF `\` IN ftp_path  WITH `/`.
      CONDENSE ftp_path.
      IF ftp_path+str_len = '/' AND p_dir_dt IS NOT INITIAL.
        CONCATENATE ftp_path p_dir_dt INTO ftp_path.
      ELSEIF p_dir_dt IS NOT INITIAL.
        CONCATENATE ftp_path '/' p_dir_dt INTO ftp_path.
      ENDIF.

      IF ftp_path+str_len = '/' AND str_len <> 0.
        ftp_path = ftp_path+0(str_len).
      ENDIF.
      FIELD-SYMBOLS: <fldvalue>,<key_constr>.
      DATA: key_constr TYPE TABLE OF string WITH HEADER LINE,l_total TYPE string,lins TYPE i,lins2 TYPE i,strtmp TYPE string.
      DATA:lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE,wa_dd03l LIKE lt_dd03l.
      SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
              WHERE tabname = p_table AND keyflag = 'X' .
      SORT lt_dd03l BY position.

      LOOP AT lt_dd03l.
        CONCATENATE ` ` orderby ` ` lt_dd03l-fieldname INTO orderby.
      ENDLOOP.
      CONDENSE orderby.

      DELETE lt_dd03l WHERE fieldname = 'MANDT'.
      READ TABLE lt_dd03l INTO wa_dd03l INDEX 1."第一主键字段

      DATA: counts TYPE i,diff_counts TYPE i.
      DO.
        g_count = sy-index.
        CONCATENATE `_` g_count INTO g_count_c.

        CLEAR:key_constr,key_constr[].
        IF sy-index = 1."首次查
          IF cond IS INITIAL.
            IF wa_dd03l-inttype = 'C'.
              CONCATENATE wa_dd03l-fieldname ` >= ''` INTO key_constr.
            ELSE.
              CONCATENATE `( ` wa_dd03l-fieldname ` >= -128 )`INTO key_constr.
            ENDIF.
          ELSE.
            IF wa_dd03l-inttype = 'C'.
              CONCATENATE `( ` wa_dd03l-fieldname ` >= '' ) AND ( ` cond ` )` INTO key_constr.
            ELSE.
              CONCATENATE `( ` wa_dd03l-fieldname ` >= -128 ) AND ( ` cond ` )` INTO key_constr.
            ENDIF.
          ENDIF.

          APPEND key_constr.
          CLEAR key_constr.
        ELSE.
          IF <dyn_table> IS NOT INITIAL ."最近一次查到数据后
            DESCRIBE TABLE lt_dd03l LINES lins.
            IF lins > 1."如果主键字段个数大于1
              PERFORM frm_key_constr TABLES <dyn_table> lt_dd03l key_constr.
              LOOP AT key_constr ASSIGNING <key_constr>.
                IF cond IS NOT INITIAL.
                  CONCATENATE `( ` <key_constr> ` ) AND ( ` cond ` )` INTO <key_constr>.
                ENDIF.
              ENDLOOP.
            ENDIF.

            CLEAR <dyn_wa>.
            DESCRIBE TABLE <dyn_table> LINES lins.
            READ TABLE <dyn_table> INTO <dyn_wa> INDEX lins.
            ASSIGN COMPONENT wa_dd03l-fieldname OF STRUCTURE <dyn_wa> TO <fldvalue>.

            "非首次查询时,无论怎样第一主键字段大于条件需要
            IF cond IS INITIAL.
              CONCATENATE wa_dd03l-fieldname ` > '` <fldvalue> `'` INTO key_constr.
            ELSE.
              CONCATENATE wa_dd03l-fieldname ` > '` <fldvalue> `' AND ( ` cond ` )` INTO key_constr.
            ENDIF.
            APPEND key_constr.
          ENDIF.
        ENDIF.

        CONCATENATE  `正在读取第 ` g_count ` 批数据...` INTO str.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
            percentage = 20
            text       = str.

        FREE <dyn_table>.
        LOOP AT key_constr.
          DESCRIBE TABLE <dyn_table> LINES lins.
          diff_counts = p_counts - lins.
          IF diff_counts <= 0 .
            EXIT.
          ENDIF.
          strtmp = key_constr.
          GET RUN TIME FIELD tm1.
          SELECT (lv_selflds) APPENDING CORRESPONDING FIELDS OF TABLE <dyn_table> FROM (p_table) UP TO diff_counts ROWS WHERE (strtmp) ORDER BY (orderby).
          DESCRIBE TABLE <dyn_table> LINES lins2.
          diff_counts = lins2 - lins.
          IF psqllog = 'X'.
            PERFORM frm_write_file2 USING strtmp diff_counts sy-tabix.
          ENDIF.
        ENDLOOP.
        IF psqllog = 'X'.
          PERFORM frm_write_file3 .
        ENDIF.

        "首次查询为空时,需要下传空文件
        IF sy-index > 1 AND <dyn_table> IS INITIAL.
          EXIT.
        ENDIF.

        DATA:dy_table_new TYPE REF TO data.
        IF p_prog IS NOT INITIAL.
    ************************************
          CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
            EXPORTING
              percentage = 20
              text       = `输出字段逻辑扩展处理...`.

          PERFORM frm_dyn IN PROGRAM (p_prog) TABLES <dyn_table> comp_tab[]
                                    s_asist1 s_asist2 s_asist3 s_asist4 s_asist5
                                    USING dy_table_new .
          ASSIGN dy_table_new->* TO <dyn_table_new>.
          IF p_fileno IS NOT INITIAL."分文件抛FTP
            PERFORM to_ftptab TABLES <dyn_table_new>.
          ELSE."不分文件
            IF g_count = 1.
              PERFORM to_ftptab TABLES <dyn_table_new>.
            ELSE.
              PERFORM frm_write_file TABLES <dyn_table_new>.
            ENDIF.
          ENDIF.
          DESCRIBE TABLE <dyn_table_new> LINES lins.
    ************************************
        ELSE.
          IF p_fileno IS NOT INITIAL.
            PERFORM to_ftptab TABLES <dyn_table>.
          ELSE.
            IF g_count = 1.
              PERFORM to_ftptab TABLES <dyn_table>.
            ELSE.
              PERFORM frm_write_file TABLES <dyn_table>.
            ENDIF.
          ENDIF.
          DESCRIBE TABLE <dyn_table> LINES lins.
        ENDIF.
        l_total = l_total + lins.
        IF flg_ftp IS NOT INITIAL.
          EXIT.
        ENDIF.
      ENDDO.

      IF p_fileno IS INITIAL.
        CONCATENATE  `正在将SAP服务上文件Append到FTP:` gv_filename INTO str.
        CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
          EXPORTING
            percentage = 20
            text       = str.
        PERFORM frm_ftp_append.
        CONCATENATE  `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
        DELETE DATASET gv_filename.
      ENDIF.

      CHECK flg_ftp IS INITIAL AND pflgfile = 'X'.

      DATA: codepage TYPE cpcodepage,
         encoding TYPE abap_encoding,
        convout TYPE REF TO cl_abap_conv_out_ce,
        buffer TYPE xstring.
      DATA: BEGIN OF dest_xtab OCCURS 0,
            x(6144) TYPE x,
          END OF dest_xtab.

      CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
        EXPORTING
          external_name = p_encodi
        IMPORTING
          sap_codepage  = codepage.
      encoding = codepage.

      CALL METHOD cl_abap_conv_out_ce=>create
        EXPORTING
          encoding = encoding
        RECEIVING
          conv     = convout.
    *  CONCATENATE `数据总条数:` l_total INTO l_total.
      CONDENSE l_total.
      CALL METHOD convout->write
        EXPORTING
          data = l_total.

      CALL METHOD convout->get_buffer
        RECEIVING
          buffer = buffer.

      DATA: lv_binary_len TYPE i.
      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = buffer
        IMPORTING
          output_length = lv_binary_len
        TABLES
          binary_tab    = dest_xtab.

      PERFORM f_ftp_connect.
      PERFORM frm_cd_dir.

      CONCATENATE p_fil_px2 `.` p_flgex INTO gv_filename.

      CONDENSE gv_filename.
      CALL FUNCTION 'FTP_R3_TO_SERVER'
        EXPORTING
          handle        = thandle
          fname         = gv_filename
          blob_length   = lv_binary_len
        TABLES
          blob          = dest_xtab
        EXCEPTIONS
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          OTHERS        = 4.
      IF sy-subrc EQ 0.
        WRITE:/ gv_filename,'传输成功!'.
      ELSE.
        WRITE:/ gv_filename,'数据文件传输失败!'.
      ENDIF.
      PERFORM f_ftp_disconnect.
    ENDFORM. " f_get_data

    *&---------------------------------------------------------------------*
    *&      Form  to_ftptab
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_SRC_TAB    text
    *      -->P_DEST_XTAB  text
    *      -->OF           text
    *      -->X            text
    *----------------------------------------------------------------------*
    FORM to_ftptab TABLES p_src_tab.
      DATA: BEGIN OF dest_xtab OCCURS 0,
            x(6144) TYPE x,
          END OF dest_xtab.
      DATA: lv_binary_len TYPE i.

      DATA:str TYPE string.
      IF p_fileno IS NOT INITIAL.
        CONCATENATE  p_fil_px2 g_count_c `.` p_extens INTO gv_filename SEPARATED BY ``.
      ELSE.
        CONCATENATE  p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
      ENDIF.
      CONCATENATE  `正在准备文件:` gv_filename INTO str.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 20
          text       = str.

      PERFORM frm_data_to_binary TABLES p_src_tab dest_xtab USING lv_binary_len 'X'.

      CONCATENATE  `正在上传文件:` gv_filename INTO str.
      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 20
          text       = str.
      PERFORM f_ftp_connect.
      PERFORM frm_mkdir.
      PERFORM frm_cd_dir.

      PERFORM f_ftp TABLES dest_xtab USING lv_binary_len.
      PERFORM f_ftp_disconnect.
      CLEAR:dest_xtab.
      REFRESH:dest_xtab[].
    ENDFORM. "to_ftptab

    *&---------------------------------------------------------------------*
    *&      Form  to_ftptab2
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_SRC_TAB  text
    *----------------------------------------------------------------------*
    FORM frm_data_to_binary TABLES p_src_tab dest_xtab USING lv_binary_len TYPE i first.
      DATA:strct_type_ref TYPE REF TO cl_abap_structdescr,
           tab_type_ref TYPE REF TO cl_abap_tabledescr,
           t_component TYPE cl_abap_structdescr=>component_table,
           wa_component LIKE LINE OF t_component.
      FIELD-SYMBOLS: <fldvalue>.
      DATA:time_stamp TYPE timestampl,timestamp_c(22).

      DATA: l_str TYPE string,fldstr TYPE string,fldtype,firsttime VALUE 'X'.
      DATA: str TYPE string.
      DATA: len TYPE string.
      DATA: codepage TYPE cpcodepage,
         encoding TYPE abap_encoding,
        convout TYPE REF TO cl_abap_conv_out_ce,
        buffer TYPE xstring.

      CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
        EXPORTING
          external_name = p_encodi
        IMPORTING
          sap_codepage  = codepage.
      encoding = codepage.

      CALL METHOD cl_abap_conv_out_ce=>create
        EXPORTING
          encoding = encoding
        RECEIVING
          conv     = convout.

      tab_type_ref ?= cl_abap_tabledescr=>describe_by_data( p_src_tab[] ).
      strct_type_ref ?= tab_type_ref->get_table_line_type( ).
      t_component = strct_type_ref->get_components( ).

      str = p_split.
      REPLACE ALL OCCURRENCES OF ` ` IN str  WITH c_tab.
      REPLACE ALL OCCURRENCES OF `T` IN str  WITH c_tab.
      REPLACE ALL OCCURRENCES OF ` ` IN str  WITH ``.

      IF p_header = 'X' AND first IS NOT INITIAL.
        PERFORM frm_find_table USING 'X'.

        CLEAR:fldstr,l_str.
        LOOP AT t_component INTO wa_component.
          READ TABLE gt_dd03l WITH KEY fieldname = wa_component-name.
          IF sy-subrc = 0.
            len = gt_dd03l-leng + gt_dd03l-decimals.
            CONDENSE len.
            READ TABLE gt_vrm_values WITH KEY key = wa_component-name.
            IF sy-subrc = 0.
              REPLACE ALL OCCURRENCES OF str IN gt_vrm_values-text  WITH ` `.
              IF fldstr = ''.
                IF p_hdtlg IS NOT INITIAL.
                  CONCATENATE gt_vrm_values-text `(` len `)` INTO fldstr.
                ELSE.
                  CLEAR: itab,itab[].
                  SPLIT gt_vrm_values-text AT `:` INTO TABLE itab.
                  READ TABLE itab INDEX 2.
                  fldstr = itab .
                ENDIF.
              ELSE.
                IF p_hdtlg IS NOT INITIAL.
                  CONCATENATE fldstr str gt_vrm_values-text `(` len `)` INTO fldstr.
                ELSE.
                  CLEAR: itab,itab[].
                  SPLIT gt_vrm_values-text AT `:` INTO TABLE itab.
                  READ TABLE itab INDEX 2.
                  CONCATENATE fldstr str itab INTO fldstr.
                ENDIF.
              ENDIF.
            ELSE.
              IF fldstr = ''.
                IF p_hdtlg IS NOT INITIAL.
                  CONCATENATE gt_dd03l-fieldname `(` len `)` INTO fldstr.
                ELSE.
                  fldstr = gt_dd03l-fieldname.
                ENDIF.
              ELSE.
                IF p_hdtlg IS NOT INITIAL.
                  CONCATENATE fldstr str gt_dd03l-fieldname `(` len `)` INTO fldstr.
                ELSE.
                  CONCATENATE fldstr str gt_dd03l-fieldname INTO fldstr.
                ENDIF.
              ENDIF.
            ENDIF.
          ELSE.
            elem_type ?= wa_component-type.
            len = elem_type->length + elem_type->decimals.
            CONDENSE len.
            IF fldstr = ''.
              IF p_hdtlg IS NOT INITIAL.
                CONCATENATE wa_component-name `(` len `)` INTO fldstr.
              ELSE.
                fldstr = wa_component-name.
              ENDIF.
            ELSE.
              IF p_hdtlg IS NOT INITIAL.
                CONCATENATE fldstr str wa_component-name `(` len `)` INTO fldstr.
              ELSE.
                CONCATENATE fldstr str wa_component-name INTO fldstr.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDLOOP.
        CALL METHOD convout->write
          EXPORTING
            data = fldstr.
        CALL METHOD convout->write
          EXPORTING
            data = cl_abap_char_utilities=>cr_lf.
      ENDIF.


      GET TIME STAMP FIELD time_stamp.
      timestamp_c = time_stamp.


      LOOP AT p_src_tab.
        firsttime = 'X'.
        CLEAR:fldstr,l_str.
        LOOP AT t_component INTO wa_component.

          IF wa_component-name = 'ZTIMESTAMPL'.
            IF firsttime = 'X'.
              fldstr = time_stamp.
              CLEAR firsttime.
            ELSE.
              CONCATENATE fldstr timestamp_c INTO fldstr SEPARATED BY str.
            ENDIF.
            CONTINUE.
          ENDIF.

          fldtype = wa_component-type->type_kind.
          ASSIGN COMPONENT wa_component-name OF STRUCTURE p_src_tab TO <fldvalue>.
          l_str = <fldvalue>.
          IF fldtype = 'P' OR fldtype = 'F'
            OR fldtype = 'I' OR fldtype = 'b'
            OR fldtype = 's'.
            CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
              CHANGING
                value = l_str.
          ENDIF.
          REPLACE ALL OCCURRENCES OF str IN l_str  WITH ` `.
          IF firsttime = 'X'.
            fldstr = l_str .
            CLEAR firsttime.
          ELSE.
            CONCATENATE fldstr l_str INTO fldstr SEPARATED BY str.
          ENDIF.
        ENDLOOP.

        CONDENSE fldstr.
        CALL METHOD convout->write
          EXPORTING
            data = fldstr.
        CALL METHOD convout->write
          EXPORTING
            data = cl_abap_char_utilities=>cr_lf.
      ENDLOOP.

      CALL METHOD convout->get_buffer
        RECEIVING
          buffer = buffer.

      CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
        EXPORTING
          buffer        = buffer
        IMPORTING
          output_length = lv_binary_len
        TABLES
          binary_tab    = dest_xtab.
    ENDFORM. "frm_data_to_binary

    *&---------------------------------------------------------------------*
    *&      Form  f_ftp_connect
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM f_ftp_connect .
      DATA: thosts(45),tusers(45),tpword(45).
      thosts = p_host.
      tusers = p_user.
      tpword = p_pwd.
      slen = STRLEN( tpword ).

    ***对密码值进行加密解析处理
      CALL FUNCTION 'HTTP_SCRAMBLE'
        EXPORTING
          SOURCE      = tpword
          sourcelen   = slen
          key         = key
        IMPORTING
          destination = tpword.
    ***定义RFC连接目标,前后台执行时不同
    *  IF sy-batch = 'X'.
      trfcdest = 'SAPFTPA'.
    *  ELSE.
    *    trfcdest = 'SAPFTP'.
    *  ENDIF.
    ***该函数可以定义有网关是账户密码,一般公司内部访问无此设置
      CALL FUNCTION 'FTP_CONNECT'
        EXPORTING
          user            = tusers
          password        = tpword
          host            = thosts
          rfc_destination = trfcdest
        IMPORTING
          handle          = thandle
        EXCEPTIONS
          not_connected   = 1
          OTHERS          = 2.

      IF sy-subrc NE 0.
        WRITE:/ 'FTP连接失败!'.
        STOP.
      ENDIF.

    ENDFORM. " f_ftp_connect
    *&---------------------------------------------------------------------*
    *&      Form  frm_mkdir
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_mkdir .
      DATA: dirstr TYPE string.
      CLEAR:com,com[],res,res[].
      CLEAR: itab, itab[].
      SPLIT ftp_path AT `/` INTO TABLE itab .
      DELETE itab WHERE table_line = ''.
      LOOP AT itab .
        IF sy-tabix = 1.
          CONCATENATE `/` itab INTO dirstr SEPARATED BY ``.
        ELSE.
          CONCATENATE dirstr `/` itab INTO dirstr SEPARATED BY ``.
        ENDIF.
        CONCATENATE `mkdir ` dirstr INTO com-cmd SEPARATED BY ``.
        APPEND com.
      ENDLOOP.

      LOOP AT com.
        CALL FUNCTION 'FTP_COMMAND'
          EXPORTING
            handle        = thandle
            command       = com-cmd
          TABLES
            data          = res
          EXCEPTIONS
            tcpip_error   = 1
            command_error = 2
            data_error    = 3
            OTHERS        = 4.
      ENDLOOP.
    ENDFORM. " frm_mkdir
    *&---------------------------------------------------------------------*
    *&      Form  frm_cd_dir
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_cd_dir .
      CLEAR:com,com[],res,res[].
      CONCATENATE 'cd' ftp_path INTO com-cmd SEPARATED BY ''.

      CALL FUNCTION 'FTP_COMMAND'
        EXPORTING
          handle        = thandle
          command       = com-cmd
        TABLES
          data          = res
        EXCEPTIONS
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          OTHERS        = 4.

    ENDFORM. " frm_cd_dir
    *&---------------------------------------------------------------------*
    *&      Form  f_ftp_disconnect
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM f_ftp_disconnect .
      CALL FUNCTION 'FTP_DISCONNECT'
        EXPORTING
          handle = thandle.
    ENDFORM. " f_ftp_disconnect
    *&---------------------------------------------------------------------*
    *&      Form  f_ftp
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM f_ftp TABLES p_ftptab USING lv_binary_len.
      CONDENSE gv_filename.
    *  DATA:str TYPE string.
    *  CONCATENATE  `正在上传文件:` gv_filename INTO str.
    *  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    *    EXPORTING
    *      percentage = 20
    *      text       = str.

      CALL FUNCTION 'FTP_R3_TO_SERVER'
        EXPORTING
          handle        = thandle
          fname         = gv_filename
          blob_length   = lv_binary_len
        TABLES
          blob          = p_ftptab
        EXCEPTIONS
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          OTHERS        = 4.
      IF sy-subrc EQ 0.
        WRITE:/ gv_filename,'传输成功!'.
      ELSE.
        WRITE:/ gv_filename,'数据文件传输失败!'.
        flg_ftp = 'X'.
      ENDIF.
    ENDFORM. " f_ftp
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_1001  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_1001 OUTPUT.
      SET PF-STATUS 'ST_1001'.
      SET TITLEBAR '1001'.
      CLEAR: texttable[],line,gt_YTEST300,gt_YTEST300[].
      CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[],rtables,rtables[].
      PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING 'X'.

      SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
      IF sy-subrc = 0.
        LOOP AT gt_YTEST300.
          READ TABLE gt_vrm_values WITH KEY key = gt_YTEST300-fldname.
          CLEAR:itab[].
          SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
          CONCATENATE line c_crlf gt_YTEST300-fldname `:` c1 INTO line SEPARATED BY ``.
        ENDLOOP.
      ELSE.
        LOOP AT gt_vrm_values.
          CLEAR:itab[].
          SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
          CONCATENATE line c_crlf gt_vrm_values-key `:` c1 INTO line SEPARATED BY ``.
        ENDLOOP.
      ENDIF.
      line = line+2.
      APPEND line TO texttable.

      IF editor_container IS NOT BOUND.
        CREATE OBJECT editor_container
              EXPORTING
                container_name =  'EDITOR'.

        CREATE OBJECT editor
            EXPORTING
              parent = editor_container
              wordwrap_mode = 1
              max_number_chars = 10000.
      ENDIF.
      editor->set_textstream( line ).
    ENDMODULE. " STATUS_1001 OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_1001  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_1001 INPUT.
      CASE sy-ucomm.
        WHEN 'RW'.
          LEAVE TO SCREEN 0.
        WHEN 'SAVE'.
          CALL METHOD editor->get_text_as_stream
            IMPORTING
              text = texttable[].
          CLEAR: line.
          LOOP AT texttable.
            CONCATENATE line texttable-line INTO line SEPARATED BY ``.
          ENDLOOP.
          IF sy-subrc <> 0.
            MESSAGE `请输入内容` TYPE 'E'.
          ELSE.
            CLEAR:itab[].
            SPLIT line AT c_crlf INTO TABLE itab .
            IF itab[] IS INITIAL.
              MESSAGE `请输入内容` TYPE 'E'.
            ELSE.
              CLEAR:itab2[].
              LOOP AT itab .
                SPLIT itab AT `:` INTO itab c1.
                CONDENSE itab.
                TRANSLATE itab TO UPPER CASE.
                APPEND itab TO itab2.
              ENDLOOP.

              LOOP AT itab .
                g_tabix = sy-tabix.
                SPLIT itab AT `:` INTO itab c1.
                CONDENSE itab.
                TRANSLATE itab TO UPPER CASE.
                IF itab <> ''.
                  CLEAR repeat.
                  LOOP AT itab2 WHERE table_line =  itab.
                    repeat = repeat + 1.
                  ENDLOOP.
                  IF repeat > 1.
                    CONCATENATE itab ` 重复输入` INTO c1.
                    MESSAGE c1 TYPE 'E'.
                    EXIT.
                  ENDIF.
                  MODIFY itab INDEX g_tabix.
                ELSE.
                  DELETE itab INDEX g_tabix.
                ENDIF.
              ENDLOOP.
              IF itab[] IS INITIAL.
                MESSAGE `请输入内容` TYPE 'E'.
              ELSE.
                CLEAR:gt_YTEST300[],gt_YTEST300.

                LOOP AT itab.
                  gt_YTEST300-sequence = sy-tabix.
                  READ TABLE gt_vrm_values WITH KEY key = itab.
                  IF sy-subrc <> 0.
                    CONCATENATE itab ` 字段不存在` INTO c1.
                    CLEAR:gt_YTEST300[],gt_YTEST300.
                    MESSAGE c1 TYPE 'E'.
                  ENDIF.
                  gt_YTEST300-username = p_varusr.
                  gt_YTEST300-tabname = p_table.
                  gt_YTEST300-fldname = itab.
                  APPEND gt_YTEST300.
                ENDLOOP.

                DATA:lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE,msg TYPE string.
                CLEAR:msg,lt_dd03l,lt_dd03l[].
                SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
                        WHERE tabname = p_table AND keyflag = 'X'.

                LOOP AT lt_dd03l.
                  READ TABLE gt_YTEST300 WITH KEY fldname = lt_dd03l-fieldname.
                  IF sy-subrc <> 0.
                    CONCATENATE lt_dd03l-fieldname `为主键,不能删除` INTO msg.
                    MESSAGE msg TYPE 'E'.
                  ENDIF.
                ENDLOOP.

                DELETE FROM YTEST300 WHERE username = p_varusr AND tabname = p_table.
                MODIFY YTEST300 FROM TABLE gt_YTEST300.
                COMMIT WORK.
                MESSAGE '保存成功' TYPE 'I'.
              ENDIF.
            ENDIF.
          ENDIF.
        WHEN 'RE_LOAD'.
          DATA: l_answer.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
              text_question         = '重置会将当前配置从YTEST300中删除,是否继续?'
              icon_button_1         = '是'
              icon_button_2         = '否'
              default_button        = '2'
              display_cancel_button = ''
            IMPORTING
              answer                = l_answer
            EXCEPTIONS
              text_not_found        = 1
              OTHERS                = 2.
          IF l_answer = '1'.
            DELETE FROM YTEST300 WHERE username = p_varusr AND tabname = p_table.
          ENDIF.

      ENDCASE.
    ENDMODULE. " USER_COMMAND_1001 INPUT

    *&---------------------------------------------------------------------*
    *&      Form  frm_val
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM frm_val TABLES lt_vrm_values TYPE vrm_values rtables STRUCTURE range_c35 lt_vrm_values_dt TYPE vrm_values lt_dd03l STRUCTURE dd03l USING mandt.
      DATA:lt_dd03t TYPE TABLE OF dd03t WITH HEADER LINE,
           lt_dd04t TYPE TABLE OF dd04t WITH HEADER LINE.
      DATA:ls_vrm_values  LIKE LINE OF lt_vrm_values.
      DATA:BEGIN OF  fieldname OCCURS 0,
        fieldname TYPE dd03t-fieldname ,
        END OF fieldname.
      DATA:BEGIN OF rollname OCCURS 0,
        rollname TYPE dd04t-rollname ,
        END OF rollname.

      IF rtables[] IS INITIAL.
        rtables-sign = 'I'.
        rtables-option = 'EQ'.
        rtables-low = p_table.
        APPEND rtables.
      ENDIF.

      IF mandt IS NOT INITIAL.
        SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
                WHERE tabname IN rtables AND fieldname <> '.INCLU--AP' AND fieldname <> '.INCLUDE'.
      ELSE.
        SELECT tabname fieldname keyflag rollname position inttype leng decimals FROM dd03l INTO CORRESPONDING FIELDS OF TABLE lt_dd03l
                WHERE tabname IN rtables AND fieldname <> 'MANDT' AND fieldname <> '.INCLU--AP' AND fieldname <> '.INCLUDE'.
      ENDIF.

      SORT lt_dd03l BY position.
      LOOP AT lt_dd03l .
        IF lt_dd03l-rollname = ''.
          APPEND lt_dd03l-fieldname TO fieldname.
        ELSE.
          APPEND lt_dd03l-rollname TO rollname.
        ENDIF.
      ENDLOOP.

      IF fieldname[] IS NOT INITIAL.
        SELECT fieldname ddtext INTO CORRESPONDING FIELDS OF TABLE lt_dd03t
                   FROM dd03t
                   FOR ALL ENTRIES IN fieldname
                   WHERE tabname = p_table
                     AND ddlanguage = '1'
                     AND fieldname = fieldname-fieldname.
      ENDIF.

      IF rollname[] IS NOT INITIAL.
        SELECT rollname ddtext INTO CORRESPONDING FIELDS OF TABLE lt_dd04t
                   FROM dd04t
                   FOR ALL ENTRIES IN rollname
                   WHERE ddlanguage = '1'
                     AND rollname = rollname-rollname.
      ENDIF.


      REFRESH lt_vrm_values.
      LOOP AT lt_dd03l.
        ls_vrm_values-key = lt_dd03l-fieldname.
        IF lt_dd03l-rollname = ''.
          READ TABLE lt_dd03t WITH KEY fieldname = lt_dd03l-fieldname.
          IF sy-subrc = 0.
            CONCATENATE lt_dd03l-fieldname `:` lt_dd03t-ddtext INTO ls_vrm_values-text SEPARATED BY  ``.
          ENDIF.
        ELSE.
          READ TABLE lt_dd04t WITH KEY rollname = lt_dd03l-rollname.
          IF sy-subrc = 0.
            CONCATENATE lt_dd03l-fieldname `:` lt_dd04t-ddtext INTO ls_vrm_values-text SEPARATED BY  ``.
          ENDIF.
        ENDIF.
        IF lt_dd03l-inttype = 'D'.
          APPEND ls_vrm_values TO lt_vrm_values_dt.
        ENDIF.
        APPEND ls_vrm_values TO lt_vrm_values.
      ENDLOOP.

    ENDFORM. "frm_val
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_1002  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_1002 OUTPUT.
      SET PF-STATUS 'ST_1002'.
      SET TITLEBAR '1002'.
      CLEAR: texttable[],line,gt_YTEST300,gt_YTEST300[].

      CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[],rtables,rtables[].
      PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING 'X'.

      CONCATENATE `CREATE TABLE IF NOT EXISTS SAP_R3_` p_table `(` INTO line.
      SELECT * FROM YTEST300 INTO TABLE gt_YTEST300 WHERE username = p_varusr AND tabname = p_table ORDER BY sequence ASCENDING.
      IF sy-subrc = 0.
        LOOP AT gt_YTEST300.
          READ TABLE gt_vrm_values WITH KEY key = gt_YTEST300-fldname.
          CLEAR:itab[].
          SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
          REPLACE ALL OCCURRENCES OF `'` IN c1  WITH ``.
          REPLACE ALL OCCURRENCES OF `,` IN c1  WITH ``.
          CONCATENATE line c_crlf gt_YTEST300-fldname ` STRING COMMENT '` c1 `',` INTO line SEPARATED BY ``.
        ENDLOOP.
      ELSE.
        LOOP AT gt_vrm_values.
          CLEAR:itab[].
          SPLIT gt_vrm_values-text AT `:` INTO itab c1 .
          REPLACE ALL OCCURRENCES OF `'` IN c1  WITH ``.
          REPLACE ALL OCCURRENCES OF `,` IN c1  WITH ``.
          CONCATENATE line c_crlf gt_vrm_values-key ` STRING COMMENT '` c1 `',` INTO line SEPARATED BY ``.
        ENDLOOP.
      ENDIF.
      DATA: str_len TYPE i.
      str_len = STRLEN( line ).
      str_len = str_len - 1.
      line = line+0(str_len).
      CONCATENATE line c_crlf `);` INTO line.
      APPEND line TO texttable.

      IF editor_container2 IS NOT BOUND.
        CREATE OBJECT editor_container2
              EXPORTING
                container_name =  'EDITOR2'.

        CREATE OBJECT editor2
            EXPORTING
              parent = editor_container2
              wordwrap_mode = 1
              max_number_chars = 12000.
      ENDIF.
      editor2->set_textstream( line ).
    ENDMODULE. " STATUS_1002 OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  user_command_1002  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_1002 INPUT.
      CASE sy-ucomm.
        WHEN 'RW'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE. " user_command_1002 INPUT
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_1003  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_1003 OUTPUT.
      SET PF-STATUS 'ST_1003'.
      SET TITLEBAR '1003'.

      DATA: code TYPE TABLE OF string WITH HEADER LINE.

      CLEAR: line,gt_YTEST300,gt_YTEST300[].

      IF editor_container3 IS NOT BOUND.
        CREATE OBJECT editor_container3
              EXPORTING
                container_name =  'EDITOR3'.

        CREATE OBJECT editor3
            EXPORTING
              parent = editor_container3
              wordwrap_mode = 1
              max_number_chars = 600000.
      ENDIF.
      READ REPORT 'YTEMPLET' INTO code.
      LOOP AT code.
        IF line = ''.
          line = code.
        ELSE.
          CONCATENATE  line cl_abap_char_utilities=>cr_lf code INTO line.
        ENDIF.
      ENDLOOP.
      editor3->set_textstream( line ).
    ENDMODULE. " STATUS_1003 OUTPUT

    *&---------------------------------------------------------------------*
    *&      Form  frm_key_constr
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_SRC_TAB     text
    *      -->LT_DD03L      text
    *      -->P_KEY_CONSTR  text
    *      -->P_ORDERBY     text
    *----------------------------------------------------------------------*
    FORM frm_key_constr TABLES p_src_tab pt_dd03l STRUCTURE dd03l key_constr.
      DATA:lin TYPE i.
      DATA: counts TYPE i.
      FIELD-SYMBOLS: <fldvalue>.
      DATA: wa_dd03l LIKE lt_dd03l.
      DATA: p_key_constr TYPE string.
      DATA: lt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE.
      lt_dd03l[] = pt_dd03l[].
      READ TABLE lt_dd03l INTO wa_dd03l INDEX 1.
      DELETE lt_dd03l INDEX 1.
      DESCRIBE TABLE lt_dd03l LINES counts.
      DESCRIBE TABLE p_src_tab LINES lin.
      CHECK lin > 0.
      READ TABLE p_src_tab INDEX lin.

      DO.
        DO counts TIMES.
          READ TABLE lt_dd03l INDEX sy-index.
          ASSIGN COMPONENT lt_dd03l-fieldname OF STRUCTURE p_src_tab TO <fldvalue>.
          IF sy-index < counts.
            IF p_key_constr <>  ''.
              CONCATENATE p_key_constr lt_dd03l-fieldname ` = '` <fldvalue> `'` INTO p_key_constr.
            ELSE.
              CONCATENATE lt_dd03l-fieldname ` = '` <fldvalue> `'` INTO p_key_constr.
            ENDIF.
            CONCATENATE p_key_constr ` AND ` INTO p_key_constr.
          ELSEIF sy-index = counts.
            IF p_key_constr <>  ''.
              CONCATENATE p_key_constr lt_dd03l-fieldname ` > '` <fldvalue> `'` INTO p_key_constr.
            ELSE.
              CONCATENATE lt_dd03l-fieldname ` > '` <fldvalue> `'` INTO p_key_constr.
            ENDIF.
          ENDIF.
        ENDDO.
        counts = counts - 1.
        IF counts <= 0.
          EXIT.
        ELSE.
          CONCATENATE p_key_constr ` OR ` INTO p_key_constr.
        ENDIF.
      ENDDO.
      CLEAR: itab,itab[].
      SPLIT p_key_constr AT ` OR ` INTO TABLE itab .
      DESCRIBE TABLE itab LINES counts.
      ASSIGN COMPONENT wa_dd03l-fieldname OF STRUCTURE p_src_tab TO <fldvalue>.
      DO counts TIMES.
        READ TABLE itab INDEX sy-index.
        CONCATENATE wa_dd03l-fieldname ` = '` <fldvalue> `' AND ` itab INTO key_constr.
        APPEND key_constr.
      ENDDO.
    ENDFORM. " frm_key_constr

    *&---------------------------------------------------------------------*
    *&      Form  frm_comp_tab
    *&---------------------------------------------------------------------*
    *       递归将某结构组件展开(如:由于BKPF表中.APPEND附加结构,通过
    *       struct_type ?= cl_abap_typedescr=>describe_by_name( 'BKPF' )获得
    *       的组件中就会有STRU类型的组件,而非基本类型组件,所以需递归展开)
    *----------------------------------------------------------------------*
    *      -->COMP_TAB   某结构的组件
    *----------------------------------------------------------------------*
    FORM frm_comp_tab TABLES comp_tab TYPE cl_abap_structdescr=>component_table.
      DATA: lt_comp_tab LIKE comp_tab[] WITH HEADER LINE.
      DATA:struct_type3 TYPE REF TO cl_abap_structdescr,
         comp_tab3 TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.

      LOOP AT comp_tab .
        IF comp_tab-name <> ''.
          APPEND comp_tab TO lt_comp_tab.
        ELSE.
          struct_type3 ?= comp_tab-type.
          comp_tab3[] = struct_type3->get_components( ).
          PERFORM frm_comp_tab TABLES comp_tab3.
          APPEND LINES OF comp_tab3 TO lt_comp_tab.
        ENDIF.
      ENDLOOP.
      comp_tab[] = lt_comp_tab[].
    ENDFORM. " frm_comp_tab

    *&---------------------------------------------------------------------*
    *&      Form  frm_find_table
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM frm_find_table USING p_tablex.
      DATA: code TYPE TABLE OF string WITH HEADER LINE.
      DATA: off  TYPE i,
            moff TYPE i,
            mlen TYPE i,
            diffoff TYPE i.
      DATA: tmpstr TYPE string.
      CLEAR:rtables,rtables[].


      IF p_prog IS NOT INITIAL.
        READ REPORT p_prog INTO code.
        line = ''.
        LOOP AT code.
          REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN code WITH ` `.
          CONDENSE code.
          CLEAR itab.
          SPLIT code AT ` ` INTO TABLE itab .
          LOOP AT itab WHERE table_line IS NOT INITIAL.
            IF line = ''.
              line = itab.
            ELSE.
              CONCATENATE  line ` ` itab INTO line SEPARATED BY ``.
            ENDIF.
          ENDLOOP.
        ENDLOOP.
        off = 0.
        DO.
          FIND ` FROM ` IN SECTION OFFSET off OF
               line
               IGNORING CASE
               MATCH OFFSET moff
               MATCH LENGTH mlen.
          IF sy-subrc = 0.
            off = moff + mlen.
            FIND ` ` IN SECTION OFFSET off OF
               line
               IGNORING CASE
               MATCH OFFSET moff
               MATCH LENGTH mlen.
            tmpstr = line.
            diffoff = moff - off.
            tmpstr = tmpstr+off(diffoff).
            CONDENSE tmpstr.
            rtables-sign = 'I'.
            rtables-option = 'EQ'.
            rtables-low = tmpstr.
            SET LOCALE LANGUAGE '1' .
            TRANSLATE rtables-low TO UPPER CASE.
            APPEND rtables.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.

        off = 0.
        DO.
          FIND ` JOIN ` IN SECTION OFFSET off OF
               line
               IGNORING CASE
               MATCH OFFSET moff
               MATCH LENGTH mlen.
          IF sy-subrc = 0.
            off = moff + mlen.
            FIND ` ` IN SECTION OFFSET off OF
               line
               IGNORING CASE
               MATCH OFFSET moff
               MATCH LENGTH mlen.
            tmpstr = line.
            diffoff = moff - off.
            tmpstr = tmpstr+off(diffoff).
            CONDENSE tmpstr.
            rtables-sign = 'I'.
            rtables-option = 'EQ'.
            rtables-low = tmpstr.
            SET LOCALE LANGUAGE '1' .
            TRANSLATE rtables-low TO UPPER CASE.
            APPEND rtables.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
      ENDIF.

      IF rtables[] IS NOT INITIAL AND p_tablex IS NOT INITIAL.
        rtables-sign = 'I'.
        rtables-option = 'EQ'.
        rtables-low = p_table.
        SET LOCALE LANGUAGE '1' .
        TRANSLATE rtables-low TO UPPER CASE.
        APPEND rtables.
      ENDIF.

      CLEAR:gt_vrm_values,gt_vrm_values[],gt_vrm_values_dt,gt_vrm_values_dt[],gt_dd03l,gt_dd03l[].
      PERFORM frm_val TABLES gt_vrm_values rtables gt_vrm_values_dt gt_dd03l USING 'X'.

    ENDFORM. "frm_find_table


    *&---------------------------------------------------------------------*
    *&      Form  frm_find_sel
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM frm_find_sel .
      DATA: code TYPE TABLE OF string WITH HEADER LINE.
      DATA: off  TYPE i,
            moff TYPE i,
            moff2 TYPE i,
            mlen TYPE i,
            diffoff TYPE i.


      DATA: BEGIN OF lt_sel OCCURS 0,
        sel TYPE string,
      END OF lt_sel.
      lt_sel-sel = ` IN S_ASIST1`.
      APPEND lt_sel.
      lt_sel-sel = ` IN S_ASIST2`.
      APPEND lt_sel.
      lt_sel-sel = ` IN S_ASIST3`.
      APPEND lt_sel.
      lt_sel-sel = ` IN S_ASIST4`.
      APPEND lt_sel.
      lt_sel-sel = ` IN S_ASIST5`.
      APPEND lt_sel.

      CLEAR:sel_flds,sel_flds[].
      IF p_prog IS NOT INITIAL.
        READ REPORT p_prog INTO code.
        line = ''.
        LOOP AT code.
          REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab IN code WITH ` `.
          CONDENSE code.
          CLEAR itab.
          SPLIT code AT ` ` INTO TABLE itab .
          LOOP AT itab WHERE table_line IS NOT INITIAL.
            IF line = ''.
              line = itab.
            ELSE.
              CONCATENATE  line ` ` itab INTO line SEPARATED BY ``.
            ENDIF.
          ENDLOOP.
        ENDLOOP.
        off = 0.
        LOOP AT lt_sel.
          DO.
            FIND lt_sel-sel IN SECTION OFFSET off OF
                 line
                 IGNORING CASE
                 MATCH OFFSET moff
                 MATCH LENGTH mlen.
            IF sy-subrc = 0.
              moff2 = moff - 1.
              WHILE line+moff2(1) <> ` `.
                moff2 = moff2 - 1.
                IF moff2 < 0.
                  EXIT.
                ENDIF.
              ENDWHILE.
              diffoff = moff - moff2.
              sel_flds-fld = line+moff2(diffoff).
              SHIFT sel_flds-fld UP TO `~` LEFT.
              REPLACE ALL OCCURRENCES OF `~` IN sel_flds-fld WITH ``.
              CONDENSE sel_flds-fld.
              TRANSLATE sel_flds-fld TO UPPER CASE.
              CASE lt_sel-sel.
                WHEN ` IN S_ASIST1`.
                  sel_flds-p_snam = 's_asist1'.
                WHEN ` IN S_ASIST2`.
                  sel_flds-p_snam = 's_asist2'.
                WHEN ` IN S_ASIST3`.
                  sel_flds-p_snam = 's_asist3'.
                WHEN ` IN S_ASIST4`.
                  sel_flds-p_snam = 's_asist4'.
                WHEN ` IN S_ASIST5`.
                  sel_flds-p_snam = 's_asist5'.
              ENDCASE.
              APPEND sel_flds.
              off = moff + mlen.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
        ENDLOOP.
      ENDIF.

    ENDFORM. "frm_find_table
    *&---------------------------------------------------------------------*
    *&      Module  user_command_1003  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_1003 INPUT.
      CASE sy-ucomm.
        WHEN 'RW'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE. " user_command_1003 INPUT

    *&---------------------------------------------------------------------*
    *&      Form  frm_write_file
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_SRC_TAB  text
    *----------------------------------------------------------------------*
    FORM frm_write_file TABLES p_src_tab.

      DATA:str TYPE string.
      CONCATENATE  `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
      CONCATENATE  `正在向SAP服务上Append文件:` gv_filename INTO str.

      IF g_count = 2.
        DELETE DATASET gv_filename.
      ENDIF.

      CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
        EXPORTING
          percentage = 20
          text       = str.

      DATA buffer TYPE xstring.
      PERFORM frm_buffer TABLES p_src_tab USING buffer.
      OPEN DATASET gv_filename FOR APPENDING IN BINARY MODE.

      TRANSFER buffer TO gv_filename.

      CLOSE DATASET gv_filename.
    ENDFORM. " frm_write_file
    *&---------------------------------------------------------------------*
    *&      Form  frm_ftp_append
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM frm_ftp_append .
      DATA: localfile TYPE string.
      PERFORM f_ftp_connect.
      PERFORM frm_cd_dir.
      CONCATENATE  p_fil_px2 `.` p_extens INTO gv_filename SEPARATED BY ``.
      CONCATENATE  `/usr/sap/tmp/` p_fil_px2 `.` p_extens INTO localfile SEPARATED BY ``.
      CLEAR:com,com[],res,res[].
      CONCATENATE 'append ' localfile  gv_filename INTO com-cmd SEPARATED BY ' '.

      CALL FUNCTION 'FTP_COMMAND'
        EXPORTING
          handle        = thandle
          command       = com-cmd
        TABLES
          data          = res
        EXCEPTIONS
          tcpip_error   = 1
          command_error = 2
          data_error    = 3
          OTHERS        = 4.

      PERFORM f_ftp_disconnect.

    ENDFORM. " frm_ftp_append
    *&---------------------------------------------------------------------*
    *&      Form  frm_buffer
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->P_BUFFER  text
    *----------------------------------------------------------------------*
    FORM frm_buffer TABLES p_src_tab USING p_buffer.
      DATA:strct_type_ref TYPE REF TO cl_abap_structdescr,
              tab_type_ref TYPE REF TO cl_abap_tabledescr,
              t_component TYPE cl_abap_structdescr=>component_table,
              wa_component LIKE LINE OF t_component.
      FIELD-SYMBOLS: <fldvalue>.

      DATA: l_str TYPE string,fldstr TYPE string,fldtype,firsttime VALUE 'X'.

      DATA: str TYPE string.
      DATA: codepage TYPE cpcodepage,
         encoding TYPE abap_encoding,
        convout TYPE REF TO cl_abap_conv_out_ce.
      DATA:time_stamp TYPE timestampl,timestamp_c(22).

      CALL FUNCTION 'SCP_CODEPAGE_BY_EXTERNAL_NAME'
        EXPORTING
          external_name = p_encodi
        IMPORTING
          sap_codepage  = codepage.
      encoding = codepage.

      CALL METHOD cl_abap_conv_out_ce=>create
        EXPORTING
          encoding = encoding
        RECEIVING
          conv     = convout.

      tab_type_ref ?= cl_abap_tabledescr=>describe_by_data( p_src_tab[] ).
      strct_type_ref ?= tab_type_ref->get_table_line_type( ).
      t_component = strct_type_ref->get_components( ).

      str = p_split.
      REPLACE ALL OCCURRENCES OF ` ` IN str  WITH c_tab.
      REPLACE ALL OCCURRENCES OF `T` IN str  WITH c_tab.
      REPLACE ALL OCCURRENCES OF ` ` IN str  WITH ``.


      GET TIME STAMP FIELD time_stamp.
      timestamp_c = time_stamp.


      LOOP AT p_src_tab.
        firsttime = 'X'.
        CLEAR:fldstr,l_str.
        LOOP AT t_component INTO wa_component.

          IF wa_component-name = 'ZTIMESTAMPL'.
            IF firsttime = 'X'.
              fldstr = time_stamp.
              CLEAR firsttime.
            ELSE.
              CONCATENATE fldstr timestamp_c INTO fldstr SEPARATED BY str.
            ENDIF.
            CONTINUE.
          ENDIF.

          fldtype = wa_component-type->type_kind.
          ASSIGN COMPONENT wa_component-name OF STRUCTURE p_src_tab TO <fldvalue>.
          l_str = <fldvalue>.
          IF fldtype = 'P' OR fldtype = 'F'
            OR fldtype = 'I' OR fldtype = 'b'
            OR fldtype = 's'.
            CALL FUNCTION 'CLOI_PUT_SIGN_IN_FRONT'
              CHANGING
                value = l_str.
          ENDIF.
          REPLACE ALL OCCURRENCES OF str IN l_str  WITH ` `.
          IF firsttime = 'X'.
            fldstr = l_str .
            CLEAR firsttime.
          ELSE.
            CONCATENATE fldstr l_str INTO fldstr SEPARATED BY str.
          ENDIF.
        ENDLOOP.

        CONDENSE fldstr.
        CALL METHOD convout->write
          EXPORTING
            data = fldstr.
        CALL METHOD convout->write
          EXPORTING
            data = cl_abap_char_utilities=>cr_lf.
      ENDLOOP.
      CALL METHOD convout->get_buffer
        RECEIVING
          buffer = p_buffer.
    ENDFORM. " frm_buffer

    *&---------------------------------------------------------------------*
    *&      Form  frm_write_file2
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->STR1       text
    *      -->STR2       text
    *----------------------------------------------------------------------*
    FORM frm_write_file2 USING str1 lins tabix .
      DATA:str TYPE string.
      GET RUN TIME FIELD tm2.
      tm = ( tm2 - tm1 ) / 1000 / 1000.
      tm1 = tm2.
      str = lins.
      CONCATENATE  `/usr/sap/tmp/` p_fil_px2 `.log` INTO gv_filename SEPARATED BY ``.
      IF tabix = 1 AND g_count = 1.
        DELETE DATASET gv_filename.
      ENDIF.
      OPEN DATASET gv_filename FOR APPENDING IN TEXT MODE ENCODING  DEFAULT.
      CONCATENATE `【` str `条】` str1 ` : 【` tm `秒】`INTO str.
      TRANSFER str TO gv_filename.
      CLOSE DATASET gv_filename.
    ENDFORM. "frm_write_file2


    *&---------------------------------------------------------------------*
    *&      Form  frm_write_file3
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    FORM frm_write_file3.
      DATA:str TYPE string.
      CONCATENATE  `/usr/sap/tmp/` p_fil_px2 `.log` INTO gv_filename SEPARATED BY ``.

      OPEN DATASET gv_filename FOR APPENDING IN TEXT MODE ENCODING  DEFAULT.
      TRANSFER g_count TO gv_filename.
      TRANSFER ` ` TO gv_filename.
      CLOSE DATASET gv_filename.
    ENDFORM. "frm_write_file3

    Code listing for: YR3TABLE2FTP_SELSCR

    Description: Include YR3TABLE2FTP_SELSCR

    *&---------------------------------------------------------------------*
    *&  包括              YR3TABLE2FTP_SELSCR
    *&---------------------------------------------------------------------*
    DATA: d TYPE sy-datum,c(35),c35(35).

    SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-008 FOR FIELD p_table,
     POSITION POS_LOW.
    PARAMETERS:p_table(16) OBLIGATORY.
    SELECTION-SCREEN COMMENT 50(20) text-009.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN: BEGIN OF BLOCK b11 WITH FRAME TITLE text-021.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(10) text-003 FOR FIELD p_name1,
     POSITION POS_LOW.
    PARAMETERS: p_name1(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val1 FOR d .

    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-004 FOR FIELD p_name2,
     POSITION POS_LOW.
    PARAMETERS: p_name2(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val2 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-005 FOR FIELD p_name3,
     POSITION POS_LOW.
    PARAMETERS: p_name3(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val3 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-006 FOR FIELD p_name4,
     POSITION POS_LOW.
    PARAMETERS: p_name4(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val4 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-007 FOR FIELD p_name5,
     POSITION POS_LOW.
    PARAMETERS: p_name5(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val5 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-010 FOR FIELD p_name6,
     POSITION POS_LOW.
    PARAMETERS: p_name6(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val6 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-011 FOR FIELD p_name7,
     POSITION POS_LOW.
    PARAMETERS: p_name7(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val7 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-012 FOR FIELD p_name8,
     POSITION POS_LOW.
    PARAMETERS: p_name8(20) AS LISTBOX VISIBLE LENGTH 30.
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_val8 FOR c VISIBLE LENGTH 30.
    SELECTION-SCREEN END OF LINE.

    PARAMETERS:p_counts(10) TYPE n DEFAULT '100000' OBLIGATORY.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 63(75) text-016.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 63(75) text-031.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN PUSHBUTTON 1(40) but1 USER-COMMAND cli1
                               VISIBLE LENGTH 15.
    SELECTION-SCREEN PUSHBUTTON 20(40) but2 USER-COMMAND cli2
                               VISIBLE LENGTH 15.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN END OF BLOCK b11.


    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN: COMMENT 1(18) text-112 FOR FIELD p_name8,
    POSITION POS_LOW.
    PARAMETERS: p_prog(20) .
    SELECTION-SCREEN COMMENT 54(16) text-900.
    SELECTION-SCREEN PUSHBUTTON 70(20) but3 USER-COMMAND cli3
                               VISIBLE LENGTH 20.
    SELECTION-SCREEN END OF LINE.


    SELECTION-SCREEN: BEGIN OF BLOCK b3 WITH FRAME TITLE text-030.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-003 FOR FIELD p_snam1,
     POSITION POS_LOW.
    PARAMETERS: p_snam1(30) .
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_asist1 FOR c35 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-004 FOR FIELD p_snam2,
     POSITION POS_LOW.
    PARAMETERS: p_snam2(30) .
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_asist2 FOR c35 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-005 FOR FIELD p_snam3,
     POSITION POS_LOW.
    PARAMETERS: p_snam3(30) .
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_asist3 FOR c35 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-006 FOR FIELD p_snam4,
     POSITION POS_LOW.
    PARAMETERS: p_snam4(30) .
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_asist4 FOR c35 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-007 FOR FIELD p_snam5,
     POSITION POS_LOW.
    PARAMETERS: p_snam5(30) .
    SELECTION-SCREEN POSITION 61.
    SELECT-OPTIONS:s_asist5 FOR c35 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN END OF BLOCK b3.

    SELECTION-SCREEN END OF BLOCK b1.

    SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
    PARAMETERS:
                p_host(60)  LOWER CASE OBLIGATORY VISIBLE LENGTH 15
                            DEFAULT '10.27.15.33' ,
                p_user(15) TYPE c  LOWER CASE OBLIGATORY
                              DEFAULT 'ftp_r3_w',
                p_pwd(15) TYPE c LOWER CASE OBLIGATORY
                              DEFAULT 'ftp_r3_w@123',
                ftp_path(100)  LOWER CASE DEFAULT '/' VISIBLE LENGTH 30 OBLIGATORY.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-071 FOR FIELD p_dir_dt,
     POSITION POS_LOW.
    PARAMETERS: p_dir_dt TYPE sy-datum DEFAULT sy-datum.
    SELECTION-SCREEN: COMMENT 45(64) text-018.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-017 FOR FIELD  p_fil_px,
     POSITION POS_LOW.
    PARAMETERS: p_fil_px(20) LOWER CASE.
    *SELECTION-SCREEN: COMMENT 54(9) text-231.
    PARAMETERS p_ymd(14) AS LISTBOX VISIBLE LENGTH 9 DEFAULT 'YYYYMMDD'.
    PARAMETERS p_fileno(7) AS LISTBOX VISIBLE LENGTH 9 DEFAULT '_NNNNNNN'.
    SELECTION-SCREEN: COMMENT 74(1) text-033.
    SELECTION-SCREEN:POSITION 75.
    PARAMETERS: p_extens(6) LOWER CASE DEFAULT 'DAT' VISIBLE LENGTH 3.
    SELECTION-SCREEN: COMMENT 79(75) text-028.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-771 FOR FIELD p_ymd2,
     POSITION POS_LOW.
    PARAMETERS: p_ymd2 TYPE sy-datum DEFAULT sy-datum.
    SELECTION-SCREEN: COMMENT 45(64) text-118.
    SELECTION-SCREEN END OF LINE.

    PARAMETERS:p_encodi(10) AS LISTBOX VISIBLE LENGTH 10 DEFAULT 'UTF-8' OBLIGATORY.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-013 FOR FIELD p_split,
     POSITION POS_LOW.
    PARAMETERS p_split(3) OBLIGATORY DEFAULT '|'.
    SELECTION-SCREEN COMMENT 37(79) text-014 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(14) text-133 FOR FIELD p_flgex,
     POSITION POS_LOW.
    PARAMETERS p_flgex(6) LOWER CASE OBLIGATORY VISIBLE LENGTH 3 DEFAULT 'FLG'.
    SELECTION-SCREEN COMMENT 37(79) text-140 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(12) text-123 ,
     POSITION POS_LOW.
    PARAMETERS: p_header AS CHECKBOX DEFAULT ''.
    SELECTION-SCREEN:COMMENT 37(73) text-126 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(18) text-213 ,
     POSITION POS_LOW.
    PARAMETERS: p_hdtlg AS CHECKBOX DEFAULT ''.
    SELECTION-SCREEN:COMMENT 37(73) text-128 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(32) text-121 ,
     POSITION POS_LOW.
    PARAMETERS: pflgfile AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(32) text-122 ,
     POSITION POS_LOW.
    PARAMETERS: timestmp AS CHECKBOX DEFAULT ''.
    SELECTION-SCREEN:COMMENT 37(73) text-129 .
    SELECTION-SCREEN END OF LINE.

    SELECTION-SCREEN END OF BLOCK b2.

    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN:
     COMMENT 1(18) text-127 ,
     POSITION POS_LOW.
    PARAMETERS: psqllog AS CHECKBOX DEFAULT ''.
    SELECTION-SCREEN END OF LINE.

    PARAMETERS: p_varusr TYPE usr02-bname DEFAULT sy-uname NO-DISPLAY.

    Code listing for: YR3TABLE2FTP_TOP

    Description: Include YR3TABLE2FTP_TOP

    *&---------------------------------------------------------------------*
    *&  包括              YR3TABLE2FTP_TOP
    *&---------------------------------------------------------------------*
    TYPE-POOLS:vrm.
    TABLES: dd02l,progdir.

    DATA:g_count(6) TYPE n,
         g_count_c(7).

    DATA: key TYPE i VALUE 26101957,
          trfcdest LIKE rfcdes-rfcdest,
          thandle TYPE i,
          slen TYPE i.

    DATA: gv_filename(50).

    DATA: BEGIN OF com OCCURS 0,
            cmd(100) TYPE c,
          END OF com.
    DATA: BEGIN OF res OCCURS 0,
            line(100) TYPE c,
          END OF res.


    DATA: flg_ftp.
    DATA: g_last_tbname(16).

    DATA: BEGIN OF gt_name OCCURS 0,
          name TYPE string,
          END OF gt_name.
    DATA:gt_YTEST300 TYPE TABLE OF YTEST300 WITH HEADER LINE.
    *DATA:gt_zfit699 TYPE TABLE OF zfit699 WITH HEADER LINE.
    DATA: editor_container TYPE REF TO cl_gui_custom_container,
     editor TYPE REF TO cl_gui_textedit.
    DATA: editor_container2 TYPE REF TO cl_gui_custom_container,
    editor2 TYPE REF TO cl_gui_textedit.
    DATA: editor_container3 TYPE REF TO cl_gui_custom_container,
    editor3 TYPE REF TO cl_gui_textedit.
    CONSTANTS: c_line_length TYPE i VALUE 255.
    TYPES: BEGIN OF st_text,
      line TYPE c LENGTH c_line_length,
    END OF st_text.
    TYPES: tt_text TYPE STANDARD TABLE OF st_text.
    DATA texttable TYPE tt_text WITH HEADER LINE.
    DATA line TYPE string.
    DATA: itab TYPE TABLE OF string WITH HEADER LINE,
          itab2 TYPE TABLE OF string WITH HEADER LINE,
          c1(50),repeat TYPE i,
          g_tabix TYPE sy-tabix.
    CONSTANTS: c_crlf(2) TYPE c VALUE cl_abap_char_utilities=>cr_lf.
    CONSTANTS: c_tab(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
    DATA:gt_vrm_values TYPE vrm_values WITH HEADER LINE,gt_vrm_values_dt TYPE vrm_values.
    DATA:gt_dd03l TYPE TABLE OF dd03l WITH HEADER LINE.

    DATA:struct_type TYPE REF TO cl_abap_structdescr,
        elem_type TYPE REF TO cl_abap_elemdescr,
        table_type TYPE REF TO cl_abap_tabledescr,
        comp_tab TYPE cl_abap_structdescr=>component_table WITH HEADER LINE,
        comp_tab2 TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.
    DATA: flg2.
    DATA: rtables TYPE TABLE OF range_c35 WITH HEADER LINE.

    DATA: BEGIN OF sel_flds OCCURS 0,
      fld TYPE string,
      p_snam TYPE string,
    END OF sel_flds.
    DATA: p_fil_px2 TYPE string.

    DATA: tm1 TYPE i,tm2 TYPE i,tm TYPE string.

    Table: YTEST300

    Description: 输出字段配置

    RowField namePositionKeyData elementDomainDatatypeLengthLowercaseDomain text
    1 MANDT 1 X MANDT MANDT CLNT 3   客户端
    2 USERNAME 2 X XUBNAME XUBNAME CHAR 12   用户主记录中的用户名称
    3 TABNAME 3 X     CHAR 20   表名
    4 FLDNAME 4 X     CHAR 20   字段名
    5 SEQUENCE 5 X     INT2 5   位置

     

    Code listing for: YTEMPLET

    Description: 输出扩展模板程序

    REPORT YTEMPLET.
    *&---------------------------------------------------------------------*
    *&      Form  frm_dyn
    *&---------------------------------------------------------------------*
    *       YR3TABLE2FTP(R3表抛FTP通用程序)输出逻辑扩展程序
    *----------------------------------------------------------------------*
    *      -->OUTPUT_TAB   原主表输出内表
    *      -->COMP_TAB     原主表输出内表结构
    *      -->S_ASIST1     关联表条件1
    *      -->S_ASIST2     关联表条件2
    *      -->S_ASIST3     关联表条件3
    *      -->S_ASIST4     关联表条件4
    *      -->S_ASIST5     关联表条件5
    *      -->DY_TAB_NEW_REF  新输出内表内存地址
    *----------------------------------------------------------------------*
    FORM frm_dyn TABLES output_tab
    comp_tab TYPE cl_abap_structdescr=>component_table
    s_asist1 STRUCTURE range_c35
    s_asist2 STRUCTURE range_c35
    s_asist3 STRUCTURE range_c35
    s_asist4 STRUCTURE range_c35
    s_asist5 STRUCTURE range_c35
    USING dy_tab_new_ref TYPE REF TO data.
      "-------------------------------------------勿动--BEGIN----------------------------------------->>
      FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,<dyn_wa>.
      FIELD-SYMBOLS: <dyn_table2> TYPE STANDARD TABLE,<dyn_wa2>.
      FIELD-SYMBOLS: <fldvalue>.
      DATA: dy_table TYPE REF TO data, dy_line TYPE REF TO data.
      DATA: dy_table2 TYPE REF TO data, dy_line2 TYPE REF TO data.
      DATA: elem_type TYPE REF TO cl_abap_elemdescr,
            struct_type_new TYPE REF TO cl_abap_structdescr,
            struct_type_new2 TYPE REF TO cl_abap_structdescr,
            table_type_new TYPE REF TO cl_abap_tabledescr,
            table_type_new2 TYPE REF TO cl_abap_tabledescr,
            comp_tab_new TYPE cl_abap_structdescr=>component_table WITH HEADER LINE."最终输出结构
      "-------------------------------------------勿动--E-N-D-----------------------------------------<<

      "在这里自定义变量
      DATA:struct_type_YTEST200 TYPE REF TO cl_abap_structdescr,
           comp_tab_YTEST200 TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.

      DATA: BEGIN OF it_gwnr OCCURS 0,
            gwnr TYPE YTEST100-gwnr,
      END OF it_gwnr.
      DATA: it_YTEST200 TYPE TABLE OF YTEST200 WITH HEADER LINE.
      FIELD-SYMBOLS:<it_YTEST200> TYPE YTEST200.

      "在这里修改输出结构
      LOOP AT comp_tab WHERE name = 'GWNR'.
        APPEND comp_tab TO comp_tab_new.
      ENDLOOP.
      struct_type_YTEST200 ?= cl_abap_typedescr=>describe_by_name( 'YTEST200' ).
      comp_tab_YTEST200[] = struct_type_YTEST200->get_components( ).
      "递归将深层组件结构展平
      PERFORM frm_comp_tab IN PROGRAM YR3TABLE2FTP TABLES comp_tab_YTEST200.
    *  "删除不需要的输出字段
    *  DELETE comp_tab_YTEST200 WHERE name <> 'OMS_ORDER_ITEM_I' AND
    *                                name <> 'OMS_OLD_NO' AND
    *                                name <> 'CMMDTY_CODE' AND
    *                                name <> 'POSORDERID' AND
    *                                name <> 'SUPPLIER_CODE' AND
    *                                name <> 'ORDER_DATE' AND
    *                                name <> 'COST_PRICE' AND
    *                                name <> 'ORDER_SALE_TOTAL' AND
    *                                name <> 'QUANTITY' AND
    *                                name <> 'BILL_TYPE' AND
    *                                name <> 'SALE_COMPANY'.
    *  APPEND LINES OF comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'OMS_ORDER_ITEM_I'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'OMS_OLD_NO'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'CMMDTY_CODE'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
    *  READ TABLE comp_tab_YTEST200 WITH KEY name = 'POSORDERID'.
    *  APPEND comp_tab_YTEST200 TO comp_tab_new.
      CLEAR: comp_tab_new.
      comp_tab_new-name = 'POSORDERID'.
      elem_type = cl_abap_elemdescr=>get_c( 14 ).
      comp_tab_new-type = elem_type.
      APPEND comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'SALE_OFFICE'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'SUPPLIER_CODE'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
    *  READ TABLE comp_tab_YTEST200 WITH KEY name = 'ORDER_DATE'.
    *  APPEND comp_tab_YTEST200 TO comp_tab_new.
      CLEAR: comp_tab_new.
      comp_tab_new-name = 'ORDER_DATE'.
      elem_type = cl_abap_elemdescr=>get_c( 10 ).
      comp_tab_new-type = elem_type.
      APPEND comp_tab_new.

      READ TABLE comp_tab_YTEST200 WITH KEY name = 'COST_PRICE'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'ORDER_SALE_TOTAL'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'QUANTITY'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'BILL_TYPE'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.
      READ TABLE comp_tab_YTEST200 WITH KEY name = 'SALE_COMPANY'.
      APPEND comp_tab_YTEST200 TO comp_tab_new.

      "除了上面通过 cl_abap_typedescr=>describe_by_name(table)从表直接获取外,如表中没有的可手动增加列,比如这里在输出结构最后加上一列fldname
    *  comp_tab_new-name = 'fldname'."设置列名为fldname
    *  elem_type = cl_abap_elemdescr=>get_c( 2 ). "类型为c(2),不同的类型需调用不同的方法获取,具体参照下面描述
    *  comp_tab_new-type = elem_type.
    *  APPEND comp_tab_new.
      "**************************************************
      "不同的ABAP类型需要调用不同的方法来获得:
      "ABAP类型 N:elem_type = cl_abap_elemdescr=>get_n( 内部长度 ).
      "ABAP类型 D:elem_type = cl_abap_elemdescr=>get_d( ).
      "ABAP类型 P:CALL METHOD cl_abap_elemdescr=>get_p
      " EXPORTING
      " p_length   = 内部长度
      " p_decimals = 小数位
      " RECEIVING
      " p_result   = elem_type.
      "ABAP类型 T:elem_type = cl_abap_elemdescr=>get_t( ).
      "ABAP类型 C:elem_type = cl_abap_elemdescr=>get_c( 内部长度 )."
      "ABAP类型 X:elem_type = cl_abap_elemdescr=>get_x( 内部长度 ).
      "ABAP类型 F:elem_type = cl_abap_elemdescr=>get_f( ).
      "ABAP类型 I、b、s:elem_type = cl_abap_elemdescr=>get_i( ).
      "ABAP类型 g:elem_type = cl_abap_elemdescr=>get_string( ).
      "ABAP类型 y:elem_type = cl_abap_elemdescr=>get_xstring( ).
      "**************************************************

      "-------------------------------------------勿动--BEGIN----------------------------------------->>
      struct_type_new = cl_abap_structdescr=>create( comp_tab_new[] ).
      table_type_new = cl_abap_tabledescr=>create( struct_type_new ).
      CREATE DATA dy_table TYPE HANDLE table_type_new.
      ASSIGN dy_table->* TO <dyn_table>.
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
      "-------------------------------------------勿动--E-N-D-----------------------------------------<<

      "在这里进行数据处理与输出数据重组
      LOOP AT output_tab.
        ASSIGN COMPONENT 'GWNR' OF STRUCTURE output_tab TO <fldvalue>.
        it_gwnr-gwnr = <fldvalue>.
        COLLECT it_gwnr.
      ENDLOOP.
      IF it_gwnr[] IS NOT INITIAL.
        SELECT * INTO CORRESPONDING FIELDS OF TABLE it_YTEST200
                   FROM
                         YTEST200 AS a
                   FOR ALL ENTRIES IN
                   it_gwnr
                   WHERE gwnr = it_gwnr-gwnr
                   AND a~rec_date IN s_asist3.
      ENDIF.

      DELETE TABLE comp_tab_new WITH TABLE KEY name = 'SALE_OFFICE'.
      struct_type_new2 = cl_abap_structdescr=>create( comp_tab_new[] ).
      table_type_new2 = cl_abap_tabledescr=>create( struct_type_new2 ).
      CREATE DATA dy_table2 TYPE HANDLE table_type_new2.
      ASSIGN dy_table2->* TO <dyn_table2>.
      CREATE DATA dy_line2 LIKE LINE OF <dyn_table2>.
      ASSIGN dy_line2->* TO <dyn_wa2>.
      DATA: posorderid TYPE string,sale_office TYPE string.

      LOOP AT it_YTEST200 ASSIGNING <it_YTEST200>.
        <it_YTEST200>-cost_price = <it_YTEST200>-cost_price * <it_YTEST200>-quantity.
        IF <it_YTEST200>-bill_type = '-1'.
          <it_YTEST200>-bill_type = 2.
        ENDIF.
        <it_YTEST200>-cost_price = ABS( <it_YTEST200>-cost_price ).
        <it_YTEST200>-quantity = ABS( <it_YTEST200>-quantity ).
        posorderid = <it_YTEST200>-posorderid.
        sale_office =  <it_YTEST200>-sale_office.
        CONDENSE: posorderid,sale_office.

        CONCATENATE posorderid sale_office INTO posorderid SEPARATED BY ``.
        CONCATENATE <it_YTEST200>-order_date+0(4) `-` <it_YTEST200>-order_date+4(2) `-` <it_YTEST200>-order_date+6(2) INTO sale_office SEPARATED BY ``.
        MOVE-CORRESPONDING <it_YTEST200> TO <dyn_wa2>.
        ASSIGN COMPONENT 'POSORDERID' OF STRUCTURE <dyn_wa2> TO <fldvalue>.
        <fldvalue> = posorderid.
        ASSIGN COMPONENT 'ORDER_DATE' OF STRUCTURE <dyn_wa2> TO <fldvalue>.
        <fldvalue> = sale_office.
        APPEND <dyn_wa2> TO <dyn_table2>.
      ENDLOOP.

      "-------------------------------------------勿动--BEGIN----------------------------------------->>
    *  GET REFERENCE OF <dyn_table> INTO dy_tab_new_ref.
      GET REFERENCE OF <dyn_table2> INTO dy_tab_new_ref.
      "-------------------------------------------勿动--E-N-D-----------------------------------------<<
    ENDFORM. "frm_dyn

     

    附件列表

  • 相关阅读:
    Linux安全应用之防垃圾邮件服务器的构建
    Postfix邮件系统安装配置视频
    Linux常用的安全工具
    Linux系统安全加固(一)
    全球开源软件发展趋势分析
    安装配置FreeBSD9全过程体验
    P1441-砝码称重
    POJ-2376 Cleaning Shifts
    P1514-引水入城
    P1378-油滴扩展
  • 原文地址:https://www.cnblogs.com/jiangzhengjun/p/6349181.html
Copyright © 2020-2023  润新知