jueves, abril 14, 2011

ALV Objetos - Añadir botón nuevo

**********************************************************************************
1) Definir capturador para el evento TOOLBAR y USER_COMMAND:
**********************************************************************************
 CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.
    CLASS-METHODS:

    handle_toolbar
        FOR EVENT toolbar OF cl_gui_alv_grid
            IMPORTING e_object e_interactive,

    handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm,
ENDCLASS.

**********************************************************************************
2) Definir implementación de los eventos (llama a una rutina)
**********************************************************************************
CLASS lcl_event_receiver IMPLEMENTATION.
  METHOD handle_toolbar.
    PERFORM handle_toolbar USING e_object.
  ENDMETHOD.                    "handle_toolbar
  METHOD handle_user_command.
    PERFORM user_command USING e_ucomm.
  ENDMETHOD.                           "handle_user_command
ENDCLASS.

**********************************************************************************
3) Definir rutinas: añadir botón  y tratar acción del botón
**********************************************************************************
 FORM handle_toolbar USING p_object TYPE REF TO cl_alv_event_toolbar_set.
  DATA: ls_toolbar TYPE stb_button.
  CLEAR ls_toolbar.
  MOVE 'PER' TO ls_toolbar-function.                        "#EC NOTEXT
  MOVE icon_display_text TO ls_toolbar-icon.
  MOVE 'Passenger Info'(201) TO ls_toolbar-quickinfo.
  MOVE 'Passenger Info'(201) TO ls_toolbar-text.
  MOVE ' ' TO ls_toolbar-disabled.                          "#EC NOTEXT
  APPEND ls_toolbar TO p_object->mt_toolbar.
ENDFORM.                    " HANDLE_TOOLBAR

FORM user_command USING p_ucomm TYPE syucomm.
  CASE p_ucomm.
    WHEN 'PER'.
      PERFORM sel_selected_rows_ims.
      LEAVE SCREEN.
  ENDCASE.
ENDFORM.                    " USER_COMMAND

**********************************************************************************
4) Registrar Eventos en el PBO
**********************************************************************************
  SET HANDLER: lcl_event_receiver=>handle_user_command FOR obj_alv_ims,
                             lcl_event_receiver=>handle_toolbar      FOR obj_alv_ims.