Skip to Content
0

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

Aug 15, 2017 at 09:11 PM

247

avatar image
Former Member

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.

10 |10000 characters needed characters left characters exceeded

We can't guess what is the problem if you don't tell us what kind of code you are using.

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Bertrand DELVALLEE Aug 16, 2017 at 10:16 AM
0

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

Show 4 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Bertrand

Yes am using: CL_GUI_ALV_GRID

i have completed writing full code,am able to fill both ALV grids for the for the first time.
i need to refresh ALV GRID2 when user click on ALV GRID1 (sales order) field

i need to work with CL_GUI_ALV_GRID Events like (DOUBLE_CLICK, HOTSPOT_CLICK)
but am failing. if you can help in writing simple code about those events it will be very helpful

0

Hi,

The key parts on my samples are :

- The SET HANDLER part had to use your header grid implementation. No matters your architecture.

- The method handling this event had to be declare like this :

METHOD filter_view_detail FOR EVENT double_click OF cl_gui_alv_grid 
                     IMPORTING e_row
                               e_column
                               es_row_no.<br>

and implemented like this :

  METHOD filter_view_detail.
*e_row
*e_column
*es_row_no.
    FIELD-SYMBOLS <l_header> LIKE LINE OF model->t_table_header.

    READ TABLE model->t_table_header INDEX e_row ASSIGNING <l_header>.
*Now use <l_header> content to fill model->t_table_detail then call controler_2->call_refresh

  ENDMETHOD. 
<br>

With

  METHOD call_refresh.
    IF view->source = vue->c_source_header.
      view->structure_name = 'Zstructure_header'.
      view->refresh( CHANGING it_display = model->t_output_header ).
    ELSEIF view->source = vue->c_source_detail.
      view->structure_name = 'Zstructure_detail'.
      view->refresh( CHANGING it_display = model->t_output_detail ).
    ENDIF.
<br>

And

METHOD refresh.
    CALL METHOD grid->set_table_for_first_display EXPORTING
        i_bypassing_buffer = 'X'
        i_structure_name   = structure_name
      CHANGING
        it_outtab          = it_display.
    grid->refresh_table_display( ).
    cl_gui_cfw=>flush( ).
0
Former Member

Hi Bertrand

bellow is my complete code, kindly if you can go through it and guide me more since it is still confusing
a littel for me

main-code.txt

bpo-9000.txt

pai-9000.txt

thanks

main-code.txt (11.6 kB)
bpo-9000.txt (1.5 kB)
bpo-9000.txt (1.5 kB)
pai-9000.txt (196 B)
0

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

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

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.

Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Sharad

am using

am using CREATE OBJECT ob_grid2 which type of : cl_gui_alv_grid

then CALL METHOD ob_grid2->set_table_for_first_display

how to enable i_callback_user_command

0

I think Sharad is mixing objects and function modules. In Objects, user commands are handled by the User_Command event which needs binding to an event handler.

1