先在ovp中添加一个button,fpm_event_id 属性设置一个值.
constants:
BEGIN OF gc_toolbar_element_type,
button TYPE fpm_tb_element_type VALUE 'BU',
toggle_button TYPE fpm_tb_element_type VALUE 'TB',
button_choice TYPE fpm_tb_element_type VALUE 'BC',
END OF gc_toolbar_element_type .
field-symbols:
<lv_enabled> type fpm_enabled,
<ls_choice_item> type if_fpm_ovp=>ty_s_toolbar_element_sub_item,
<ls_toolbar_element> type if_fpm_ovp=>ty_s_toolbar_element.
** Read toolbar of content area
try.
call method io_ovp->get_toolbar_elements
exporting
iv_uibb_primary_attribute = iv_uibb_primary_attribute
importing
et_toolbar_element = lt_toolbar_elements.
loop at lt_toolbar_elements assigning <ls_toolbar_element>.
lv_update = abap_false. "by default no update
case <ls_toolbar_element>-type.
when if_fpm_constants=>gc_toolbar_element_type-button.
* Process toolbar element type Button
call method io_ovp->get_toolbar_button
exporting
iv_uibb_primary_attribute = iv_uibb_primary_attribute
iv_toolbar_element_id = <ls_toolbar_element>-element_id
importing
es_toolbar_button = ls_toolbar_button.
if ls_toolbar_button-event_id = iv_event_id.
* Call method that handles the updating of attribut
assign component 'ENABLED' of structure ls_toolbar_element to <lv_enabled>.
if <lv_enabled> <> iv_enabled.
<lv_enabled> = iv_enabled.
ev_update = abap_true.
endif. "iv_enabled <> <lv_enabled>
ls_toolbar_element- visibility = iv_text.
element_id TYPE fpm_element_id,
index TYPE fpm_index,
text TYPE fpm_text,
image TYPE fpm_image,
tooltip TYPE fpm_tooltip,
hotkey TYPE fpm_hotkey,
explanation_text TYPE fpm_explanation,
enabled TYPE fpm_enabled,
visibility TYPE fpm_visibility,
alignment TYPE fpm_toolbar_element_alignment,
has_separator TYPE fpm_add_separator,
event_id TYPE fpm_event_id,
event_parameters TYPE fpm_t_parameter,
action_type TYPE fpm_action_type,
target_content_area TYPE fpm_target_content_area,
component TYPE fpm_component_name,
interface_view TYPE fpm_view_name,
config_id TYPE wdy_config_id,
config_type TYPE wdy_config_type,
config_var TYPE wdy_config_var,
if lv_update eq abap_true.
call method io_ovp->change_toolbar_button
exporting
iv_uibb_primary_attribute = iv_uibb_primary_attribute
is_toolbar_button = ls_toolbar_button
iv_override_existing_action = abap_true. "required to set attributes to existing action
endif. "lv_update EQ abap_true
when if_fpm_constants=>gc_toolbar_element_type-toggle_button.
when if_fpm_constants=>gc_toolbar_element_type-button_choice.
call method io_ovp->get_toolbar_button_choice
exporting
iv_uibb_primary_attribute = iv_uibb_primary_attribute
iv_toolbar_element_id = <ls_toolbar_element>-element_id
importing
es_toolbar_button_choice = ls_tb_button_choice
et_toolbar_button_choice_item = lt_tb_but_choice_item.
read table lt_tb_but_choice_item with key event_id = iv_event_id
assigning <ls_choice_item>.
endcase.
endloop. "lt_toolbar_elements ASSIGNING
catch cx_fpm_floorplan .
return.
endtry.