Skip to Content
avatar image
Former Member

fill second ALV grid after double click on the first alv grid

Hi

i have 2 alv grids on one screen, i need to fill the second alv grid with detailed data

after double click on any row of the first alv grid
( i will show some details related sales order items)

how can i do that.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Aug 16, 2017 at 10:16 AM

    Hello,

    If you work with class cl_gui_alv_grid (and you should) you can create a simple MVC architecture of that kind :

    - 1 global Model object dealing with data

    - 2 Controller objects dealings with interactions of each ALV

    - 2 View objects dealings with display and refresh

    - 1 Main Program object binding all this (creating all implementations and handling events )

    Your model should be very basic, like :

    CLASS lcl_model DEFINITION.
      PUBLIC SECTION.
        DATA t_table_header TYPE TABLE OF Zstructure_header.
        DATA t_table_detail TYPE TABLE OF Zstructure_detail.
        METHODS : constructor. " fill t_table_header 
    

    As the 2 views are very similar you can use the same local class definition for them. So for the controllers.

    Something like :

    CLASS lcl_view_ALV_Grid DEFINITION.
      PUBLIC SECTION.
        DATA :
               grid           TYPE REF TO cl_gui_alv_grid,      " ALV
               structure_name TYPE dd02l-tabname,               " Structure DDIC
               source.                                          " (H)eader or (D)etail
    
        CONSTANTS : c_source_header VALUE 'H',
                    c_source_detail   VALUE 'D'.
    
        METHODS : 
                "  Do CREATE OBJECT grid EXPORTING i_parent = i_graphic_parent.
                  constructor IMPORTING i_graphic_parent TYPE REF TO cl_gui_container,
                " call grid->set_table_for_first_display, grid->refresh_table_display and cl_gui_cfw=>flush
                  refresh     CHANGING it_display TYPE ANY TABLE. 
    ENDCLASS.  
    CLASS lcl_controler_ALV_Grid DEFINITION.
      PUBLIC SECTION.
        DATA model TYPE REF TO lcl_model. 
        DATA view  TYPE REF TO lcl_view_ALV_Grid .
    
    
        METHODS : 
    * Constructor had to : model =  i_model, CREATE OBJECT view exporting i_graphic, view->source = i_source_type
        constructor IMPORTING i_model TYPE REF TO lcl_model       " Ref to the unique implementation of lcl_model
                              i_source_type TYPE char1            " H or D
                              i_graphic TYPE REF TO cl_gui_container,
    
    * Call view->refresh 
        call_refresh.
    ENDCLASS.           
    
    CLASS lcl_main DEFINITION.
      PUBLIC SECTION.
        DATA : model TYPE REF TO lcl_model,
               container TYPE REF TO cl_gui_custom_container,
               splitter TYPE REF TO cl_gui_splitter_container,
               controler_1 TYPE REF TO lcl_controler,
               graphic_parent1 TYPE REF TO cl_gui_container,
               controler_2 TYPE REF TO lcl_controler,
               graphic_parent2 TYPE REF TO cl_gui_container.
    
    
        METHODS: constructor,
                 display,
                 
                 " Change model->t_table_detail and call controler_2->call_refresh
                 filter_view_detail FOR EVENT double_click OF cl_gui_alv_grid 
                         IMPORTING e_row
                                   e_column
                                   es_row_no.
    
    ENDCLASS.  
    

    And

    CLASS lcl_main IMPLEMENTATION.
    * Initialisation
      METHOD constructor.
        CREATE OBJECT model.
        CREATE OBJECT container
          EXPORTING
            container_name = 'CUSTOM'.
    
    *--------------------------------------------------------------------*
    **   create splitter container in which to place graphics
        CREATE OBJECT splitter
          EXPORTING
            parent  = container
            rows    = 2
            columns = 1
            align   = 15. " (splitter fills the hole custom container)
    **   get part of splitter container for 1st table
        CALL METHOD splitter->get_container
          EXPORTING
            row       = 1
            column    = 1
          RECEIVING
            container = graphic_parent1.
    **   get part of splitter container for 2nd table
        CALL METHOD splitter->get_container
          EXPORTING
            row       = 2
            column    = 1
          RECEIVING
            container = graphic_parent2.
    
    *--------------------------------------------------------------------*
        CREATE OBJECT controler_1
          EXPORTING
            i_model   = model
            i_type    = 'H'
            i_graphic = graphic_parent1.
        CREATE OBJECT controler_2
          EXPORTING
            i_model   = model
            i_type    = 'D'
            i_graphic = graphic_parent2.
    
    
    *--------------------------------------------------------------------*
        SET HANDLER filter_view_detail  FOR controler_1->view->grid.
      ENDMETHOD.   
    

    And your report should look like :

    INITIALIZATION.
      CREATE OBJECT main.
    START-OF-SELECTION.
    [...]
    * Transfer data from selection screen to some main's methods to fill some Model attributes.
    END-OF-SELECTION.
     main->display( ).

    Once you understand the basics you can re-factorize your code using best practices. Like create more events to distinct action from the user (handling in your controller) to reaction to model's attributes changes (your controller should listen event from Model) as your main program object should not involve in your MVC reactions)

    Best regards

    Bertrand

    Add comment
    10|10000 characters needed characters exceeded

    • Ok.

      It seems your code has been modified a lot and you are no more able to see mistakes.

      For example your "get_tab2" method fill "itab1". I'm pretty sure that's not what this method is supposed to do. ;)

      Moreover you use global variables in some methods, that's a huge source of problems. It can be ok for now but why to use CLASS and METHOD if you don't follow their rules (make them stronger than old performs/FM)? For example you use wa_fcat_tab1 to fill it_fcat_tab2 : you should create local wa_fcat_tab variable in each method.

      My advice : create a new local test program with few columns an static data just to create a proof of concept. Once you are able to create an interaction between 2 ALV grids you will be able to modify any productive program to add this functionality.

      Keep in mind that event double_click from grid1 has to be listen by a method which will modify itab2 and call grid2->set_table_for_first_display

      Best regards

  • avatar image
    Former Member
    Aug 16, 2017 at 07:55 AM

    Enable the Exporting Parameter ' i_callback_user_command' where your calling first FM for ALV_Display and the in Form & Endform get the details of the Selected row

    and the fill an another internal table with those details and then display the details in second alv grid using 'set_table_for_first_display' using this interal table

    and then call method alv_grid->refresh_table_display.

    Add comment
    10|10000 characters needed characters exceeded