Pour l’ajout d’un bouton spécifique dans la barre d’outils et pour sa gestion, il faut implémenter deux methodes.
METHODS handler_tool FOREVENT toolbar OF cl_gui_alv_grid IMPORTING e_object.
METHODS handle_user_command FOREVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.
Handler_tool : Création du bouton
Handler_user_command : Gestion du bouton
Exemple de code :
METHOD handler_tool. CLEAR ws_toolbar. ” => On affiche la ligne de séparation MOVE3TO ws_toolbar-butn_type. MOVEspace TO ws_toolbar-disabled. APPEND ws_toolbar TO e_object->mt_toolbar.
CLEAR ws_toolbar. “=> On affiche le bouton MOVE0TO ws_toolbar-butn_type. MOVE‘SAVE’TO ws_toolbar-function. MOVE icon_system_save TO ws_toolbar-icon. MOVE text-001 TO ws_toolbar-quickinfo. MOVE space TOws_toolbar-disabled. APPEND ws_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
METHOD handle_user_command. CASE e_ucomm. WHEN‘SAVE’. ” Traitement bouton 1 WHEN‘XXX’.” Traitement bouton X ENDCASE. ENDMETHOD.
Il faut bien penser à initer les évenements dans le constructeur par exemple.
METHODconstructor. SETHANDLER handler_tool FOR i_alv. SETHANDLER handle_user_command FOR i_alv.