ABAP-AVL-如何去掉OO方法中的ALV的标准按钮
SAP在做报表开发中,不同公司对报表的风格往往各异,为此经常在使用OO方法做ALV报表中需要去掉自带的工具栏而自行添加一些工具按钮,下面将简单介绍一些其实现过程与原理:
步骤一:
DATA : gt_exclude TYPE ui_functions.
步骤二:写一个FORM将要去掉的按钮添加到上面定义的表(gt_exclude)
perform exclude_tb_functions tables gt_exclude
FORM exclude_tb_functions TABLES pt_exclude TYPE ui_functions .
DATA: ls_exclude TYPE ui_func.
ls_exclude = cl_gui_alv_grid=>mc_fc_maximum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_minimum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_subtot .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_average .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_sum .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_subtot .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_asc.
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_sort_dsc .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_find .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_filter .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_print_prev .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_export .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_graph .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_mb_view .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_detail .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_help .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>mc_fc_info .
APPEND ls_exclude TO pt_exclude.
ls_exclude = cl_gui_alv_grid=>MC_MB_VARIANT.
APPEND ls_exclude TO pt_exclude.
ENDFORM. " exclude_tb_functions
步骤三:
CALL METHOD grf_grid1->set_table_for_first_display
EXPORTING
is_variant = gs_variant
i_save = ' '
is_layout = gs_layout
it_toolbar_excluding = gt_exclude
CHANGING
it_outtab = gt_result1[]
it_fieldcatalog = gt_fcat_lvc.
3.6、对象ALV单元格编辑状态设计
ALV函数只能实现对整列的编辑状态控制,单元格的编辑状态控制只能通过ALV OO实现。
1.单元格状态控制和单元格颜色控制类似,在LIST DATA TABLE中定义一个字段cellstyle. TYPE lvc_t_styl
list data table中的cellstyle字段将被用来存储单元格样式信息,单元格编辑状态就是通过表中的内容来控制
2.根据相关条件调整list data table中的cellstyle字段内容
3.设置样式输出控制结构的stylename字段内容为单元格状态控制字段名
3.7、cell 更新事件
ALV单元格设置为可输入后,通常我们需要对单元格输入的值做一个检查,一般来说用循环内表的方法可以实现上述操作,不过如果ALV中有大量数据,而我们只更新了少量的单元格数据,这样检查显得非常的麻烦,而且效率低下
在ALV OO中我们可以通过DATA_CHANGE事件得到被修改的单元格的信息,利用这些信息我们可以很方便的对所填数据做检查,别且可以给用户相应的错误提示,以及自动修改单元格数据
1.我们需要在处理事件的类中添加一个处理DATA_CHANGE事件的方法
Eg:
CLASS lcl_alv_receiver DEFINITION DEFERRED.
CLASS lcl_alv_receiver DEFINITION.
PUBLIC SECTION.
……..
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm.
ENDCLASS. "lcl_event_receiver DEFINITION
2.初始化ALV后为lcl_alv_receiver类注册一个DATA_CHANGED事件 Eg:
CALL METHOD g_grid->set_table_for_first_display
EXPORTING
i_save = x_save
is_variant = ls_layout
is_layout = is_layout
CHANGING
it_fieldcatalog = it_fieldcat
it_outtab = lt_zqsdmx[].
SET HANDLER g_alv_application->handle_data_changed FOR g_grid.
CALL METHOD g_grid->register_edit_event “注册更新事件
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter .
其中i_event_id = cl_gui_alv_grid=>mc_evt_enter 表示在单元格修改后回车或者执行其他操作时触发事件,此类型可用于多个单元格修改后一起检查修改的值
i_event_id = cl_gui_alv_grid=>mc_evt_modified 表示单光标焦点移开被修改单元格后既触发事件,此类型可用于每个每个单元个的实时更新检查
3.实现lcl_alv_receiver类的handle_data_changed方法,其中一些常用的一些属性方法我会在后附表列出Eg:
CLASS lcl_alv_receiver IMPLEMENTATION.
METHOD handle_toolbar.
METHOD handle_data_changed.
PERFORM. handle_data_changed USING er_data_changed.
ENDMETHOD. "handle_data_changed
ENDCLASS. "lcl_ALV_event_receiver
*&---------------------------------------------------------------------*
*& Form handle_data_changed
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ER_DATA_CHANGED text
*----------------------------------------------------------------------*
FORM. handle_data_changed USING p_er_data_changed TYPE REF TO cl_alv_changed_data_protocol.
*如果更新的reason字段长度小于10为则提示用户填入字符数不能低于10
DATA:mod_data TYPE lvc_t_modi,
wa_mod_data TYPE lvc_s_modi.
mod_data = p_er_data_changed->mt_mod_cells.
LOOP AT mod_data INTO wa_mod_data Where fieldname = 'ZRESON'.
IF STRLEN( wa_mod_data-value ) < 10.
CALL METHOD p_er_data_changed->add_protocol_entry
EXPORTING
i_msgid = '00'
i_msgty = 'E'
i_msgno = '001'
i_msgv1 = '长度必须大于10 '
i_fieldname = wa_mod_data-fieldname.
*如果长度小于10,则将字段内容更新为长都无法确定
CALL METHOD p_er_data_changed->modify_cell
EXPORTING
i_row_id = wa_mod_data-row_id
i_fieldname = wa_mod_data-fieldname.
ENDIF.
ENDLOOP.
ENDFORM.