Google Search - Blog...........

ABAP - Customizing Toolbar In ALV Tree Using ABAP OO


Often, one requires customizing the toolbar that appears in an ALV Tree and taking specific actions on choosing this button by triggering the specific handlers.

The following code snippet shows how this can be done in ABAP OO assuming you have a class which requires this handling and the following methods in the same will help you achieve this.

The following code snippet assumes that a filter button appears on given conditions only in the ALV tree and requires to be turned off at other times.

This is achieved in the following manner:

Assume the ALV Tree is created and now we wish to customize the toolbar for the same:
p_filter is the flag which decides if the filter button requires to be visible or not.


******************************************************************
*Create ALV tree prior to this in create_my_tree() method.
*Change the toolbar to suit our needs,pass the tree and filter as parameters.
.........

method create_toolbar.
create_my_tree().

if f_alvtree is not initial. __call_toolbar( tree = f_alvtree filter = p_filter ).
endif.
endmethod.


******************************************************************
*You could specify the toolbar by passing the instance variable f_toolbar which stores the toolbar instance and the filter options.

method __call_toolbar.
check tree is not initial.
tree->get_toolbar_object( importing er_toolbar = f_toolbar ).
f_filter_opt = filter.
__customize_toolbar( alvtreebar = f_toolbar refresh = f_filter_opt ).
endmethod.

******************************************************************
*Specify the tooltips that you wish for your toolbar items. Here *iconquick is a text icon defined in the dictionary.
*It also is optimal to group your icons in an icon package. Raise the event for handling the icon change ,define an event as below in your class.
******************************************************************


method __customize_toolbar.
data : l_tooltip type iconquick.
if alvtreebar is not initial.


*----------------------------------------------------
call method alvtreebar->delete_button
exporting
fcode = 'SHOW_GRID'.

* ----------------------------------------------------
if refresh = ''. " Filter is off so add filter off button
clear: l_tooltip.
l_tooltip = 'Switch on Filter '(add).

call method alvtreebar->add_button
exporting
butn_type = cntb_btype_button
quickinfo = l_tooltip
icon = icon_filter_undo
fcode = 'FILON'.
else.

* ----------------------------------------------------
clear: l_tooltip." Add filter on button
l_tooltip = 'Switch off Filter'(fil).

call method alvtreebar->add_button
exporting
butn_type = cntb_btype_button
quickinfo = l_tooltip
icon = icon_filter
fcode = 'FILOFF'
is_disabled = ''.
endif.

* ----------------------------------------------------
raise event change_tree_toolbar
exporting
im_toolbar = alvtreebar.

* ----------------------------------------------------
set handler __handle_filter_selected for alvtreebar.
endif.

******************************************************************
* This method actually deals with the change on filter appearing/disappearing.
method __handle_filter_selected.

case fcode.
when 'FILOFF'.
check f_toolbar is not initial.
f_filter_opt = ''.
__handle_filter( ).
f_filter_opt = 'X'.
when 'FILON' .
check f_toolbar is not initial.
f_filter_opt = 'X'.
__handle_filter( ).
when others.
endcase.
endmethod.
******************************************************************



ALSO READ:

- Dropdown in ALV Grid Display.

- Dynamic ALV Grid/List Display.

- Handling Radio Buttons in SALV Tree Display.

- Implementing F4 Search Help In OO ALV Grid Display.

..... Back To Index On ALV List/ Grid Display.

..... Back To MAIN INDEX.


No comments:

Post a Comment