下拉列表,据说只有带LVC的function才能实现下拉列表,未测试
步骤①:声明一个类型为lvc_t_drop的内表,用来保存下拉列表的值,如下:
DATA: gt_ddval TYPE lvc_t_drop,
gs_ddval TYPE lvc_s_drop.
步骤②:往gt_ddval中塞值,其中
字段handle代表不同的下拉列表,有几个列需要设置下拉列表就设置到几
字段value为对应的下拉列表的值
如下:
CLEAR gs_ddval.
gs_ddval-handle = '1'.
gs_ddval-value = '下拉1-1'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '1'.
gs_ddval-value = '下拉1-2'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '1'.
gs_ddval-value = '下拉1-3'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '2'.
gs_ddval-value = '下拉2-1'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '2'.
gs_ddval-value = '下拉2-2'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '2'.
gs_ddval-value = '下拉2-3'.
APPEND gs_ddval TO gt_ddval.
gs_ddval-handle = '2'.
gs_ddval-value = '下拉2-4'.
APPEND gs_ddval TO gt_ddval.
步骤③:注册CALLER_EXIT事件,并在事件中调用set_drop_down_table方法
如下:
"事件响应
"注册CALLER_EXIT事件,在CALLER_EXIT事件中注册其他事件
CLEAR: ls_events,lt_events.
ls_events-name = 'CALLER_EXIT'. "注册的事件
ls_events-form = 'FRM_EVENTS_CALLER'. "响应事件的form
APPEND ls_events TO lt_events.
FORM frm_events_caller USING ls_data TYPE slis_data_caller_exit. "ls_data形参
IF go_grid IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = go_grid.
ENDIF.
"设置下拉列表
CALL METHOD go_grid->set_drop_down_table
EXPORTING
it_drop_down = gt_ddval.
"如果call ALV未设置参数回调参数I_GRID_SETTINGS,需要注册EDIT事件
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
ENDFORM.
步骤④:设置fieldcat字段
drdn_hndl:对应步骤②中的handle
edit:设置为‘X’
DATA: gt_fieldcat TYPE lvc_t_fcat,
gs_fieldcat TYPE lvc_s_fcat,
DEFINE fieldcat_add.
CLEAR gs_fieldcat.
gv_index = gv_index + 1.
gs_fieldcat-col_pos = gv_index.
gs_fieldcat-fieldname = &1.
gs_fieldcat-reptext = &2.
gs_fieldcat-outputlen = &3.
gs_fieldcat-no_zero = &4.
gs_fieldcat-decimals = &5.
gs_fieldcat-checkbox = &6.
gs_fieldcat-edit = &7.
gs_fieldcat-ref_table = &8.
gs_fieldcat-ref_field = &9.
IF &1 = 'ZCS1'.
gs_fieldcat-drdn_hndl = '1'.
ELSEIF &1 = 'ZCS2'.
gs_fieldcat-drdn_hndl = '2'.
ENDIF.
APPEND gs_fieldcat TO gt_fieldcat.
END-OF-DEFINITION.
fieldcat_add 'ZCS1' '测试1' '10' '' '' '' 'X' '' ''.
fieldcat_add 'ZCS2' '测试2' '10' '' '' '' 'X' '' ''.
测试效果:
以上。