Skip to Content
0
Former Member
Feb 25, 2009 at 07:38 PM

ALV Grid Object Oriented

1653 Views

Hi there,

In a report type program I'm making, I have to show the data trough an ALV Control. I've decided to do it by the object oriented type.

So this is what I have. In the TOP INCLUDE, and in the main program:

CLASS lcl_receptor_eventos DEFINITION DEFERRED.

DATA: go_grid                   TYPE REF TO cl_gui_alv_grid,
           go_cont                  TYPE REF TO cl_gui_custom_container,
           go_context_menu    TYPE REF TO cl_ctmenu,
           go_event_receiver    TYPE REF TO lcl_receptor_eventos.

CALL SCREEN 1400.

In another include for the local classes to be declared, I have declared the class who will receive the events. I have done this in order to set handlers later, in order to add a button to the ALV's toolbar:

CLASS lcl_receptor_eventos DEFINITION.

  PUBLIC SECTION.

    METHODS:

      handle_menu_button
          FOR EVENT menu_button OF cl_gui_alv_grid
          IMPORTING e_ucomm e_object,

         handle_toolbar_set
          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 sender.

ENDCLASS.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lvl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_receptor_eventos IMPLEMENTATION.

  METHOD handle_user_command.
    CASE e_ucomm.
      WHEN 'SUBT'.
        gv_okcode = 'SUBT'.
      ENDCASE.
  ENDMETHOD.    

* Here I will add the button 

  METHOD handle_toolbar_set.
    DATA: gs_toolbar  TYPE stb_button.

    CLEAR gs_toolbar.
    MOVE 'SUBT' TO gs_toolbar-function.
    MOVE ICON_SUM TO gs_toolbar-icon.
    MOVE 1 TO gs_toolbar-BUTN_TYPE.
    MOVE 'Totales parciales' TO gs_toolbar-quickinfo.
    MOVE ' ' TO gs_toolbar-disabled.
    INSERT gs_toolbar INTO e_object->mt_toolbar INDEX 10.
    CALL METHOD cl_gui_control=>set_focus
      EXPORTING
        control = go_grid.

  ENDMETHOD.  

  METHOD handle_menu_button.
    IF e_ucomm = 'MBUT'.
      CALL METHOD e_object->add_function
        EXPORTING
          fcode = 'SUBT'
          text  = text-105.
    ENDIF.
  ENDMETHOD.

ENDCLASS.

In the 1400 screen's PBO there is two modules. One of them instantiates the objects and sets the handlers for the events:

MODULE instanciar_objetos OUTPUT.

  IF go_cont IS INITIAL.
    CREATE OBJECT go_cont
      EXPORTING
        container_name = 'ALV_CONTAINER'.

    CREATE OBJECT go_grid
      EXPORTING
        i_appl_events     = 'X'
        i_parent = go_cont.

    CREATE OBJECT go_event_receiver.

    SET HANDLER go_event_receiver->handle_toolbar_set FOR go_grid.
    SET HANDLER go_event_receiver->handle_user_command FOR go_grid.
    SET HANDLER go_event_receiver->handle_menu_button FOR go_grid.

    PERFORM introducir_datos_en_grilla TABLES gt_salida.
    PERFORM crear_tabla_dinamica.

  ENDIF.

ENDMODULE.

The another one is to set the status and the main window toolbar, so it's not relevant right now. In the PAI there is a module who register the events, in order to the handlers to be called at the beginning of the PAI and the ok_code to be set.

module REGISTRAR_EVENTOS input.

DATA return_code TYPE i.

 CALL METHOD cl_gui_cfw=>dispatch
      IMPORTING
        return_code = return_code.

endmodule.

So, here the question comes... I need, when the button I have added is pressed, to show a submenu beside it (exactly like the one that is shown when the standard sigma button in the ALV toolbar, I mean the sum button, is pressed). How can I do that??