Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to select the object selected on ALV

Former Member
0 Kudos

Hi

I have two ALV grid on same screen object name G_grid and U_grid. I have created a local class and define the method for double click. I set the handler for event receiver in the the PBO for both G_grid and U_grid. fields name of both grids are same.

Now i want to know in single method that which object is double clicked.

regards

Ammad

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi,

You can use the implicit parameter sender to know the instance.


methods:handle_double_click for event double_click of cl_gui_alv_grid
               importing e_row e_column sender.

method handle_double_click.
case sender.
when 'OBJ1'.
"---
when 'OBJ2'.
"---
when others.
"Do nothing
endcase.
endmethod.

12 REPLIES 12

Former Member
0 Kudos

Hi,

We can use any number of objects for single class and when you are calling method with G-GRID its related double click method will call and same for U_GRID.

We can call single method by using different objects.

Warm Regards,

PavanKumar.G

0 Kudos

Hi

i think i didn't explain my question properly. i called the same method with different object, but problem is in same method i need to read the value of either g_grid or u_grid through following code .

i am unable to place a condition that either it should read g_grid or u_grid. as i cann't differentiated at run time that either g_grid is double clicked or u_grid is double clicked.

METHOD handle_double_click.

CALL METHOD g_grid->get_current_cell

IMPORTING

e_value = ws_value1.

ENDMETHOD.

Regards

Ammad

kesavadas_thekkillath
Active Contributor
0 Kudos

Hi,

You can use the implicit parameter sender to know the instance.


methods:handle_double_click for event double_click of cl_gui_alv_grid
               importing e_row e_column sender.

method handle_double_click.
case sender.
when 'OBJ1'.
"---
when 'OBJ2'.
"---
when others.
"Do nothing
endcase.
endmethod.

0 Kudos

what type of sender should be and which value we may pass it to it ???

0 Kudos

Hi Sorry

there is a correction

its


case obj1. "obj1 TYPE REF TO cl_gui_alv_grid 
---
case obj2. "obj2 TYPE REF TO cl_gui_alv_grid 
---
endcase.

We cannot pass any value to sender. Its a implicit parameter of the instance events.

In your case its G_grid and U_grid

0 Kudos

I think we need to mention the condition . so that we can select obj1 or obj2 accordingly. If you may please explain it more.

regards

Ammad

0 Kudos

Hi ,

in addition to Keshav,


  method double_click.
  case sender.
  case 1.
    perform double_click using 'GT_FPAYP' "Internal table name......
                               e_row      "selected row id 
                               e_column. "selected column id
case2.

endcase.
endmethod...

regards

Prabhu

0 Kudos

Hi,

I am not able to understand you

You will be setting the handlers for your two alv's like ex:


SET HANDLER XXX->handle_double_click FOR all instances. "G_grid and U_grid

Now when the row in ALV is double clicked your method gets triggered. Inside the method you will get the instance name of the ALV clicked. Suppose when you click a line of the ALV ( instance G_grid ) then sender will hold g_grid else if its clicked from other alv( instance u_grid ) then sender will hold u_grid. Now based on this parameter you can know from which alv the row was clicked. Now inside the condition you can differentiate the instance and code it

You can refer if you need the coded examples

Kesav

0 Kudos

SET HANDLER event_receiver->handle_double_click FOR G_grid.

I set the handler event as above but in sender i still not getting any thing. if you guys can guide me

Regards

Ammad

0 Kudos

Hi,

As said by keshav , it should work..

Check, have you defined your handler method with sender.

methods:

double_click for event double_click

of cl_gui_alv_grid

importing e_row

e_column

es_row_no

sender.

Check program BCALV_TEST_GRID_EVENTS for reference..

Regards,

Ravi.

0 Kudos

Hi ,

you need extrac code lines as mentioned by Keshav in this link...


* definition......
    METHODS double_click
      FOR EVENT double_click OF cl_gui_alv_grid
      IMPORTING *e_row e_column sender*.
    

0 Kudos

Check this code for example


class lcl definition deferred.

data:obj1 type ref to cl_gui_alv_grid,
     obj2 type ref to cl_gui_alv_grid,
     container1 type ref to cl_gui_custom_container,
     container2 type ref to cl_gui_custom_container,
     event_receiver type ref to lcl,
     it_fldcat type lvc_t_fcat,
     it type table of mara,
     it2 type table of marc.

*---------------------------------------------------------------------*
*       CLASS lcl_definition
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl definition.
  public section.
    methods: handle_double_click
        for event double_click of cl_gui_alv_grid
             importing e_row e_column sender.

endclass.

*---------------------------------------------------------------------*
*       CLASS lcl IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl implementation.
  method handle_double_click.
    data:row type i,
         value type matnr,
         col type i,
         wa type mara,
         wa2 type marc.
    call method sender->get_current_cell
        importing
          e_row     = row
          e_value   = value
          e_col     = col.
    case sender.
      when obj1.
        "'GRID 1 CLICKED ME !!! He He '.
        read table it into wa index row.
        if sy-subrc = 0.
          "--
        endif.
      when obj2.
        "'GRID 2 CLICKED ME !!! He He '.
        read table it2 into wa2 index row.
        if sy-subrc = 0.
          "--
        endif.
    endcase.
  endmethod.
endclass.

start-of-selection.
  call screen 100.
*&---------------------------------------------------------------------*
*&      Module  fill_data  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module fill_data output.
  select * from mara into table it up to 50 rows.
  select * from marc into table it2 up to 50 rows.
endmodule.                 " fill_data  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  display  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module display output.

  create object container1
         exporting
             container_name = 'CONT1'.
  create object obj1
              exporting i_parent = container1.

  call function 'LVC_FIELDCATALOG_MERGE'
       exporting
            i_structure_name       = 'MARA'
       changing
            ct_fieldcat            = it_fldcat[]
       exceptions
            inconsistent_interface = 1
            program_error          = 2
            others                 = 3.

  call method obj1->set_table_for_first_display
     changing
       it_outtab            = it[]
       it_fieldcatalog      = it_fldcat[].

  clear  it_fldcat.

  create object container2
         exporting
             container_name = 'CONT2'.
  create object obj2
              exporting i_parent = container2.

  call function 'LVC_FIELDCATALOG_MERGE'
       exporting
            i_structure_name       = 'MARC'
       changing
            ct_fieldcat            = it_fldcat[]
       exceptions
            inconsistent_interface = 1
            program_error          = 2
            others                 = 3.

  call method obj2->set_table_for_first_display
     changing
       it_outtab            = it2[]
       it_fieldcatalog      = it_fldcat[].

  create object event_receiver.
  set handler event_receiver->handle_double_click for all instances.