下拉列表的例子
REPORT ZJGLTEST01 .
************************************************************************
* DATEN DEFINITION *
************************************************************************
type-pools: slis.
tables:makt.
types:
begin of t_data,
matnr type makt-matnr,
maktx type makt-maktx,
spras type makt-spras,
end of t_data,
begin of t_alv,
matnr type makt-matnr,
maktx type makt-maktx,
spras type makt-spras,
dd_handle type int4,
end of t_alv.
data:
gt_fieldcatalog type lvc_t_fcat,
gw_fieldcatalog type lvc_s_fcat,
*定义存储下拉列表的数据
gt_ddval type lvc_t_drop,
gw_ddval type lvc_s_drop,
gt_events type slis_t_event,
gw_events type slis_alv_event,
gt_data type table of t_data,
gw_data type t_data,
gt_alv type table of t_alv,
gw_alv type t_alv,
g_repid type sy-repid value sy-repid.
************************************************************************
* SELECTION SCREEN *
************************************************************************
select-options: s_matnr for makt-matnr .
************************************************************************
* START-OF-SELECTION *
************************************************************************
start-of-selection.
select matnr maktx spras
into table gt_data
up to 5 rows
from makt
where matnr in s_matnr
and spras = '1'.
loop at gt_data into gw_data.
move-corresponding gw_data to gw_alv.
append gw_alv to gt_alv.
endloop.
perform creat_fieldcat.
perform creat_dropdown_values.
perform creat_event_exits.
call function 'REUSE_ALV_GRID_DISPLAY_LVC'
exporting
i_callback_program = g_repid
it_fieldcat_lvc = gt_fieldcatalog
it_events = gt_events
tables
t_outtab = gt_alv.
*---------------------------------------------------------------------*
* 设置输出字段的格式
*---------------------------------------------------------------------*
form creat_fieldcat.
clear gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MATNR'.
gw_fieldcatalog-ref_field = 'MATNR'.
gw_fieldcatalog-ref_table = 'MAKT'.
append gw_fieldcatalog to gt_fieldcatalog.
clear gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MAKTX'.
gw_fieldcatalog-ref_field = 'MAKTX'.
gw_fieldcatalog-ref_table = 'MAKT'.
append gw_fieldcatalog to gt_fieldcatalog.
clear gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'SPRAS'.
gw_fieldcatalog-outputlen = '7'.
gw_fieldcatalog-dd_outlen = '7'.
gw_fieldcatalog-intlen = '2'.
gw_fieldcatalog-inttype = 'C'.
gw_fieldcatalog-coltext = 'Language'.
gw_fieldcatalog-tooltip = 'Language'.
gw_fieldcatalog-seltext = 'Language'.
gw_fieldcatalog-drdn_field = 'DD_HANDLE'.
gw_fieldcatalog-edit = 'X'.
append gw_fieldcatalog to gt_fieldcatalog.
endform. " creat_fieldcat
*---------------------------------------------------------------------*
*根据物料的所有的语言生成不同的生成下拉列表
*---------------------------------------------------------------------*
form creat_dropdown_values.
data: l_spras type makt-spras,
l_count type i.
loop at gt_alv into gw_alv.
add 1 to l_count.
select spras
into l_spras
from makt
where matnr = gw_alv-matnr.
clear gw_ddval.
gw_ddval-handle = l_count.
gw_ddval-value = l_spras.
append gw_ddval to gt_ddval.
endselect.
clear gw_ddval.
gw_ddval-handle = l_count.
gw_ddval-value = ' '.
append gw_ddval to gt_ddval.
*设置对应
gw_alv-dd_handle = l_count.
modify gt_alv from gw_alv.
endloop.
endform. " creat_dropdown_values
*---------------------------------------------------------------------*
* Form creat_event_exits
*---------------------------------------------------------------------*
form creat_event_exits .
gw_events-name = 'CALLER_EXIT'.
gw_events-form = 'CALLER_EXIT'.
append gw_events to gt_events.
endform. " creat_event_exits
*---------------------------------------------------------------------*
*设置下拉列表,使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