ABAP 表数据维护程序(类似SM30或者SE16N)

中午正在午休 业务大哥跟我说外围系统接口数据传过来错了,我说那直接生产机SE16N改吧 通过函数或者debug权限改,不行啊 生产机这种权限都没有啊。 大哥几张表啊,业务大概说15张表 当时无语,写程序吧。得多久啊 别领导发现数据错误在加上中午我又喝酒 就完蛋了  你帮帮我我请你喝酒。实在没办法我写一个批量修改程序吧 写完分享一兄弟门。如下:

很牛逼的工具上源代码:

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

***********************************************************************
REPORT yxmme004_new  NO STANDARD PAGE HEADING   " LINE-COUNT 0(4)
                MESSAGE-ID  yxa_mm
                LINE-SIZE  128
                LINE-COUNT 33.



INCLUDE yxmme004_new_top.
INCLUDE yxmme004_new_sel.
INCLUDE yxmme004_new_frm.


AT SELECTION-SCREEN OUTPUT.

*&---------------------------------------------------------------------*
*& 包含               YXMME004_NEW_TOP
*&---------------------------------------------------------------------*



DATA:"gt_migolog TYPE STANDARD TABLE OF ts_migolog,
     gt_fcat    TYPE lvc_t_fcat,
     gs_layout  TYPE lvc_s_layo.

DATA:gv_tabname TYPE tabname.
DATA:gt_table_fields  TYPE TABLE OF dfies,
     gt_where_clauses TYPE rsds_twhere.
DATA:gt_tables_tab TYPE STANDARD TABLE OF rsdstabs,
     gt_fields_tab TYPE STANDARD TABLE OF rsdsfields.
DATA:gt_sorted_field TYPE abap_sortorder_tab.
FIELD-SYMBOLS:<gt_table> TYPE STANDARD TABLE,
              <gs_row>   TYPE any.




DATA:"gt_migolog TYPE STANDARD TABLE OF ts_migolog,
     gt_fcat2    TYPE lvc_t_fcat.

FIELD-SYMBOLS:<gt_table2> TYPE STANDARD TABLE.

*&---------------------------------------------------------------------*
*& 包含               YXMME004_NEW_SEL
*&---------------------------------------------------------------------*


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

  PARAMETERS: p_cg RADIOBUTTON GROUP rg1  USER-COMMAND u1 DEFAULT 'X',
              p_mg RADIOBUTTON GROUP rg1,
              p_hx RADIOBUTTON GROUP rg1,
              p_lf RADIOBUTTON GROUP rg1, "
              p_jg RADIOBUTTON GROUP rg1,
              p_rd RADIOBUTTON GROUP rg1,
              p_jc RADIOBUTTON GROUP rg1,
              p_id RADIOBUTTON GROUP rg1,
              p_pr RADIOBUTTON GROUP rg1,
              p_mi RADIOBUTTON GROUP rg1,
              p_zx RADIOBUTTON GROUP rg1,
              p_zc RADIOBUTTON GROUP rg1,
              p_rq RADIOBUTTON GROUP rg1,
              p_qh RADIOBUTTON GROUP rg1,
              p_qi RADIOBUTTON GROUP rg1,
              p_so RADIOBUTTON GROUP rg1,
              p_od RADIOBUTTON GROUP rg1,
              p_wj RADIOBUTTON GROUP rg1,
              p_dd RADIOBUTTON GROUP rg1,
              p_go RADIOBUTTON GROUP rg1.

SELECTION-SCREEN END OF BLOCK block1.

*&---------------------------------------------------------------------*
*& 包含               YXMME004_NEW_FRM
*&---------------------------------------------------------------------*


FORM frm_table_determine.
  CASE 'X'.
    WHEN p_cg.
      gv_tabname = 'YTMM_CGDD'.
    WHEN p_mg.
      gv_tabname = 'YTMM_ZCMIGO_LOG'.
    WHEN p_hx.
      gv_tabname = 'YTMM080'.
    WHEN p_lf.
      gv_tabname = 'YTMM_ZCPR'.
    WHEN p_jg.
      gv_tabname = 'YTMM_PRICE_LOG'.
  ENDCASE.

  REFRESH:gt_table_fields.
  CALL FUNCTION 'DDIF_FIELDINFO_GET'
    EXPORTING
      tabname        = gv_tabname
      langu          = sy-langu
    TABLES
      dfies_tab      = gt_table_fields
    EXCEPTIONS
      not_found      = 1
      internal_error = 2
      OTHERS         = 3.
  IF sy-subrc <> 0.
    MESSAGE 'Failed to get table fields' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  DELETE gt_table_fields WHERE fieldname EQ 'MANDT'. "remove client field
ENDFORM.

FORM frm_get_dynamic_where_clause.
  DATA:lv_selection_id TYPE rsdynsel-selid.

  REFRESH:gt_where_clauses,gt_tables_tab,gt_fields_tab,gt_sorted_field.

  gt_tables_tab = VALUE #( ( prim_tab = gv_tabname ) ).

  "Preselect all key fields by default
  gt_fields_tab = VALUE #( FOR ls_fields IN gt_table_fields
                           WHERE ( keyflag EQ 'X' )
                         ( tablename = gv_tabname fieldname = ls_fields-fieldname ) ).

  gt_sorted_field = VALUE #( FOR ls_fields IN gt_table_fields
                           WHERE ( keyflag EQ 'X' )
                           ( name = ls_fields-fieldname ) ).

  PERFORM frm_preselect_otherfields TABLES gt_fields_tab USING gv_tabname.

  CALL FUNCTION 'FREE_SELECTIONS_INIT'
    EXPORTING
      kind         = 'T'
    IMPORTING
      selection_id = lv_selection_id
    TABLES
      tables_tab   = gt_tables_tab
      fields_tab   = gt_fields_tab
    EXCEPTIONS
      OTHERS       = 20.

  IF sy-subrc EQ 0.
    CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
      EXPORTING
        selection_id    = lv_selection_id
        title           = '选择'
        frame_text      = '查询条件'
        as_window       = ''
      IMPORTING
        where_clauses   = gt_where_clauses
      TABLES
        fields_tab      = gt_fields_tab
      EXCEPTIONS
        internal_error  = 1
        no_action       = 2
        selid_not_found = 3
        illegal_status  = 4
        OTHERS          = 5.
    IF sy-subrc NE 0.
      LEAVE LIST-PROCESSING.
    ENDIF.
  ENDIF.
ENDFORM.

FORM frm_preselect_otherfields TABLES pt_fields LIKE gt_fields_tab USING p_tabname. "非Key字段预选
  CASE p_tabname.
    WHEN 'YTMM_CGDD'.
      APPEND VALUE #( tablename = p_tabname fieldname = 'ZEBELN_M' )  TO pt_fields.
      APPEND VALUE #( tablename = p_tabname fieldname = 'ZFLAG' )  TO pt_fields.
    WHEN 'YTMM_ZCMIGO_LOG'.

  ENDCASE.
ENDFORM.

FORM frm_get_generic_data.
  DATA:ls_where TYPE rsds_where.
  DATA:dref     TYPE REF TO data.
  DATA:dref2     TYPE REF TO data.

  FREE dref.
  UNASSIGN <gt_table>.

  READ TABLE gt_where_clauses INTO ls_where WITH KEY tablename = gv_tabname. "#EC CI_SUBRC

  CREATE DATA dref TYPE TABLE OF (gv_tabname).
  ASSIGN dref->* TO <gt_table>.

  UNASSIGN <gt_table2>.
  CREATE DATA dref2 TYPE TABLE OF (gv_tabname).
  ASSIGN dref2->* TO <gt_table2>.

  TRY.
      SELECT * INTO TABLE <gt_table>
        FROM (gv_tabname)
       WHERE (ls_where-where_tab).

      SORT <gt_table> BY (gt_sorted_field). "Sort by key fields

    CATCH cx_sy_dynamic_osql_error.
      MESSAGE 'Error in dynamic Open SQL' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
  ENDTRY.
ENDFORM.

FORM frm_display_alv_new.
  DATA: lv_repid      TYPE sy-repid.

  REFRESH:gt_fcat.

  gt_fcat = VALUE #( FOR ls_field IN gt_table_fields
                     ( fieldname = ls_field-fieldname
                       ref_field = ls_field-fieldname
                       ref_table = ls_field-tabname
                       edit      = COND #( WHEN ls_field-keyflag NE 'X' THEN 'X' ELSE '' )
                      ) ).

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program       = sy-repid
      is_layout_lvc            = VALUE lvc_s_layo( cwidth_opt = 'X' zebra = 'X' sel_mode = 'B' )
      i_callback_pf_status_set = 'FRM_PF_STATUS_N'
      i_callback_user_command  = 'FRM_USER_COMMAND_NEW'
      it_fieldcat_lvc          = gt_fcat
    TABLES
      t_outtab                 = <gt_table>
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
ENDFORM.

FORM frm_pf_status_n USING extab TYPE slis_t_extab.
  DATA: lt_fcode TYPE TABLE OF sy-ucomm,
        ls_fcode TYPE sy-ucomm.
  CLEAR:lt_fcode[].

  SET PF-STATUS 'STANDARD'.
ENDFORM.

FORM frm_user_command_new USING r_ucomm      LIKE sy-ucomm
                            rs_selfield  TYPE slis_selfield.

  DATA:lr_grid TYPE REF TO cl_gui_alv_grid,
       lt_rows TYPE lvc_t_row,
       ls_row  TYPE lvc_s_row,
       lv_answ TYPE c.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.

  CALL METHOD lr_grid->get_selected_rows
    IMPORTING
      et_index_rows = lt_rows.

  CASE r_ucomm.
    WHEN '&UPDA'.
      IF lt_rows[] IS INITIAL.
        MESSAGE TEXT-m03 TYPE 'E'.
      ENDIF.

      CALL METHOD lr_grid->check_changed_data.

      LOOP AT lt_rows INTO ls_row.
        READ TABLE <gt_table> ASSIGNING <gs_row> INDEX ls_row-index.
        CHECK sy-subrc EQ 0.

        MODIFY (gv_tabname) FROM <gs_row>.          "#EC CI_IMUD_NESTED
        IF sy-subrc EQ 0.
          COMMIT WORK.
        ENDIF.
      ENDLOOP.

      rs_selfield-refresh = 'X'.
    WHEN '&DELE'.
      IF lt_rows[] IS INITIAL.
        MESSAGE TEXT-m03 TYPE 'E'.
      ENDIF.

      PERFORM frm_confirm USING lv_answ. "删除确认
      CHECK lv_answ EQ abap_true.

      SORT lt_rows BY index DESCENDING.

      LOOP AT lt_rows INTO ls_row.
        READ TABLE <gt_table> ASSIGNING <gs_row> INDEX ls_row-index.
        CHECK sy-subrc EQ 0.

        DELETE (gv_tabname) FROM <gs_row>.          "#EC CI_IMUD_NESTED
        IF sy-subrc EQ 0.
          COMMIT WORK.
          DELETE <gt_table> INDEX ls_row-index. "delete internal table row
        ENDIF.
      ENDLOOP.

      rs_selfield-refresh = 'X'.
    WHEN 'ZINSERT'.
      REFRESH <gt_table2>.

*      IF lt_rows[] IS INITIAL.
*        MESSAGE TEXT-m04 TYPE 'E'.
*      ENDIF.

      PERFORM frm_confirm2 USING lv_answ. "删除确认

      CHECK lv_answ EQ abap_true.

      LOOP AT lt_rows INTO ls_row.
        READ TABLE <gt_table> ASSIGNING <gs_row> INDEX ls_row-index.
        CHECK sy-subrc EQ 0.

        APPEND <gs_row> TO <gt_table2>.
      ENDLOOP.
      IF sy-subrc NE 0.
        APPEND INITIAL LINE TO <gt_table2> ASSIGNING FIELD-SYMBOL(<fs_row2>)." ASSIGNING <gs_row>.
      ENDIF.

      PERFORM rm_add_data .


*
*
*      APPEND INITIAL LINE TO <gt_table> ASSIGNING <gs_row>.
**      INSERT INITIAL LINE INTO <gt_table> ASSIGNING <gs_row>.
      rs_selfield-refresh = 'X'.
  ENDCASE.
ENDFORM.

FORM frm_confirm USING p_ret.
  DATA:lv_answer TYPE c.
  CLEAR:p_ret,lv_answer.

  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      titlebar              = '确定删除'
      text_question         = '确定删除所选行'
      text_button_1         = '确定删除'
      text_button_2         = '取消'
      default_button        = '1'
      display_cancel_button = ''
      start_column          = 25
      start_row             = 6
    IMPORTING
      answer                = lv_answer
    EXCEPTIONS
      text_not_found        = 1
      OTHERS                = 2.
  IF sy-subrc EQ 0 AND lv_answer EQ '1'.
    p_ret = abap_true.
  ENDIF.
ENDFORM.
FORM frm_confirm2 USING p_ret.
  DATA:lv_answer TYPE c.
  CLEAR:p_ret,lv_answer.

  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
      titlebar              = '确定新增'
      text_question         = '确定新增一行'
      text_button_1         = '确定新增'
      text_button_2         = '取消'
      default_button        = '1'
      display_cancel_button = ''
      start_column          = 25
      start_row             = 6
    IMPORTING
      answer                = lv_answer
    EXCEPTIONS
      text_not_found        = 1
      OTHERS                = 2.
  IF sy-subrc EQ 0 AND lv_answer EQ '1'.
    p_ret = abap_true.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form RM_ADD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM rm_add_data .
  REFRESH gt_fcat2.
  gt_fcat2[] = gt_fcat[].

  LOOP AT gt_fcat2 ASSIGNING FIELD-SYMBOL(<fs_fcat>).
    <fs_fcat>-edit = 'X'.
  ENDLOOP.

*  IF sy-uname NE 'E_QIJUN'.
*    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
*      EXPORTING
*        i_grid_title             = '新增数据'
*        i_callback_program       = sy-repid
*        is_layout_lvc            = VALUE lvc_s_layo( cwidth_opt = 'X' zebra = 'X' sel_mode = 'B' )
*        i_callback_pf_status_set = 'FRM_PF_STATUS_N2'
*        i_callback_user_command  = 'FRM_USER_COMMAND_NEW2'
*        it_fieldcat_lvc          = gt_fcat2
*      TABLES
*        t_outtab                 = <gt_table2>
*      EXCEPTIONS
*        program_error            = 1
*        OTHERS                   = 2.
*  ELSE.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_grid_title             = '新增数据'
      i_callback_program       = sy-repid
      is_layout_lvc            = VALUE lvc_s_layo( cwidth_opt = 'X' zebra = 'X' sel_mode = 'B' )
      i_callback_pf_status_set = 'FRM_PF_STATUS_N2'
      i_callback_user_command  = 'FRM_USER_COMMAND_NEW2'
      i_screen_start_column    = 3
      i_screen_start_line      = 3
      i_screen_end_column      = 110
      i_screen_end_line        = 20
      it_fieldcat_lvc          = gt_fcat2
    TABLES
      t_outtab                 = <gt_table2>
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
*  ENDIF.

ENDFORM.
FORM frm_pf_status_n2 USING extab TYPE slis_t_extab.
  DATA: lt_fcode TYPE TABLE OF sy-ucomm,
        ls_fcode TYPE sy-ucomm.
  CLEAR:lt_fcode[].

  SET PF-STATUS 'STANDARD_ADD'.
ENDFORM.

FORM frm_user_command_new2 USING r_ucomm      LIKE sy-ucomm
                            rs_selfield  TYPE slis_selfield.

  DATA:lr_grid TYPE REF TO cl_gui_alv_grid,
       lt_rows TYPE lvc_t_row,
       ls_row  TYPE lvc_s_row,
       lv_answ TYPE c.

  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.

  CALL METHOD lr_grid->get_selected_rows
    IMPORTING
      et_index_rows = lt_rows.



  CASE r_ucomm.
    WHEN 'ZSAVE'.
      CALL METHOD lr_grid->check_changed_data.

      APPEND LINES OF <gt_table2> TO <gt_table>.

      LEAVE TO SCREEN 0.
*      rs_selfield-refresh = 'X'.
    WHEN 'ZDEL'.
      IF lt_rows[] IS INITIAL.
        MESSAGE TEXT-m03 TYPE 'E'.
      ENDIF.

      PERFORM frm_confirm USING lv_answ. "删除确认
      CHECK lv_answ EQ abap_true.

      SORT lt_rows BY index DESCENDING.

      LOOP AT lt_rows INTO ls_row.
        READ TABLE <gt_table2> ASSIGNING <gs_row> INDEX ls_row-index.
        CHECK sy-subrc EQ 0.
        DELETE <gt_table2> INDEX ls_row-index. "delete internal table row

      ENDLOOP.

      rs_selfield-refresh = 'X'.
    WHEN 'ZADD'.

      APPEND INITIAL LINE TO <gt_table2>.

      rs_selfield-refresh = 'X'.
  ENDCASE.
ENDFORM.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值