jueves, abril 14, 2011

ALV Objetos - Redefinir botón stándard

Para redefinir botón  standard del la barra de herramientas de un ALV OO:
***********************************************************************************
1) Definir capturador para el evento BEFORE_USER_COMMAND y generar otro evento:
***********************************************************************************
 CLASS lcl_event_receiver DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS:
    handle_before_user_command
        FOR EVENT before_user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm.
    handle_user_command
        FOR EVENT user_command OF cl_gui_alv_grid
            IMPORTING e_ucomm,
ENDCLASS.                    "lcl_event_receiver DEFINITION

***********************************************************************************
2) Definir implemetación de los eventos (llama a una rutina)
***********************************************************************************
CLASS lcl_event_receiver IMPLEMENTATION. 
  METHOD handle_before_user_command.
    PERFORM handle_before_user_command USING e_ucomm.
   ENDMETHOD.                    "handle_before_user_command


  METHOD handle_user_command.
    PERFORM user_command USING e_ucomm.
  ENDMETHOD.                           "handle_user_command
 ENDCLASS.
***********************************************************************************
3) Definir rutinas: recuperar el código del botón estándard y llama a otro.
***********************************************************************************
FORM handle_before_user_command USING p_ucomm TYPE syucomm.
  CASE p_ucomm .
    WHEN '&DETAIL'.
      CALL METHOD obj_alv_ims->set_user_command
        EXPORTING
          i_ucomm = 'SEL_DETAIL_IMS'.
   ENDCASE .
ENDFORM.                    " HANDLE_BEFORE_USER_COMMAND

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


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

***********************************************************************************
NOTA:
***********************************************************************************
- Para forzar PBO del dynpro LEAVE SCREEN.