report.
*---data definition
types: begin of typ_ztco.
include structure ztco.
types: zsel type c, "选择标识
style type lvc_t_styl, "FOR DISABLE
dd_handle type int4, "下拉
end of typ_ztco.
data: git_ztco type table of typ_ztco with header line,
gwa_ztco type typ_ztco.
*---for alv
type-pools: slis.
data: gwa_layout type lvc_s_layo,"slis_layout_alv
git_field type lvc_t_fcat,"slis_t_fieldcat_alv
gwa_field like line of git_field,
git_sort type lvc_t_sort,"slis_t_sortinfo_alv
gwa_sort like line of git_sort,
g_grid_title type lvc_title,
go_gui_alv_grid type ref to cl_gui_alv_grid.
*---for 下拉
data: gt_ddval type lvc_t_drop,
gw_ddval type lvc_s_drop,
gt_events type slis_t_event,
gw_events type slis_alv_event.
*------------------ class definition -----------------------------------
class lcl_alv_receiver definition.
public section.
methods:
handle_data_changed for event data_changed of cl_gui_alv_grid
importing er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.
endclass. "lcl_event_receiver DEFINITION
*---------------------- class implementation ---------------------------
class lcl_alv_receiver implementation.
method handle_data_changed.
perform frm_handle_data_changed using er_data_changed.
endmethod. "handle_data_changed
endclass. "lcl_ALV_event_receiver
define m_alv_fieldcat.
clear gwa_field.
gwa_field-fieldname = &1."字段名称
gwa_field-just = &2."对齐方式
gwa_field-scrtext_m = &3.
gwa_field-edit = &4."是否编辑
gwa_field-checkbox = &5."复选框
gwa_field-key = &6.
gwa_field-no_zero = &7.
gwa_field-ref_field = &8."参考字段,配合参考表,在alv单元格上会看到效果
gwa_field-ref_table = &9."参考表
gwa_field-outputlen = '10'.
*---给类型字段设置下拉框形式
if &1 = 'TYPE'.
gwa_field-drdn_field = 'DD_HANDLE'.
endif.
append gwa_field to git_field.
end-of-definition.
start-of-selection.
select * into corresponding fields of table git_ztco from ztco.
m_alv_fieldcat: 'WERKS' '' text-f02 '' '' 'X' 'X' 'WERKS' 'ZTCO',
'STATE' 'R' text-f03 '' '' 'X' 'X' 'STATE' 'ZTCO',
'NAME1' '' text-f05 '' '' '' 'X' '' 'ZTCO',
'ERDAT' '' text-f04 '' '' '' 'X' '' 'ZTCO',
'TYPE' '' text-f06 '' '' 'X' 'X' 'TYPE' 'ZTCO',
'SHFE' '' text-f07 'X' '' '' 'X' 'SHFE' 'ZTCO'.
*---设置下拉内容,handle相当于分组的功能,这里设置为1个组
clear gw_ddval.
gw_ddval-handle = 1.
gw_ddval-value = 'ZP01'.
append gw_ddval to gt_ddval.
clear gw_ddval.
gw_ddval-handle = 1.
gw_ddval-value = 'ZP02'.
append gw_ddval to gt_ddval.
clear gw_ddval.
gw_ddval-handle = 1.
gw_ddval-value = 'ZP03'.
append gw_ddval to gt_ddval.
sort gt_ddval by value.
clear gw_ddval.
gw_ddval-handle = 1.
gw_ddval-value = ''.
append gw_ddval to gt_ddval.
*---设置对应到第1组数据
loop at git_ztco.
git_ztco-dd_handle = 1.
modify git_ztco.
endloop.
*---添加下拉事件
gw_events-name = 'CALLER_EXIT'.
gw_events-form = 'CALLER_EXIT'.
append gw_events to gt_events.
*----------------------- 设置下拉列表,使Grid和内表能链接上 ---------------------------
form caller_exit using ls_data type slis_data_caller_exit.
data: l_ref_alv type ref to cl_gui_alv_grid.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = l_ref_alv.
call method l_ref_alv->set_drop_down_table
exporting
it_drop_down = gt_ddval.
endform. "CALLER_EXIT
end-of-selection.
gwa_layout-box_fname = 'ZSEL'.
gwa_layout-stylefname = 'STYLE'.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
i_callback_program = sy-repid
i_callback_pf_status_set = 'FRM_SET_STATUS'
is_layout_lvc = gwa_layout
it_fieldcat_lvc = git_field
it_sort_lvc = git_sort
it_events = gt_events
i_default = 'X'
i_save = 'A'
tables
t_outtab = git_ztco
exceptions
program_error = 1
others = 2.
*&---------------------------------------------------------------------*
*& Form frm_handle_data_changed
*&---------------------------------------------------------------------*
form frm_handle_data_changed using data_changed type ref to cl_alv_changed_data_protocol.
* data: mod_data type lvc_t_modi,
* wa_mod_data type lvc_s_modi.
* mod_data = data_changed->mt_mod_cells.
*---alv 数据改变的响应
message 'dd' type 'I'.
endform. "frm_handle_data_changed
*&---------------------------------------------------------------------*
*& Form frm_set_status
*&---------------------------------------------------------------------*
form frm_set_status using rt_extab type slis_t_extab.
set pf-status 'STATUS_001'.
*---为alv grid注册事件
data: lr_grid type ref to cl_gui_alv_grid.
call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
importing
e_grid = lr_grid.
data event_receiver type ref to lcl_alv_receiver.
create object event_receiver.
set handler event_receiver->handle_data_changed for lr_grid.
call method lr_grid->check_changed_data.
call method lr_grid->register_edit_event "注册更新事件
exporting
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
*---稳定更新,使焦点不改变
* data ls_stable type lvc_s_stbl.
* ls_stable-row = 'X'.
* ls_stable-col = 'X'.
* call method lr_grid->refresh_table_display
* exporting
* is_stable = ls_stable
* exceptions
* finished = 1
* others = 2.
*---程序调用screen刷新
* call method cl_gui_cfw=>flush.
endform. "frm_set_status
评论