ALV下拉框
如图在ALV下拉框内做了1到5 的选择下拉框,下面一起来看下如何实施
1.在GT_DATA中增加一个字段来用于下拉框的使用:
TYPES:BEGIN OF ty_data,
checkbox TYPE c,
matnr TYPE mara-matnr,
mtart TYPE mara-mtart,
matkl TYPE mara-matkl,
maktx TYPE makt-maktx,
context TYPE char10,”用于下拉框
END OF ty_data.
DATA gt_data TYPE TABLE OF ty_data WITH EMPTY KEY.
|
2.设置fieldcat属性:
设置context字段可输入,设置fieldcat-drdn_hndl = ‘1’.
(这个1是下面下拉框对应的组,可以用2 3 4 5 6··· 来标记下拉框的组,以此来实现多个下拉框)
FORM frm_set_fieldcat.
DATA lv_pos TYPE i.
DATA ls_fieldcat LIKE LINE OF gt_fieldcat.
DEFINE %%append_fieldcat.
lv_pos = lv_pos + 1.
ls_fieldcat-col_pos = lv_pos.
ls_fieldcat-fieldname = &1.”字段名
ls_fieldcat-coltext = &2.”文本
* ls_fieldcat-no_zero = &3.”去掉前导零
ls_fieldcat-ref_table = &3.
ls_fieldcat-ref_field = &4.
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
END-OF-DEFINITION.
%%append_fieldcat:
‘CHECKBOX’ ‘选择’ ” ”,
‘MATNR’ ” ‘MARA’ ‘MATNR’,
‘MTART’ ” ‘MARA’ ‘MTART’,
‘MATKL’ ” ‘MARA’ ‘MATKL’,
‘MAKTX’ ” ‘MAKT’ ‘MAKTX’,
‘CONTEXT’ ‘下拉输入1’ ” ”.
READ TABLE gt_fieldcat ASSIGNING FIELD-SYMBOL(<fs1>) WITH KEY fieldname = ‘CONTEXT’.
IF sy-subrc EQ 0.
<fs1>-edit = ‘X’.
<fs1>-drdn_hndl = ‘1’.“分组标识
ENDIF.
|
3.设置下拉框内容
如下图,set_drop_down_table()方法需要在 set_table_for_first_display()方法之前调用,否则下拉框没有下拉值。
Handle = 1 就是给下拉框分组
“ALV 下拉框
DATA:ls_drop_down TYPE lvc_s_drop,
lt_drop_down TYPE lvc_t_drop.
“句柄HANDLE 为I类型,相同数字为同一组下拉框
DO 5 TIMES.
CLEAR ls_drop_down.
ls_drop_down-handle = ‘1’.“对应分组标识
ls_drop_down-value = sy-index.
APPEND ls_drop_down TO lt_drop_down.
ENDDO.
|
“ALV 下拉框
cr_grid->set_drop_down_table(
it_drop_down = lt_drop_down
).
CALL METHOD cr_grid->set_table_for_first_display
EXPORTING
is_variant = ls_disvariant
i_default = ‘X’
i_save = ‘U’
is_layout = ls_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = ct_data
it_fieldcatalog = ct_fieldcat.
|
4.有多个下拉框分组的时候效果:
这样应该理解了handle = 1 / 2 时分组的概念了。