Create Custom Button in initialization method
like below.
DATA lo_cmp_usage TYPE REF TO if_wd_component_usage,
lo_alv_config TYPE REF TO cl_salv_wd_config_table,
lo_cmp_usage = wd_this->wd_cpuse_alv_risk_result( ).
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.
DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .
lo_interfacecontroller = wd_this->wd_cpifc_alv_risk_result( ).
lo_alv_config = lo_interfacecontroller->get_model( ).
Pass This Ref to Global.
Wd_this->go_alv_ref = lo_alv_config .
Create Custom Button.
DATA lr_buttonui TYPE REF TO cl_salv_wd_fe_button.
DATA button1 TYPE REF TO cl_salv_wd_function.
CREATE OBJECT lr_buttonui.
lr_buttonui->set_text('Button')."setting the text of the button on alv toolbar
button1 = lo_alv_config->if_salv_wd_function_settings~create_function( id = 'BUTTON')."creating the function for alv button
button1->set_editor( lr_buttonui ).
Create One Method of Event handler of On_Function
method BUTTON .
DATA: lr_but type string,
lr_buttonui TYPE REF TO cl_salv_wd_fe_button,
button1 TYPE REF TO cl_salv_wd_function.
lr_but = r_param->id.
if lr_but = 'BUTTON'. "Ur Button Id in Tool ALV
create OBJECT lr_buttonui.
lr_buttonui->set_enabled( abap_false ).
lr_buttonui->set_text( 'Button' ). "Same Button text
Button1 = wd_this->go_alv_ref->if_salv_wd_function_settings~get_function( id = lr_but ).
Button1->set_editor( lr_buttonui ).
endif.
endmethod.