alv展示数据时,有时需要全选或取消全选,对数据进行操作,一般的做法,在内表中给标志列赋值,但是,如果根据条件过滤数据后,全选或取消全选时,会影响到所有数据(不仅仅过滤后的数据),以下是解决方法:
*———————————————————————*
* FORM USER_COMMAND *
*———————————————————————*
FORM user_command USING rf_ucomm LIKE sy–ucomm
rs TYPE slis_selfield . “#EC CALLED
DATA: wl_answer TYPE c.
DATA: lr_grid TYPE REF TO cl_gui_alv_grid.
DATA : et_filtered TYPE lvc_t_fidx.
DATA:lv_tabix TYPE sy–tabix.
CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
IMPORTING
e_grid = lr_grid.
CALL METHOD lr_grid->check_changed_data.
DATA:p_count TYPE i.
rs–refresh = ‘X’. “自动刷新
CLEAR : et_filtered.
CALL METHOD lr_grid->get_filtered_entries
IMPORTING
et_filtered_entries = et_filtered.
CASE rf_ucomm.
WHEN ‘&SALL’.
LOOP AT result.
lv_tabix = sy–tabix.
READ TABLE et_filtered WITH KEY table_line = lv_tabix TRANSPORTING NO FIELDS.
IF sy–subrc NE 0.
result–chk = ‘X’.
MODIFY result.
CLEAR result.
ENDIF.
ENDLOOP.
WHEN ‘&SCLL’.
LOOP AT result.
lv_tabix = sy–tabix.
READ TABLE et_filtered WITH KEY table_line = lv_tabix TRANSPORTING NO FIELDS.
IF sy–subrc NE 0.
result–chk = ”.
MODIFY result.
CLEAR result.
ENDIF.
ENDLOOP.
WHEN ‘&FX11’.
CLEAR wl_answer.
CALL FUNCTION ‘POPUP_TO_CONFIRM’
EXPORTING
text_question = ‘确定要删除所选信息吗?’ “确定要删除吗?
icon_button_1 = ‘是’ “text-035 “是
icon_button_2 = ‘否’ “text-036 “否
default_button = ‘2’
display_cancel_button = ”
start_column = 25
start_row = 6
IMPORTING
answer = wl_answer
EXCEPTIONS
text_not_found = 1
OTHERS = 2.
IF wl_answer = ‘1’.
CLEAR p_count.
LOOP AT result WHERE chk = ‘X’.
p_count = p_count + 1.
ENDLOOP.
IF p_count <= 0.
MESSAGE ‘请选择要删除的数据!’ TYPE ‘E’.
STOP.
ENDIF.
PERFORM frm_del.
ENDIF.
ENDCASE.
rs–refresh = ‘X’.
ENDFORM. ” USER_COMMAND
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/20134.html