SE14功能解析及数据恢复

6 篇文章 0 订阅

按:SE14危险吗?如果是故意删除数据库、清空数据,那当然是危险的,但是,如果是正常操作导致的问题,比如SE14失败、超时DUMP、丢失了表等等,相信你看完本文会感觉这都不是问题,使用工具程序顺手就能解决了。

下面正文开始:

SE14作为SAP透明表在数据库层的处理工具,作用很多,但是最经常使用的还是在SE11修改了表字段后调整之用。本文要讲的就是这个场景,阐述SE14调整表的过程以及遇到问题后如何恢复数据,文末附上一个解决问题需要用到工具程序。

  1. 什么时候需要运行SE14?

    当SE11修改了表的字段,新的类型长度如果小于原长度,或者是修改了字段的数据类型,比如C类型变成了P类型等等这些需要强制转换的场景,并且表内已经有了数据,这个时候就需要运行SE14,使数据库内已存在的数据符合新的数据类型。
     

  2. SE14的处理过程是怎样的?
    以表ZTEST为例,正常的处理过程分下面几个步骤:

    ①、给表改名,RENAME 'ZTEST' TO 'QCMZTEST',即在表的前面加上QCM
    ②、删除表的所有索引,DROP INDEX 'ZTEST~0'

    ③、根据修改后的透明表字段创建数据库表QCM8ZTEST
    ④、QCM8表创建所有索引,
    CREATE UNIQUE INDEX 'ZTEST~0' ON 'QCM8ZTEST'
    ⑤、数据从QCMZTEST 复制到 QCM8ZTEST。方法为取出QCM表内的数据放到内表,然后MOVE-CORRESPONDING到新的表结构的内表,然后内表数据插入到QCM8表。
    ⑥、删除QCM表,DROP TABLE 'QCMZTEST'.
    ⑦、把QCM8表改名为透明表表名,RENAME 'QCM8ZTEST' TO 'ZTEST'。(因为RENAME后数据库会自动把索引带过去,所以不需要删除索引重建)。

    出错后的继续调整过程:
    DROP TABLE 'QCM8ZTEST'
    CREATE TABLE 'QCM8ZTEST'
    CREATE UNIQUE INDEX 'ZTEST~0' ON 'QCM8ZTEST'......
    即继续调整的时候首先把QCM8表删除,然后从第三步开始执行
     

  3. SE14为什么会失败?失败有哪些原因?
    SE14的失败主要是发生第⑤步,MOVE-CORRESPONDING失败导致程序DUMP。
    MOVE-CORRESPONDING为什么会失败呢?
    因为MOVE-CORRESPONDING属于强制赋值,当字段的新旧类型不同,比如旧类型是C类型,值为“ABC”,新类型为P类型,强制赋值的时候,把“ABC”赋值给P类型就会导致程序DUMP,然后SE14就失败了。
    另外,前台执行超时也是一个常见的原因。
     

  4. 如何避免失败
    ①、使用后台执行的方式执行SE14
    ②、先把字段删除,激活后再把字段加上,同时类型改为新类型
    ③、使用工具程序把更改的字段Update为空,然后再运行SE14
     

  5. 如果已经失败了应该怎么办?
    ①、如果是前台执行超时导致的,只要勾中"后台",然后继续调整就行了
    be611c15be63ac37843e7ad9007979f5.png
     

    ②、如果是第5步失败,那么再继续调整也是没有用的,这个时候有两个办法,一是使用工具程序的Update功能把QCMZTEST表的更改字段清空,再运行“继续调整”,二是“解锁表格”,然后使用SE14的“创建数据库表”或者SE11保存直接生成ZTEST表,如果报索引无法创建的错误就使用工具程序DROP INDEX。使用第二种方法创建的表是空的,需要把数据再复制回来。
     

  6. SE11更改字段的建议
    ①、如果更改的字段数据不要了,删除再创建,如果还要,确保新格式能放下老数据

    ②、如果使用先删除再创建的方法,记得传输请求也是分两次

    ③、SE14尽量以后台的方式执行
     

  7. 工具程序的使用
    本辅助程序基本上能解决所有的SE14造成的问题,最起码价值20 Manday,但是因为直接操作数据库,也请谨慎使用。


    功能介绍:
    ①、查找表,可以根据表名查找是否存在,比如下面:
    1a2e2fa9aa862e6bcd372a143d5dd139.png58aae19605f7dcb106e58252a6f34c78.png

    ②、查看表内容,可以查看非SAP DDIC表的内容,比如QCM表
    bb668e82482975b44d3102e6124e9d07.png36aa231e71d9621f84f0a534bcbcc4a5.png

    ③、备份表,数据安全第一,任何时候多一个备份动作都是应该的
    84e07e6f74eda219479eb50e2a4e41e4.png

    ④、复制数据,核心功能,恢复数据用。可以把源表内容复制到目的表,主要是把QCMZTEST表的内容复制到ZTEST
    19a7bf1788659a83f57aa073b291a637.png

    ⑤、DROP INDEX,因为SE14的Bug,在解锁表后索引并没有删除,导致新建表失败或者没有索引,需要先DROP INDEX
    5286c1dbf3911b86832b80a04f2d9657.png

    ⑥、Update Table,可以update指定字段。在这儿用于把无法转换的字段清空。
    511da219108fe155ea6082944f213fff.png

  8. 源代码
    *&---------------------------------------------------------------------*
    *& Report ZSE14
    *&---------------------------------------------------------------------*
    *& Baitianzhen
    *& SE14辅助工具,请谨慎使用!
    *&---------------------------------------------------------------------*
    REPORT zse14 NO STANDARD PAGE HEADING.
     
     
    TABLES:dd02l,dd03l.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE btxt1.
      PARAMETERS: p_find RADIOBUTTON GROUP g1 USER-COMMAND uc DEFAULT 'X',
                  p_view RADIOBUTTON GROUP g1,
                  p_back RADIOBUTTON GROUP g1,
                  p_copy RADIOBUTTON GROUP g1,
                  p_drop RADIOBUTTON GROUP g1,
                  p_updt RADIOBUTTON GROUP g1.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE btxt2.
      PARAMETERS: p_index TYPE char20 MODIF ID a,
                  p_uptab TYPE tabname MODIF ID c,
                  p_upfld TYPE fieldname MODIF ID c,
                  p_upval TYPE char255   MODIF ID c,
                  p_frtab TYPE tabname MODIF ID g,
                  p_totab TYPE tabname MODIF ID g,
                  p_tanam TYPE tabname MODIF ID e,
                  p_where TYPE char255 MODIF ID b,
                  p_uprow TYPE i MODIF ID f DEFAULT 1000.
      SELECT-OPTIONS s_exfld FOR dd03l-fieldname NO INTERVALS MODIF ID d.
      PARAMETERS  p_trunc AS CHECKBOX MODIF ID d.
    SELECTION-SCREEN END OF BLOCK b2.
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE btxt3.
      PARAMETERS p_usejob AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK b3.
    SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE btxt4.
      SELECTION-SCREEN COMMENT /1(79): txt1,txt2,txt3,txt4,txt5,txt6,txt7.
    SELECTION-SCREEN END OF BLOCK b4.
     
     
    AT SELECTION-SCREEN OUTPUT.
      btxt1 = '功能'.
      btxt2 = '操作'.
      btxt3 = '选项'.
      btxt4 = '说明'.
      %_p_drop_%_app_%-text  = 'DROP INDEX'.
      %_p_copy_%_app_%-text  = '复制数据'.
      %_p_updt_%_app_%-text  = 'UPDATE TABLE'.
      %_p_view_%_app_%-text  = '查看表数据'.
      %_p_find_%_app_%-text  = '查找表'.
      %_p_back_%_app_%-text  = '备份表'.
      %_p_frtab_%_app_%-text = '从表'.
      %_p_totab_%_app_%-text = '到表'.
      %_s_exfld_%_app_%-text = '排除源表字段'.
      %_p_trunc_%_app_%-text = '复制前清空目的表(所有Client所有数据)'.
      %_p_index_%_app_%-text = '索引名'.
      %_p_where_%_app_%-text = 'WHERE语句'.
      %_p_uptab_%_app_%-text = 'UPDATE表'.
      %_p_upfld_%_app_%-text = 'UPDATE字段'.
      %_p_upval_%_app_%-text = 'UPDATE值为'.
      %_p_tanam_%_app_%-text = '数据库表名'.
      %_p_uprow_%_app_%-text = '最大行数'.
      %_p_usejob_%_app_%-text = '后台执行'.
      txt1 = '1.查找表主要是查询QCM/QCM8等在SAP DDIC看不到的表,支持星号通配符'.
      txt2 = '2.查看表数据显示QCM/QCM8等表的表内容,也可以查看其他未在DDIC的表'.
      txt3 = '3.备份表会直接在数据库生成表,如果目的表不输会在源表名后面添加_YYYYMMDDHHMMSS做新表名'.
      txt4 = '4.复制数据,把QCM的表内容复制到SAP透明表,勾中清空目的表会在复制前清空目的表数据且无法恢复'.
      txt5 = '5.DROP索引请输入索引全称,比如:ZTEST~0'.
      txt6 = '6.Update表会Update所有Client,如果需要指定Client,请在WHERE语句指定'.
      txt7 = '7.Update/复制数据功能建议勾上后台执行,执行后SM37查看结果'.
      LOOP AT SCREEN.
        CASE 'X'.
          WHEN p_drop.
            IF screen-group1 CA 'BCDEFG'.
              screen-active = '0'.
            ENDIF.
          WHEN p_copy.
            IF screen-group1 CA 'ACEF'.
              screen-active = '0'.
            ENDIF.
          WHEN p_updt.
            IF screen-group1 CA 'ADEFG'.
              screen-active = '0'.
            ENDIF.
          WHEN p_view.
            IF screen-group1 CA 'ACDG'.
              screen-active = '0'.
            ENDIF.
          WHEN p_find.
            IF screen-group1 CA 'ABCDFG'.
              screen-active = '0'.
            ENDIF.
          WHEN p_back.
            IF screen-group1 CA 'ACDEF'.
              screen-active = '0'.
            ENDIF.
        ENDCASE.
        MODIFY SCREEN.
      ENDLOOP.
     
     
    START-OF-SELECTION.
      IF sy-batch = '' AND p_usejob = 'X'.
        PERFORM submitjob.
      ELSE.
        CASE 'X'.
          WHEN p_updt.
            PERFORM confirm.
            CHECK sy-subrc = 0.
            PERFORM update_fld USING p_uptab p_upfld p_upval p_where.
          WHEN p_drop.
            PERFORM confirm.
            CHECK sy-subrc = 0.
            PERFORM drop_index USING p_index.
          WHEN p_copy.
            PERFORM confirm.
            CHECK sy-subrc = 0.
            PERFORM copy_data USING p_frtab p_totab.
          WHEN p_view.
            PERFORM view_data.
          WHEN p_find.
            PERFORM find_table.
          WHEN p_back.
            PERFORM back_table.
        ENDCASE.
      ENDIF.
     
     
    *&---------------------------------------------------------------------*
    *& 删除索引
    *&---------------------------------------------------------------------*
    FORM drop_index USING pv_index.
      DATA: lv_sql TYPE string.
     
     
      IF pv_index IS INITIAL.
        MESSAGE s000(oo) WITH '请输入索引名称'.
      ELSE.
        lv_sql = `drop index "` && pv_index && `"`.
        PERFORM exec_ddl USING lv_sql.
        CHECK sy-subrc = 0.
        MESSAGE s000(oo) WITH '删除成功'.
      ENDIF.
    ENDFORM.                    "drop_index
     
     
    *&---------------------------------------------------------------------*
    *& 执行SQL DDL
    *&---------------------------------------------------------------------*
    FORM exec_ddl USING pv_sql.
      DATA: lo_con TYPE REF TO cl_sql_connection,
            lo_sta TYPE REF TO cl_sql_statement,
            lx_err TYPE REF TO cx_sql_exception,
            lv_err TYPE char200.
     
     
      CREATE OBJECT lo_con.
      lo_sta = lo_con->create_statement( ).
      TRY.
          lo_sta->execute_ddl( statement = pv_sql ).
        CATCH cx_sql_exception INTO lx_err.
          lv_err = lx_err->sql_message.
          sy-subrc = 8.
          MESSAGE e000(oo) WITH lv_err(50) lv_err+50(50) lv_err+100(50)
                                lv_err+150(50).
      ENDTRY.
    ENDFORM.                    "exec_sql
     
     
    *&---------------------------------------------------------------------*
    *& Update表
    *&---------------------------------------------------------------------*
    FORM update_fld USING pv_tabnam pv_fldnam pv_fldval pv_where.
      DATA: lv_str TYPE string.
     
     
      IF pv_tabnam IS INITIAL OR
         pv_fldnam IS INITIAL.
        MESSAGE s000(oo) WITH '请输入表和字段名称'.
      ELSE.
        lv_str = pv_fldnam && ` = '` && pv_fldval && `'`.
        UPDATE (pv_tabnam) USING ALL CLIENTS "CLIENT SPECIFIED
          SET   (lv_str)
          WHERE (pv_where).
        IF sy-subrc = 0.
          CALL FUNCTION 'DB_COMMIT'.
          MESSAGE s000(oo) WITH '更新数据条数:' sy-dbcnt.
        ELSE.
          MESSAGE e000(oo) WITH '更新失败'.
        ENDIF.
      ENDIF.
    ENDFORM.                    "update_fld
     
     
    *&---------------------------------------------------------------------*
    *& 复制表数据
    *&---------------------------------------------------------------------*
    FORM copy_data USING pv_frtab pv_totab.
      DATA: lv_cursor TYPE cursor,
            lv_ddlstr TYPE string,
            lt_fields TYPE fkk_fields,
            lv_dbcntr TYPE i,
            lv_dbcntw TYPE i,
            lv_length TYPE i,
            lv_decims TYPE i,
            lr_data   TYPE REF TO data.
      DATA: lt_x031l  TYPE ddx031ltab WITH HEADER LINE.
      DATA: lt_compo  TYPE cl_abap_structdescr=>component_table WITH HEADER LINE.
      DATA: lo_tabdes TYPE REF TO cl_abap_tabledescr.
      FIELD-SYMBOLS: <lt_src> TYPE STANDARD TABLE,
                     <lt_dst> TYPE STANDARD TABLE,
                     <ls_src> TYPE any,
                     <ls_dst> TYPE any.
     
     
      IF pv_frtab IS INITIAL OR
         pv_totab IS INITIAL.
        MESSAGE s000(oo) WITH '源表和目的表必须输入'.
        RETURN.
      ENDIF.
     
     
      SELECT SINGLE * FROM dd02l
        WHERE tabname  = pv_totab AND
              as4local = 'A'.
      IF sy-subrc NE 0.
        MESSAGE s000(oo) WITH '目的表只能是SAP数据字典存在并激活的表'.
        RETURN.
      ENDIF.
     
     
      CALL FUNCTION 'DD_GET_NAMETAB'
        EXPORTING
          tabname   = pv_frtab
        TABLES
          x031l_tab = lt_x031l
        EXCEPTIONS
          OTHERS    = 1.
      IF sy-subrc NE 0.
        MESSAGE e000(oo) WITH '获取表结构失败:' pv_frtab.
      ENDIF.
     
     
      IF s_exfld[] IS NOT INITIAL.
        DELETE lt_x031l WHERE fieldname IN s_exfld.
      ENDIF.
     
     
      LOOP AT lt_x031l.
        APPEND lt_x031l-fieldname TO lt_fields.
     
     
        IF lt_x031l-exid CA 'CN'.
          lv_length = lt_x031l-dblength / 2.
        ELSE.
          lv_length = lt_x031l-dblength.
        ENDIF.
        lv_decims     = lt_x031l-decimals.
     
     
        lt_compo-name = lt_x031l-fieldname.
        PERFORM get_by_kind USING lt_x031l-exid
                                  lv_length
                                  lv_decims
                            CHANGING lt_compo-type.
        APPEND lt_compo.
      ENDLOOP.
      lo_tabdes = cl_abap_tabledescr=>get( p_line_type = cl_abap_structdescr=>get( p_components = lt_compo[] ) ).
     
     
      CREATE DATA lr_data TYPE HANDLE lo_tabdes.
      ASSIGN lr_data->* TO <lt_src>.
     
     
      CREATE DATA lr_data TYPE STANDARD TABLE OF (pv_totab).
      ASSIGN lr_data->* TO <lt_dst>.
      CREATE DATA lr_data LIKE LINE OF <lt_dst>.
      ASSIGN lr_data->* TO <ls_dst>.
     
     
      IF p_trunc = 'X'.
        lv_ddlstr = `truncate table ` && p_totab.
        PERFORM exec_ddl USING lv_ddlstr.
      ENDIF.
     
     
      OPEN CURSOR WITH HOLD lv_cursor FOR
          SELECT (lt_fields) FROM (pv_frtab)
            CLIENT SPECIFIED BYPASSING BUFFER
            WHERE (p_where).
      DO.
        FETCH NEXT CURSOR lv_cursor INTO TABLE <lt_src> PACKAGE SIZE 10000.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
        lv_dbcntr = sy-dbcnt.
     
     
        CLEAR <lt_dst>.
        LOOP AT <lt_src> ASSIGNING <ls_src>.
          TRY.
              MOVE-CORRESPONDING <ls_src> TO <ls_dst>.
            CATCH cx_root.
          ENDTRY.
          APPEND <ls_dst> TO <lt_dst>.
        ENDLOOP.
     
     
        INSERT (pv_totab) CLIENT SPECIFIED
            FROM TABLE <lt_dst> ACCEPTING DUPLICATE KEYS.
        lv_dbcntw = lv_dbcntw + sy-dbcnt.
        CALL FUNCTION 'DB_COMMIT'.
        MESSAGE s000(oo) WITH '累计读出条数:' lv_dbcntr ' 累计写入条数:' lv_dbcntw.
      ENDDO.
      CLOSE CURSOR lv_cursor.
      CALL FUNCTION 'DB_COMMIT'.
    ENDFORM.                    "copy_data
     
     
    *&---------------------------------------------------------------------*
    *& 备份表
    *&---------------------------------------------------------------------*
    FORM back_table.
      DATA: lv_ddlstr TYPE string.
     
     
      IF p_frtab IS INITIAL.
        MESSAGE s000(oo) WITH '请输入源表'.
      ELSE.
        IF p_totab IS INITIAL.
          p_totab = p_frtab && '_' && sy-datum && sy-uzeit.
        ENDIF.
     
     
        IF p_where IS INITIAL.
          IF sy-dbsys = 'ORACLE'.
            lv_ddlstr = `CREATE TABLE ` && p_totab &&
                        ` AS SELECT * FROM ` && p_frtab.
          ELSEIF sy-dbsys = 'HDB'.
            lv_ddlstr = `CREATE COLUMN TABLE ` && p_totab &&
                        ` LIKE ` && p_frtab && ` WITH DATA;`.
          ELSE.
            MESSAGE s000(oo) WITH '不支持的数据库'.
          ENDIF.
        ELSE.
          IF sy-dbsys = 'ORACLE'.
            lv_ddlstr = `CREATE TABLE ` && p_totab &&
                        ` AS SELECT * FROM ` && p_frtab && ` WHERE ` && p_where.
          ELSEIF sy-dbsys = 'HDB'.
            lv_ddlstr = `CREATE COLUMN TABLE ` && p_totab &&
                        ` AS (SELECT * FROM ` && p_frtab && ` WHERE ` && p_where && `);`.
          ELSE.
            MESSAGE s000(oo) WITH '不支持的数据库'.
          ENDIF.
        ENDIF.
        PERFORM exec_ddl USING lv_ddlstr.
        CHECK sy-subrc = 0.
        MESSAGE s000(oo) WITH '已备份到表:' p_totab.
      ENDIF.
    ENDFORM.                    " BACK_TABLE
     
     
    *&---------------------------------------------------------------------*
    *& 查看表数据
    *&---------------------------------------------------------------------*
    FORM view_data.
      DATA: lv_sql TYPE string.
     
     
      IF p_tanam IS INITIAL.
        MESSAGE s000(oo) WITH '请输入表名'.
      ELSE.
        IF p_where IS INITIAL.
          p_where = ' 1 = 1'.
        ENDIF.
        lv_sql = `select * from ` && p_tanam && ` where ` && p_where.
      ENDIF.
      PERFORM exec_select USING lv_sql p_uprow.
    ENDFORM.                    "view_data
     
     
    *&---------------------------------------------------------------------*
    *& 查找表
    *&---------------------------------------------------------------------*
    FORM find_table.
      DATA: lv_sql TYPE string.
     
     
      IF p_tanam IS INITIAL.
        MESSAGE s000(oo) WITH '请输入表名,支持星号通配符'.
      ELSE.
        TRANSLATE p_tanam USING '*%'.
        IF sy-dbsys = 'HDB'. "HANA
          lv_sql = `select * from m_tables ` &&
                   `where table_name like '` && p_tanam && `'`.
        ELSEIF sy-dbsys = 'ORACLE'.
          lv_sql = `select * from user_tables ` &&
                   `where table_name like '` && p_tanam && `'`.
        ELSE.
          MESSAGE s000(oo) WITH '本功能只支持HANA和Oracle'.
          RETURN.
        ENDIF.
        PERFORM exec_select USING lv_sql p_uprow.
      ENDIF.
    ENDFORM.                    "find_table
     
     
    *&---------------------------------------------------------------------*
    *& ADBC执行SELECT语句并ALV显示
    *&---------------------------------------------------------------------*
    FORM exec_select USING pv_sql pv_rows.
      DATA: lo_connt    TYPE REF TO cl_sql_connection,
            lo_query    TYPE REF TO cl_sql_statement,
            lo_rslt_set TYPE REF TO cl_sql_result_set,
            lr_result   TYPE REF TO data,
            lo_studes   TYPE REF TO cl_abap_structdescr,
            lo_tabdes   TYPE REF TO cl_abap_tabledescr,
            lt_mete_des TYPE adbc_rs_metadata_descr_tab,
            ls_mete_des TYPE adbc_rs_metadata_descr,
            lr_meta     TYPE REF TO data,
            lx_err      TYPE REF TO cx_sql_exception,
            lv_err      TYPE char200.
      DATA: ls_fldcat TYPE lvc_s_fcat,
            lt_fldcat TYPE lvc_t_fcat.
      FIELD-SYMBOLS <lt_result> TYPE STANDARD TABLE.
     
     
      CREATE OBJECT lo_connt.
      lo_query = lo_connt->create_statement( ).
      TRY.
          lo_rslt_set = lo_query->execute_query( pv_sql ).
          lt_mete_des = lo_rslt_set->get_metadata( ).
          LOOP AT lt_mete_des INTO ls_mete_des.
            ls_fldcat-fieldname = ls_mete_des-column_name.
            ls_fldcat-scrtext_l = ls_mete_des-column_name.
            ls_fldcat-coltext   = ls_mete_des-column_name.
            ls_fldcat-ref_table = 'RSREF'.
            ls_fldcat-ref_field = 'STRING'.
            ls_fldcat-col_opt   = 'A'.
            APPEND ls_fldcat TO lt_fldcat.
          ENDLOOP.
     
     
          lr_meta = lo_rslt_set->get_struct_ref( md_tab   = lt_mete_des
                                                 p_strict = '' ).
          lo_studes ?= cl_abap_typedescr=>describe_by_data_ref( lr_meta ).
          lo_tabdes = cl_abap_tabledescr=>create( p_line_type  = lo_studes
                                                  p_table_kind = 'S' ).
          CREATE DATA lr_result TYPE HANDLE lo_tabdes.
          ASSIGN lr_result->* TO <lt_result>.
     
     
          lo_rslt_set->set_param_table( itab_ref = lr_result ).
          IF pv_rows IS INITIAL.
            lo_rslt_set->next_package( ).
          ELSE.
            lo_rslt_set->next_package( EXPORTING upto = pv_rows ).
          ENDIF.
          lo_rslt_set->close( ).
        CATCH cx_sql_exception INTO lx_err.
          lv_err = lx_err->sql_message.
          sy-subrc = 8.
          MESSAGE e000(oo) WITH lv_err(50) lv_err+50(50) lv_err+100(50)
                                lv_err+150(50).
      ENDTRY.
     
     
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          it_fieldcat_lvc = lt_fldcat
        TABLES
          t_outtab        = <lt_result>.
    ENDFORM.                    "exec_select
     
     
    *&---------------------------------------------------------------------*
    *& confirm
    *&---------------------------------------------------------------------*
    FORM confirm.
      DATA lv_rcode TYPE c.
     
     
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          titlebar       = '确认'
          text_question  = '危险!可能导致数据丢失,是否继续?'
          default_button = '2'
        IMPORTING
          answer         = lv_rcode.
      IF lv_rcode = '1'.
        sy-subrc = 0.
      ELSE.
        sy-subrc = 4.
      ENDIF.
    ENDFORM.
     
     
    *&---------------------------------------------------------------------*
    *& get_by_kind
    *&---------------------------------------------------------------------*
    FORM get_by_kind USING p_type_kind TYPE abap_typekind
                           p_length    TYPE i
                           p_decimals  TYPE i
                     CHANGING p_result TYPE REF TO cl_abap_datadescr.
     
     
      CASE p_type_kind.
        WHEN cl_abap_typedescr=>typekind_char.
          p_result = cl_abap_elemdescr=>get_c( p_length = p_length ).
        WHEN cl_abap_typedescr=>typekind_num.
          p_result = cl_abap_elemdescr=>get_n( p_length = p_length ).
        WHEN cl_abap_typedescr=>typekind_hex.
          p_result = cl_abap_elemdescr=>get_x( p_length = p_length ).
        WHEN cl_abap_typedescr=>typekind_packed.
          p_result = cl_abap_elemdescr=>get_p( p_length = p_length p_decimals = p_decimals ).
        WHEN cl_abap_typedescr=>typekind_date.
          p_result = cl_abap_elemdescr=>get_d( ).
        WHEN cl_abap_typedescr=>typekind_time.
          p_result = cl_abap_elemdescr=>get_t( ).
        WHEN cl_abap_typedescr=>typekind_int  OR
             cl_abap_typedescr=>typekind_int1 OR
             cl_abap_typedescr=>typekind_int2.
          p_result = cl_abap_elemdescr=>get_i( ).
        WHEN cl_abap_typedescr=>typekind_float.
          p_result = cl_abap_elemdescr=>get_f( ).
        WHEN cl_abap_typedescr=>typekind_decfloat16.
          p_result = cl_abap_elemdescr=>get_decfloat16( ).
        WHEN cl_abap_typedescr=>typekind_decfloat34.
          p_result = cl_abap_elemdescr=>get_decfloat34( ).
        WHEN cl_abap_typedescr=>typekind_string.
          p_result = cl_abap_elemdescr=>get_string( ).
        WHEN cl_abap_typedescr=>typekind_xstring.
          p_result = cl_abap_elemdescr=>get_xstring( ).
        WHEN OTHERS.
          MESSAGE e000(oo) WITH '不支持的类型' p_type_kind.
      ENDCASE.
    ENDFORM.                    "get_by_kind
     
     
    *&---------------------------------------------------------------------*
    *&      Form  submitjob
    *&---------------------------------------------------------------------*
    FORM submitjob.
      DATA: lv_jobnam TYPE tbtcjob-jobname,
            lv_jobnum TYPE tbtcjob-jobcount,
            lt_params TYPE TABLE OF rsparamsl_255.
     
     
      lv_jobnam = sy-cprog.
      CALL FUNCTION 'JOB_OPEN'
        EXPORTING
          jobname          = lv_jobnam
        IMPORTING
          jobcount         = lv_jobnum
        EXCEPTIONS
          cant_create_job  = 01
          invalid_job_data = 02
          jobname_missing  = 03
          OTHERS           = 99.
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
     
     
      CALL FUNCTION 'RS_REFRESH_FROSELECTION_TABLE_255M_SELECTOPTIONS'
        EXPORTING
          curr_report         = sy-cprog
        TABLES
          selection_table_255 = lt_params
        EXCEPTIONS
          not_found           = 1
          no_report           = 2
          OTHERS              = 3.
      IF sy-subrc NE 0.
        MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
     
     
      SUBMIT (sy-cprog)
          WITH SELECTION-TABLE lt_params
          VIA JOB lv_jobnam NUMBER  lv_jobnum
          AND RETURN.
      IF sy-subrc = 0.
        CALL FUNCTION 'JOB_CLOSE'
          EXPORTING
            jobcount  = lv_jobnum
            jobname   = lv_jobnam
            strtimmed = 'X'
          EXCEPTIONS
            OTHERS    = 8.
        IF sy-subrc NE 0.
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ELSE.
          MESSAGE s000(oo) WITH 'JOB名:' lv_jobnam 'JOB Number:' lv_jobnum.
        ENDIF.
      ENDIF.
    ENDFORM.                    "submitjob

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值