11-26-2007 10:52 AM
hi experts,
How to keep button in alv toolbar?,explanin me with example.
thanks in advance.
11-26-2007 10:54 AM
copy the standard alv pf_status.
se80->pf_status->editmode-> application tool bar ->add button.set sy-ucomm.
11-26-2007 10:56 AM
11-26-2007 10:57 AM
<b>refer following template for Object Oriented approach to add a push button on ALV toolbar</b>
----
DATA DECLARTION FOR ALV GRID CONTROL *
----
data gr_alvgrid type ref to cl_gui_alv_grid.
data gc_custom_control_name type scrfname value 'CC_CTRL'."Custom container
data gr_ccontainer type ref to cl_gui_custom_container.
data gt_fieldcat type lvc_t_fcat.
data gs_layout type lvc_s_layo.
include <icon>.
****************************************************************
LOCAL CLASSES: Definition For ALV
****************************************************************
*Create local class which will define methods for events u wanna use
class
cl_event_receiver1 definition.
public section.
data: ucomm type sy-ucomm.
data: selfield type slis_selfield.
data: ls_it_trans like line of it_trans.
*Double click method (ALV)
methods:
handle_double_click "Double click event
for event double_click of cl_gui_alv_grid
importing e_row e_column,
*Display button (ALV)
handle_toolbar "Display button on toolbar
for event toolbar of cl_gui_alv_grid
importing e_object,
handle_user_command "Handle button click
for event user_command of cl_gui_alv_grid
importing e_ucomm.
private section.
endclass. "cl_event_receiver1 DEFINITION
----
CLASS CL_EVENT_RECEIVER1 IMPLEMENTATION
----
*Class implementation that will contain method implementation of events
class cl_event_receiver1 implementation.
handle double_click
method handle_double_click.
data: g_repid like sy-repid.
g_repid = sy-repid.
call method cl_gui_cfw=>flush."Sends buffered data to front end(Precautionary)
if sy-subrc ne 0.
call function 'POPUP_TO_INFORM'
exporting
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
endif.
perform pick_object using e_row e_column.
endmethod. "handle_double_click
*Button Click Handler (ALV)
method handle_toolbar. toolbar method
data: ls_toolbar type stb_button.
clear ls_toolbar.
move 3 to ls_toolbar-butn_type.
append ls_toolbar to e_object->mt_toolbar.
clear ls_toolbar.
move 'DISP' to ls_toolbar-function. OK-CODE of Button
move icon_display to ls_toolbar-icon. icon of Button
move 'Transaction Details' to ls_toolbar-quickinfo. Quick info
move 'Details' to ls_toolbar-text. Button text
move ' ' to ls_toolbar-disabled.
append ls_toolbar to e_object->mt_toolbar.
endmethod. "handle_toolbar
method handle_user_command. Button click method
data: lt_rows type lvc_t_row.
data : ls_rows type line of lvc_t_row.
data: gs_rows like line of lt_rows.
data: g_repid like sy-repid.
g_repid = sy-repid.
get selected row
call method gr_alvgrid->get_selected_rows
importing
et_index_rows = lt_rows.
case e_ucomm.
when 'DISP'.
read table lt_rows into ls_rows index 1 transporting index.
read table it_trans into ls_it_trans index ls_rows-index.
call method cl_gui_cfw=>flush.
if sy-subrc ne 0.
call function 'POPUP_TO_INFORM'
exporting
titel = g_repid
txt2 = sy-subrc
txt1 = 'Error in Flush'(500).
else.
perform show_relevant_details using ls_it_trans-prod_typ.
endif.
endcase.
endmethod. "handle_user_command
endclass. "cl_event_receiver1 IMPLEMENTATION
data : gcl_receiver type ref to cl_event_receiver1. "Reference for the local event receiver class
data : event_receiver type ref to cl_event_receiver1.
<b>DATA COLLECTION IN Internal Table FOR DISPLAY ON GRID</b>
end-of-selection.
<b>*Call to Custom control screen</b>
call screen 9000.
----
PREPARE ALV LAYOUT AND CATALOG *
----
initialization.
perform prepare_layout changing gs_layout. "Grid Layout
perform prepare_field_catalog changing gt_fieldcat. "Field Catalog
&----
*& Form alv_display
&----
text
----
--> p1 text
<-- p2 text
----
form alv_display tables p_itab structure it_trans. Reuse ALV Grid
call method gr_alvgrid->set_table_for_first_display
exporting
is_layout = gs_layout
changing
it_outtab = p_itab[]
it_fieldcatalog = gt_fieldcat[]
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
if sy-subrc <> 0.
*--Exception handling
endif.
endform. "alv_display
*& Form prepare_field_catalog
&----
text
----
<--P_GT_FIELDCAT text
----
form prepare_field_catalog changing p_gt_fieldcat type lvc_t_fcat. "Define Grid's Field Catalog
data ls_fcat type lvc_s_fcat.
*Transaction Number
ls_fcat-fieldname = 'TRANS_NO'.
ls_fcat-ref_table = 'IT_TRANS'.
ls_fcat-coltext = 'Transaction Number'.
ls_fcat-seltext = 'Transaction Number'.
ls_fcat-just = 'C'.
ls_fcat-key = 'X'.
append ls_fcat to p_gt_fieldcat.
clear ls_fcat.
endform. " prepare_field_catalog
&----
*& Form prepare_layout
&----
text
----
<--P_GS_LAYOUT text
----
form prepare_layout changing p_gs_layout type lvc_s_layo. "Define grid layout
p_gs_layout-zebra = 'X'.
p_gs_layout-grid_title = 'Transaction Details Report'.
p_gs_layout-smalltitle = ''.
p_gs_layout-excp_conds = 'X'.
p_gs_layout-sel_mode = 'D'.
p_gs_layout-sgl_clk_hd = 'X'.
p_gs_layout-cwidth_opt = 'X'.
endform. " prepare_layout
&----
*& Form clear_grid
&----
text
----
--> p1 text
<-- p2 text
----
form clear_grid. "Free memory reserved for ALV
call method gr_ccontainer->free
exceptions
cntl_error = 1
cntl_system_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. " clear_grid
&----
*& Module STATUS_9000 OUTPUT
&----
text
----
*Initialise container in PBO of custom container screen
module status_9000 output.
set pf-status 'PF9000'.
if gr_ccontainer is initial.
*----Creating custom container instance
create object gr_ccontainer " container initialization
exporting
container_name = gc_custom_control_name
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6 .
if sy-subrc <> 0.
*--Exception handling
endif.
*----Creating ALV Grid instance
create object gr_alvgrid "grid initialization
exporting
i_parent = gr_ccontainer
exceptions
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
others = 5 .
if sy-subrc = 0.
create object gcl_receiver. "Instantiating event class <b>(for double click)</b>
create object event_receiver.
set handler gcl_receiver->handle_double_click for gr_alvgrid. "Activating event handler<b>(double click)</b>
set handler event_receiver->handle_user_command for gr_alvgrid. "Activating event of <b>Display button</b>
set handler event_receiver->handle_toolbar for gr_alvgrid. "Activating event of toolbar for <b>Display button</b>
perform alv_display tables it_trans.
*To display btn
call method gr_alvgrid->set_toolbar_interactive.
call method cl_gui_control=>set_focus
exporting
control = gr_alvgrid.
endif.
endif.
endmodule. " STATUS_9000 OUTPUT
&----
*& Module USER_COMMAND_9000 INPUT
&----
text
----
module user_command_9000 input. Check OK-CODE of PF Status buttons
ok_code = sy-ucomm.
case ok_code.
when 'BACK' or 'EXIT'.
leave to screen 0.
when 'CANCEL'.
leave program.
endcase.
endmodule. " USER_COMMAND_9000 INPUT
&----
*& Form PICK_OBJECT
&----
text
----
-->P_E_ROW Row number, which is double clicked by user
-->P_E_COLUMN
----
form pick_object using p_e_row "Double click navigation
p_e_column.
<b>* Code to be executed after double click</b>
endform. "pick_object
&----
*& Form show_relevant_details
&----
text
----
--> p1 text
<-- p2 text
----
form show_relevant_details using p_prod_typ. "Button click navigation
<b>* Code to be executed after button click</b>
endform. " show_relevant_details
11-26-2007 10:57 AM
Hi
<b>u can add push button to alv toolbar for this
u have to use structure STB_BUTTON</b>
check the documentation for PF-STATUS of that FM .U will get some idea.
&----
*& form z_alv_events
&----
form alv_events.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = fevents[].
read table fevents with key name = 'PF_STATUS'.
if sy-subrc = 0.
fevents-form = 'Z_PF_STATUS'.
modify fevents index sy-tabix.
clear fevents.
endif.
endform. "alv_events
&----
*& Form Z_PFSTATUS
&----
text
----
-->EXTAB text
----
form z_pf_status using extab type slis_t_extab.
data i_extab type slis_t_extab with header line.
i_extab[] = extab[].
append '&POST' to i_extab.
set pf-status g_statu_07.
endform. "Z_PF_STATUS
call will be like this
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = lv_repid
i_callback_user_command = 'Z_USER_COMMAND'
i_callback_pf_status_set = 'Z_PF_STATUS'
So here u have to Copy standard Pf-status then pass that one to g_statu_07Regards
11-26-2007 11:02 AM
Hi,
In SE38 tcode give bcalv* it will display the list of standard ALV grid programs
refer that.
Regards,
Prashant
11-26-2007 11:21 AM