ALV GRID参考文档 ( 11 ) -表单中显示按钮

PUSHBUTTONS ON THE LIST
如果想让某个单元格显示为按钮,那么只需两步就可做到。首先在显示数据内表中插入类型为LVC_T_STYL的内表。
*-- Internal table holding list data
DATA: BEGIN OF gt_list OCCURS 0.
   INCLUDE STRUCTURE sflight.
DATA rowcolor(4) TYPE c.
DATA cellcolors TYPE lvc_t_scol.
DATA carrid_handle TYPE int4.
DATA connid_handle TYPE int4.
DATA cellstyles TYPE lvc_t_styl.
DATA END OF gt_list.
把想要显示为按钮的字段添加到内表中
DATA ls_style TYPE lvc_s_styl.
READ TABLE gt_list INDEX 7.
Ls_style-fieldname = ‘SEATSMAX’.
Ls_style-style = cl_gui_alv_grid=>nc_style_button.
APPEND ls_style TO gt_list-cellstyles.
MODIFY gt_list INDEX 7.
在layout structure中指明显示数据内表中表示样式的字段。例如;
Gs_layout-stylefname = ‘CELLSTYLES’.
按钮点击事件和单击事件差不多也是通过参数es_col_id和es_row_no来确定被点击按钮的位置。
添加自己的功能:
ALV GRID控件提供了通过单击按钮来实现自己功能的接口。实现这种功能主要有两个事件。通过toolbar事件来实现添加工具条按钮通过事件user_command来实现用户定义的新功能。
FORM handle_toolbar USING i_object TYPE REF TO cl_alv_event_toolbar_set.
 DATA: ls_toolbar TYPE stb_button.
 
 CLEAR ls_toolbar.
 MOVE 3 TO ls_toolbar-butn_type.
 APPEND ls_toolbar TO i_object->mt_toolbar.
 CLEAR ls_toolbar.
 MOVE ‘PER’ TO ls_toolbar-function.
 MOVE icon_display_text TO ls_toolbar-icon.
 MOVE ‘Passenger Info’(201) TO ls_toolbar-quickinfo.
 MOVE ‘Passenger Info’(201) TO ls_toolbar-text.
 MOVE ‘ ‘ TO ls_toolbar-disabled.
 APPEND ls_toolbar TO i_object->mt_toolbar.
 
 CLEAR ls_toolbar.
 MOVE ‘EXCH’ TO ls_toolbar-function.
 MOVE 2 TO ls_toolbar-butn_type.
 MOVE icon_calculation TO ls_toolbar-icon.
 MOVE ‘Payment in other Curencies’(202) TO ls_toolbar-quickinfo.
 MOVE ‘ ‘ TO ls_toolbar-text.
 MOVE ‘ ‘ TO ls_toolbar-disapbled.
 APPEND ls_toolbar TO i_object->mt_toolbar.
ENDFORM.
这个结构的字段的列表如下:
Field
Description
FUNCTION
FUNCTION CODE FOR THE FUNCTION
BUTN_TYPE
Button type will be added to the toolbar. Available button types are:
0                                                     Button(normal)
1                                                     Menu and default button
2                                                     Menu
3                                                     Separator
4                                                     Radio button
5                                                     Checkbox
6                                                     Menu entry
ICON
ICON for the button(optional)
TEXT
TEXT for the button(optional)
QUICKINFO
Quick info for the button(optional)
DISABLED
Adds the button as disabled
下面例子的代码添加了一个normal button和一个menu button,并添加了一个分隔线。通过把button的类型设为1或2就可以添加menu button,在事件menu_button中还可以实现子菜单。这些子菜单中的功能码也是在user_command中实现的。
FORM handle_menu_button USING i_object TYPE REF TO cl_ctmenu
I_ucomm TYPE syucomm..
 CASE i_ucomm.
 WHEN ‘EXCH’.
CALL METHOD i_object->add_function
      EXPORTING
         Fcode     = ‘EU’
         Text      = ‘Euro’.
CALL METHOD i_object->add_function
      EXPORTING
         Fcode     = ‘TRL’
         Text      = ‘Turkish Lira’.
 ENDCASE.
ENDFORM.
通过事件user_command来处理点击工具条中的按钮或菜单要做的事情。
FORM handle_user_command USING i_ucomm TYPE syucomm.
 DATA lt_selected_rows TYPE lvc_t_rowid.
 DATA ls_selected_row TYPE lvc_s_roid.
 
 CALL METHOD gr_alvgrid->get_selected_rows
        IMPORTING
              Et_row_no = lt_selected_rows.
 READ TABLE lt_selected_rows INTO ls_selected_row INDEX 1.
 If sy-subrc ne 0.
    MESSAGE S000(su) WITH ‘Select a row’(203).
 ENDIF.
 CASE i_ucomm.
 WHEN ‘CAR’.
     READ TABLE gt_list INDEX ls_selected_row-row_id.
     IF sy-subrc = 0.
       CALL FUNCTION ‘ZDISPLAY_CARRIER_INFO’
             EXPORTING carrid = gt_list-carrid
             EXCEPTIONS carrier_not_found  = 1
                          Oters           = 2.
     ENDIF.
 WHEN ‘EU’.
     READ TABLE gt_list INDEX ls_selected_row-row_id.
     IF sy-subrc = 0.
        CALL FUNCTION ‘ZPOPUP_CONV_CURR_ADD_DISPLAY’
              EXPORTING monun = ‘EU’
                          Quant = gt_list-paymentsum.
     ENDIF.
 ENDCASE.
ENDFORM.
通过方法get_selected_rows来得到选取的行的信息。由于功能EXCH含有子功能,并没有在它哪里实现任何功能。
想要alv显示额外的功能,必须使用alv grid实例的set_toolbar_interactive方法。
CALL METHOD gr_alv_grid->set_toolbar_interactive.

你可能感兴趣的:(function,command,文档,button,menu,structure)