*&---------------------------------------------------------------------*
*& Report ZJAMES002
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z1.
TABLES: usr21,adrp.
TYPES: BEGIN OF ty_1,
sel(1) TYPE c,
bname TYPE xubname,
name_first TYPE ad_namefir,
name_last TYPE ad_namelas,
name_text TYPE ad_namtext,
checkbox(1) TYPE c,
END OF ty_1.
DATA gs_user TYPE ty_1.
DATA gt_user TYPE TABLE OF ty_1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS:
r_bname FOR usr21-bname ,
r_name_f FOR adrp-name_first,
r_name_l FOR adrp-name_last ,
r_name_t FOR adrp-name_text.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION.
START-OF-SELECTION.
PERFORM get_data.
END-OF-SELECTION.
PERFORM show_data.
*---------------------------------------------------------------------
* Form GET_DATA
*---------------------------------------------------------------------
FORM get_data .
SELECT t0~bname t1~name_first t1~name_last t1~name_text
INTO TABLE gt_user
FROM usr21 AS t0 INNER JOIN adrp AS t1
ON t0~persnumber = t1~persnumber
WHERE bname IN r_bname AND
name_first IN r_name_f AND
name_last IN r_name_l AND
name_text IN r_name_t.
ENDFORM.
*---------------------------------------------------------------------
* Form SHOW_DATA
*---------------------------------------------------------------------
FORM show_data .
DATA: ws_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
ws_fieldgroups_tab TYPE slis_t_sp_group_alv,
ws_layout TYPE slis_layout_alv,
ws_sortfields_tab TYPE slis_t_sortinfo_alv WITH HEADER LINE,
gt_events TYPE slis_t_event,
gs_event TYPE slis_alv_event,
gs_glay TYPE lvc_s_glay.
DATA: nn TYPE i VALUE 0.
DATA: title TYPE lvc_title.
DATA: color TYPE slis_t_specialcol_alv WITH HEADER LINE.
*
DEFINE hout.
NN = NN + 1.
WS_FIELDCAT-COL_POS = NN.
WS_FIELDCAT-TABNAME = 'GT_user'.
WS_FIELDCAT-KEY = &1.
WS_FIELDCAT-FIELDNAME = &2.
WS_FIELDCAT-SELTEXT_M = &3.
WS_FIELDCAT-CFIELDNAME = &4.
WS_FIELDCAT-DATATYPE = &5.
WS_FIELDCAT-REF_TABNAME = &6.
WS_FIELDCAT-REF_FIELDNAME = &7.
WS_FIELDCAT-CHECKBOX = &8.
WS_FIELDCAT-EDIT = &9.
APPEND WS_FIELDCAT.
CLEAR WS_FIELDCAT.
END-OF-DEFINITION.
hout:
'' 'BNAME' '帐号' '' '' '' '' '' '',
'' 'NAME_FIRST' '名字1' '' '' '' '' '' '',
'' 'NAME_LAST' '名字2' '' '' '' '' '' '',
'' 'NAME_TEXT' '名字3' '' '' '' '' '' 'X',
'' 'CHECKBOX' '选择' '' '' '' '' 'X' 'X'.
ws_layout-zebra = 'X'.
ws_layout-get_selinfos = 'X'.
ws_layout-colwidth_optimize = 'X'.
ws_layout-detail_popup = 'X'.
"排序这个字段
ws_sortfields_tab-fieldname = 'NAME_FIRST'.
ws_sortfields_tab-down = 'X'.
APPEND ws_sortfields_tab.
CLEAR ws_sortfields_tab.
gs_event-name = gs_event-form = 'DATA_CHANGED'.
APPEND gs_event TO gt_events.
gs_glay-edt_cll_cb = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = ws_layout
it_fieldcat = ws_fieldcat[]
* it_special_groups = ws_fieldgroups_tab[]
* it_sort = ws_sortfields_tab[]
it_events = gt_events
* i_grid_title = title
i_grid_settings = gs_glay
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_user
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
*---------------------------------------------------------------------
* Form DATA_CHANGED
*---------------------------------------------------------------------
FORM data_changed USING pcl_data TYPE REF TO cl_alv_changed_data_protocol.
DATA(lt_mod_cell) = pcl_data->mt_mod_cells .
READ TABLE lt_mod_cell INTO DATA(ls_mod_cell) INDEX 1.
READ TABLE GT_data INTO gs_data INDEX ls_mod_cell-row_id." 读内表中将要被修改的一行
gs_data-box = ls_mod_cell-value. " ALV界面已经改了,现在把这个修改内容赋值给内表工作区
MODIFY gt_data FROM gs_data INDEX ls_mod_cell-row_id . "更新内表
LOOP AT gt_data ASSIGNING FIELD-SYMBOL(<lw_data>) WHERE zdz = gs_data-zdz.
<lw_data>-box = ls_mod_cell-value.
ENDLOOP.
"刷新才能看到数据改变的效果
PERFORM frm_refresh_table.
ENDFORM.
FORM frm_refresh_table.
DATA: ls_stbl TYPE lvc_s_stbl.
DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_ref_alv.
ls_stbl-row = 'X'.
ls_stbl-col = 'X'.
"刷新屏幕
CALL METHOD l_ref_alv->refresh_table_display
EXPORTING
is_stable = ls_stbl
* I_SOFT_REFRESH = 'X'
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
注意:必须要gt_event gs_glay 不然,复选框点击一次不会进去