‎2008 Jul 17 6:12 AM
Hi Friends
I have created two buttons on the ALV toolbar and have written code on event USER_COMMAND.
But when I click on the button the desired functionality is not working.
Please check the code below.
-
*
CLASS lcl_alv_toolbar DEFINITION
----
ALV event handler
----
CLASS lcl_alv_toolbar DEFINITION.
PUBLIC SECTION.
*Constructor
METHODS: constructor
IMPORTING
io_alv_grid TYPE REF TO cl_gui_alv_grid,
*Event for toolbar
on_toolbar
FOR EVENT toolbar
OF cl_gui_alv_grid
IMPORTING
e_object.
METHODS USER_COMMAND
FOR EVENT USER_COMMAND OF cl_gui_alv_grid
IMPORTING E_UCOMM.
ENDCLASS. "lcl_alv_toolbar DEFINITION
----
CLASS lcl_alv_toolbar IMPLEMENTATION
----
ALV event handler
----
CLASS lcl_alv_toolbar IMPLEMENTATION.
METHOD constructor.
Create ALV toolbar manager instance
CREATE OBJECT c_alv_toolbarmanager
EXPORTING
io_alv_grid = io_alv_grid.
ENDMETHOD. "constructor
METHOD on_toolbar.
Add customized toolbar buttons.
variable for Toolbar Button
t_toolbar-icon = icon_generate.
t_toolbar-butn_type = 0.
t_toolbar-text = 'UPDATE'.
t_toolbar-function = text-009.
APPEND t_toolbar TO e_object->mt_toolbar.
t_toolbar-icon = ICON_COLUMN_RIGHT.
t_toolbar-butn_type = 0.
t_toolbar-text = 'DISPLAY_LOG'.
t_toolbar-function = text-010.
APPEND t_toolbar TO e_object->mt_toolbar.
Call reorganize method of toolbar manager to
display the toolbar
CALL METHOD c_alv_toolbarmanager->reorganize
EXPORTING
io_alv_toolbar = e_object.
ENDMETHOD.
METHOD USER_COMMAND.
PERFORM UPDATE USING E_UCOMM.
ENDMETHOD. "on_toolbar
ENDCLASS. "lcl_alv_toolbar IMPLEMENTATION
FORM UPDATE USING P_E_UCOMM TYPE sy-ucomm.
CASE sy-ucomm.
CASE P_E_UCOMM.
WHEN text-009.
PERFORM UPDATE_DATA.
WHEN text-010.
PERFORM DISPLAY_LOG.
ENDCASE.
ENDFORM.
‎2008 Jul 17 6:19 AM
Heloo,
For catching the events u need to set the handler
SET HANDLER lcl_alv_toolbar =>USER_COMMAND FOR toolbar.
‎2008 Jul 17 6:17 AM
Check whether u have register the event with ur ALV grid object or not..
SET HANDLER handler1 handler2 ... FOR oref|{ALL INSTANCES}
[ACTIVATION act].
Regards,
Joy.
‎2008 Jul 17 6:19 AM
Heloo,
For catching the events u need to set the handler
SET HANDLER lcl_alv_toolbar =>USER_COMMAND FOR toolbar.
‎2008 Jul 17 6:30 AM
Hi Manisha.
I would like to suggest you a few references which relate to your case,
[SDN Wiki - Standard Reference for TOOLBAR & USER COMMAND in ALV|https://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action?pageId=37715]
[SDN - Reference for code functionality for Buttons in ALV toolbar|;
[SDN - Reference for writing code functionality for two pushbuttons in Application toolbar in ALV & error in triggering of Event at user command|;
[SDN - Reference for Error in Event User command during creation of push buttons in ALV|;
Hope that's usefull.
Good Luck & Regards.
Harsh Dave
‎2008 Jul 17 7:08 AM
‎2008 Jul 17 7:35 AM
HI frnd ,
JST TRY THIS SMALL CODE .
REPORT ZPRI_ALV8.
type-pools : slis .
data: v_repid like sy-repid .
data: itab like mara occurs 0 with header line .
data: itab1 like makt occurs 0 with header line .
break devuser .
select * from mara into table itab .
v_repid = sy-repid .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = v_repid
I_CALLBACK_USER_COMMAND = 'DISPLAY_DOCUMENT '
I_STRUCTURE_NAME = 'mara'
TABLES
t_outtab = itab
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*****************************************************
FOR DISPLAYING sECONDRY LIST .
FORM DISPLAY_DOCUMENT USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
IF RS_SELFIELD-FIELDNAME = 'MATNR'.
READ TABLE ITAB INDEX RS_SELFIELD-TABINDEX .
select * from makt into table itab1 where matnr = itab-matnr .
IF SY-SUBRC = 0 .
ENDIF .
*
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'makt'
TABLES
T_OUTTAB = ITAB1
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endif.
ENDFORM.
THIS code will definetly help you to understand intractive alv ...
Regards
priyank Dixit