在 ALV 报表中使用 CL_SALV 类时,如何处理多行?
举个例子: 我设置了显示 “全选按钮”。
需要选择几行,在这种情况下,已经选择了 2 行,并使用这 2 行执行了一个调用事务。但还有其他事情要做,因为 ALV 报告中的所有行都执行了调用事务。
我找到了以下内容:
layout-box_fname = “字段名”。
layout-sel_mode = 'A'。
但这种功能要在 CL_GUI_ALV_GRID
中使用。
在 CL_SALV
类中,也可以设置选择模式:
lo_selections = lo_salv->get_selections( ).
* set selection mode
lo_selections->set_selection_mode( if_salv_c_selection_mode=>row_column ). " 支持行列选择
然后在对应的行进行选中,支持获取选中的行做处理:
DATA: lt_rows TYPE salv_t_row,
ls_rows TYPE i.
DATA: lo_selections TYPE REF TO cl_salv_selections
lo_selections = lo_salv->get_selections( ).
lt_rows = lo_selections->get_selected_rows( ).
IF lt_rows IS INITIAL.
MESSAGE '请选中行再进行保存' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
FIELD-SYMBOLS: <fs_out> TYPE LINE OF lo_report->gt_out.
LOOP AT lt_rows INTO ls_rows.
READ TABLE lo_report->gt_out ASSIGNING <fs_out> INDEX ls_rows.
IF sy-subrc = 0.
" 你的选择逻辑
ENDIF.
ENDLOOP.
也可以看官方 Demo 报表:SALV_TEST_TABLE_SELECTIONS
,在 FORM form get_selections
中有类似的逻辑。
*&---------------------------------------------------------------------*
*& Form get_selections
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form get_selections .
data: lr_selections type ref to cl_salv_selections.
data: lt_rows type salv_t_row,
lt_cols type salv_t_column,
ls_cell type salv_s_cell.
data: l_row type i,
l_col type lvc_fname,
l_row_string type char128,
l_col_string type char128,
l_row_info type char128,
l_col_info type char128.
lr_selections = gr_table->get_selections( ).
lt_rows = lr_selections->get_selected_rows( ).
lt_cols = lr_selections->get_selected_columns( ).
ls_cell = lr_selections->get_current_cell( ).
*... 行
clear l_row_info.
loop at lt_rows into l_row.
write l_row to l_row_string left-justified.
concatenate l_row_info l_row_string into l_row_info separated by space.
endloop.
if sy-subrc eq 0.
message i000(0k) with text-i02 l_row_info.
endif.
*... 列
clear l_col_info.
loop at lt_cols into l_col.
write l_col to l_col_string left-justified.
concatenate l_col_info l_col_string into l_col_info separated by space.
endloop.
if sy-subrc eq 0.
message i000(0k) with text-i03 l_col_info.
endif.
*... 单元格
if ls_cell is not initial.
message i000(0k) with text-i02 ls_cell-row text-i03 ls_cell-columnname.
endif.
endform. " get_selections
原文地址:https://blog.csdn.net/SAP_yu/article/details/143712587
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!