如何在cl_gui_alv_grid设置list列表
在进行OO Grid编程时,用户常需要使用下拉列表来选择输入,其方法步骤如下:
1、创建内表,在内表增加一下字段
handle_drdn type lvc_s_drop-handle,
2、创建GRID
if cl_gui_alv_grid=>offline( ) is initial.
create object gr_container_d0100
exporting container_name = 'D0100_CONTAINER'.
endif.
create object gr_grid_d0100
exporting i_parent = gr_container_d0100.
3、设置字段显示格式
ct_fcat type lvc_t_fcat.
data: ls_fcat type lvc_s_fcat,
l_lin type i.
clear ls_fcat.
ls_fcat-tabname = '1'.
ls_fcat-fieldname = 'DROPDOWN_F4'.
ls_fcat-inttype = 'I'.
ls_fcat-intlen = 10.
ls_fcat-col_pos = l_lin.
ls_fcat-scrtext_s = ls_fcat-fieldname.
ls_fcat-scrtext_m = ls_fcat-fieldname.
ls_fcat-scrtext_l = ls_fcat-fieldname.
append ls_fcat to ct_fcat.
4、设置下拉列表数据(本代码是设置'DROPDOWN_F4'为下拉列表)
form d0100_set_grid_drdn changing ct_fcat type lvc_t_fcat.
field-symbols: <ls_outtab> type g_ty_s_outtab,
<ls_fcat> type lvc_s_fcat.
data: lt_drdn type lvc_t_drop, "#EC NEEDED
ls_drdn type lvc_s_drop, "#EC NEEDED
lt_dral type lvc_t_dral, "#EC NEEDED
ls_dral type lvc_s_dral, "#EC NEEDED
l_count type i.
define mac_get_drdn.
ls_drdn-handle = 1. "列表对象句柄
ls_drdn-value = &1. "列表显示的值
append ls_drdn to lt_drdn.
add 1 to l_count.
ls_dral-handle = 1."列表对象句柄
ls_dral-value = &1. "列表显示的值
write l_count to ls_dral-int_value left-justified. " "选择输入的显示的值
append ls_dral to lt_dral.
end-of-definition.
mac_get_drdn 'http://www.aa.com'.
mac_get_drdn 'http://www.airberlin.com'.
mac_get_drdn 'http://www.aircanda.ca'.
mac_get_drdn 'http://www.airfrance.ca'.
mac_get_drdn 'http://www.alitalia.it'.
mac_get_drdn 'http://www.british-airways.com'.
mac_get_drdn 'http://www.continental.com'.
mac_get_drdn 'http://www.delta-air.com'.
mac_get_drdn 'http://www.airpacific.com'.
mac_get_drdn 'http://www.jal.co.jp'.
mac_get_drdn 'http://www.lufthansa.com'.
mac_get_drdn 'http://www.laudaair.com'.
mac_get_drdn 'http://www.nwa.com'.
mac_get_drdn 'http://www.gantas.com.au'.
mac_get_drdn 'http://www.saa.co.za.de'.
mac_get_drdn 'http://www.singaporeair.com'.
mac_get_drdn 'http://www.swissair.com'.
mac_get_drdn 'http://www.ual.com'.
call method gr_grid_d0100->set_drop_down_table
exporting
it_drop_down_alias = lt_dral. "该调用将列出描叙,自动转换为输入ID值
* call method gr_grid_d0100->set_drop_down_table
* exporting
* it_drop_down = lt_drdn. "该列表选择
read table ct_fcat assigning <ls_fcat>
with key fieldname = 'DROPDOWN_F4'.
if sy-subrc eq 0.
<ls_fcat>-drdn_field = 'HANDLE_DRDN'.
<ls_fcat>-edit = 'X'.
<ls_fcat>-drdn_alias = con_true.
endif.
loop at gt_outtab assigning <ls_outtab>.
<ls_outtab>-handle_drdn = 1."设置字段列表控制句柄,和上面list表对应上
endloop.
endform. " d0100_set_grid_drdn
5、输出数据
call method gr_grid_d0100->set_table_for_first_display
exporting
i_buffer_active = gs_test-buffer_active
i_bypassing_buffer = gs_test-bypassing_buffer
i_consistency_check = l_consistency_check
is_variant = ls_vari
i_save = 'A'
i_default = con_true
is_layout = ls_layo
is_print = ls_prnt
it_hyperlink = lt_hype
changing
it_outtab = gt_outtab[]
it_fieldcatalog = lt_fcat.
参考sap代码:BCALV_TEST_GRID_EDITABLE