Home > SAP > ALV – Ajout d’un bouton spécifique

ALV – Ajout d’un bouton spécifique

** En OBJET**

Pour l’ajout d’un bouton spécifique dans la barre d’outils et pour sa gestion, il faut implémenter deux methodes.

toolbar

 

 

 

  1.   METHODS  handler_tool FOR EVENT toolbar OF cl_gui_alv_grid
                                                      IMPORTING e_object.
  2.   METHODS handle_user_command FOR EVENT 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
    MOVE 3 TO ws_toolbar-butn_type.
    MOVE space TO ws_toolbar-disabled.
    APPEND ws_toolbar TO e_object->mt_toolbar.

    CLEAR ws_toolbar. “=> On affiche le bouton
    MOVE 0 TO 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 TO ws_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.

   METHOD constructor.
    SET HANDLER handler_tool FOR i_alv.
    SET HANDLER handle_user_command FOR i_alv. 

  ENDMETHOD.

Categories: SAP Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.