ABAP OOALV中实现可编辑,并校验输入内容

OOALV中实现可编辑,并校验输入内容

    • 1.CLASS中声明change方法
    • 2.实现该change方法
    • 3.获取修改内容并校验
    • 4. 校验完自动刷新alv

1.CLASS中声明change方法

代码如下:

CLASS gcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    METHODS handle_data_changed
                 FOR EVENT data_changed OF cl_gui_alv_grid
     			 IMPORTING er_data_changed.
ENDCLASS.

2.实现该change方法

先修改,再刷新alv
代码如下:

CLASS gcl_event_receiver IMPLEMENTATION.
  METHOD handle_data_changed.
    CLEAR gv_stop.
    PERFORM frm_data_changed USING er_data_changed.		
    PERFORM frm_refresh_alv USING gcl_alvgrid.
  ENDMETHOD.                   

ENDCLASS.

3.获取修改内容并校验

FORM frm_data_changed  USING uo_data_changed TYPE REF TO cl_alv_changed_data_protocol.
  LOOP AT uo_data_changed->mt_mod_cells ASSIGNING FIELD-SYMBOL().
    CASE -fieldname.
      WHEN 'ZQXFZ'."判断修改的是哪个字段
        CHECK -value IS NOT INITIAL.
        TRANSLATE -value TO UPPER CASE.
        CONDENSE -value NO-GAPS.
        READ TABLE gt_tab ASSIGNING FIELD-SYMBOL() INDEX -row_id.
        IF sy-subrc = 0.
          LOOP AT gt_tab TRANSPORTING NO FIELDS WHERE zqxfz = -value.
          "下面的方法用来填写message
            CALL METHOD uo_data_changed->add_protocol_entry
              EXPORTING
                i_msgid     = 'OO'
                i_msgty     = 'E'
                i_msgno     = '000'
                i_msgv1     = '权限重复'
                i_fieldname = -fieldname
                i_row_id    = -row_id
                i_tabix     = -tabix.

            -zqxfz = -value.
            gv_stop = abap_true.
            RETURN.
          ENDLOOP.
          SELECT zqxms INTO -zqxms FROM zyktssf0200 WHERE zqxfz = -value.ENDSELECT.
        ENDIF.


      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.
ENDFORM.

4. 校验完自动刷新alv

FORM frm_refresh_alv  USING icl_alvgrid TYPE REF TO cl_gui_alv_grid.
  DATA: ls_stbl TYPE lvc_s_stbl,
        lr_grid TYPE REF TO cl_gui_alv_grid..
  "稳定刷新
  ls_stbl-row = abap_true.  "基于行的稳定刷新
  ls_stbl-col = abap_true.  "基于列稳定刷新
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'       "得到当前屏幕上的ALV的句柄
    IMPORTING
      e_grid = lr_grid.

  CALL METHOD lr_grid->refresh_table_display
    EXPORTING
      is_stable = ls_stbl.
ENDFORM.

你可能感兴趣的:(abap,sap,erp,后端)