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: 

ALV Grid left Most Button

Former Member
0 Kudos

Hi All,

I had created a ALV grid control. I want to handle the left most button of the alv grid, which when clicked , entire row gets selected.

I have to do some functionality when this button is clicked. So, can anybody help me in handling this button event.

9 REPLIES 9

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

How about just making the row a hotspot. When user double clicks the row, trigger some functionality.

Here is a sample program



report zrich_0001.

data: begin of i_alv occurs 0,
      matnr type mara-matnr,
      maktx type makt-maktx,
      end of i_alv.

***********************************************************************
*       CLASS lcl_event_receiver DEFINITION      Handles Double Click
***********************************************************************
class lcl_event_receiver definition.
  public section.
    methods handle_double_click
      for event double_click of cl_gui_alv_grid
      importing e_row e_column.
  private section.
endclass.

***********************************************************************
*       CLASS lCL_EVENT_RECEIVER IMPLEMENTATION    Handles Double Click
***********************************************************************
class lcl_event_receiver implementation.
  method handle_double_click.
    perform drill_down using e_row-index.
  endmethod.
endclass.


data: alv_container  type ref to cl_gui_custom_container.
data: event_receiver type ref to lcl_event_receiver.
data: alv_grid       type ref to cl_gui_alv_grid.
data: layout    type lvc_s_layo.
data: fieldcat  type lvc_t_fcat.

selection-screen begin of block b1 with frame title text-001 .
select-options: s_matnr for i_alv-matnr.
selection-screen end of block b1.

start-of-selection.

  select * into corresponding fields of table i_alv
        from mara
          inner join makt
            on mara~matnr = makt~matnr
               where mara~matnr in s_matnr
                 and makt~spras = sy-langu.

  sort i_alv ascending by matnr.


  call screen 100.

************************************************************************
*      Module  status_0100  OUTPUT
************************************************************************
module status_0100 output.
  set pf-status '0100'.
  set titlebar '0100'.

  data: variant type  disvariant.

  variant-report = sy-repid.
  variant-username = sy-uname.

* Create Controls
  create object alv_container
         exporting
               container_name    = 'ALV_CONTAINER'.

  create object alv_grid
         exporting
               i_parent          =  alv_container.

*  Create Event Receiver
  create object event_receiver.

*  ALV Specific. Data selection.
*  Populate Field Catalog
  data: ls_fcat type lvc_s_fcat.
  refresh: fieldcat.

  clear: ls_fcat.
  ls_fcat-reptext    = 'Material Number'.
  ls_fcat-coltext    = 'Material Number'.
  ls_fcat-fieldname  = 'MATNR'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '18'.
  ls_fcat-col_pos    = 1.
  append ls_fcat to fieldcat.

  clear: ls_fcat.
  ls_fcat-reptext    = 'Material Description'.
  ls_fcat-coltext    = 'Material Description'.
  ls_fcat-fieldname  = 'MAKTX'.
  ls_fcat-ref_table  = 'I_ALV'.
  ls_fcat-outputlen  = '40'.
  ls_fcat-col_pos    = 2.
  append ls_fcat to fieldcat.


* Set table for display
  call method alv_grid->set_table_for_first_display
      exporting
           is_layout              = layout
           is_variant             = variant
           i_save                 = 'U'
           i_structure_name       = 'I_ALV'
      changing
           it_outtab       = i_alv[]
           it_fieldcatalog = fieldcat[].

*   handler for ALV grid
  set handler event_receiver->handle_double_click for alv_grid.

endmodule.

************************************************************************
*      Module  USER_COMMAND_0100  INPUT
************************************************************************
module user_command_0100 input.

  case sy-ucomm.
    when 'BACK' or 'CANC'.
      if not alv_container is initial.
        call method alv_container->free.
        clear: alv_container.
        free : alv_container.
      endif.
      if sy-subrc = 0.
        set screen 0.
        leave screen.
      else.
        leave program.
      endif.
    when 'EXIT'.
      if not alv_container is initial.
        call method alv_container->free.
        clear: alv_container.
        free : alv_container.
      endif.
      leave program.
  endcase.

endmodule.

************************************************************************
* DRILL_DOWN
************************************************************************
form drill_down using index.

  read table i_alv index index.
  if sy-subrc = 0.
    set parameter id 'MAT' field i_alv-matnr.
    call transaction 'MM03' and skip first screen.
    if not alv_container is initial.
      call method alv_container->free.
      clear: alv_container.
      free : alv_container.
    endif.
  endif.

endform.

Regards,

Rich Heilman

ssimsekler
Active Contributor
0 Kudos

Hi Kalyan

Maybe you can make use of the tutorial <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/an%20easy%20reference%20for%20alv%20grid%20control.pdf">"An Easy Reference for ALV Grid Control"</a>.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

0 Kudos

Hi,

Thanks for you help...but my requirement is that I have to click the left most button.

Kalyans

0 Kudos

<b>left most button</b> - > whats the button name?

do you mean the row selection button.

Regards

Raja

0 Kudos

Hi Durairaj,

Yes..i mean the row selection button. I want to handled the button click event of the row selection button.

Please help me ...

Rgds

Kalyan

Former Member
0 Kudos

Hi,

Use the method get_selected_lines:

DATA: gt_selline TYPE lvc_t_row. " Tabellenzeilen

CLEAR: gt_selline[].

CALL METHOD hnd_grid_sd->get_selected_rows

IMPORTING et_index_rows = gt_selline.

IF gt_selline[] IS INITIAL.

MESSAGE i000(38) WITH 'Not pressed!'.

else.

MESSAGE i000(38) WITH 'Pressed!'.

ENDIF.

Hope I could help you.

(If so, please mark your question as solved.

Reward points would be nice )

BR

Michael

0 Kudos

Hi Michael,

Sorry micheal this is not what i want. I want to handle the button click of the row selection button.

Rgds

Kalyan

0 Kudos

Hi Kalyan

It is not implemented such a way that row selection fields can not trigger any events. Instead, you can make some fields to be hotspot, but if you require to fire somethings as soon as a row is selected, as far as I know ther is no way.

By the way, I remember <a href="http://forums.sdn.sap.com/thread.jspa%3FthreadID%3D32162">one of your previous threads</a> is not closed. It seems you are not familiar with this and thus let me introduce you something about the SDN: You can assign points to posts you find helpful using the points scale at the left of each post. By assigning a 10-point or selecting "solved my own" at the left of your original post you close tyhe issue.

Regards

*--Serdar <a href="https://www.sdn.sap.com:443http://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.sdn.businesscard.sdnbusinesscard?u=qbk%2bsag%2bjiw%3d">[ BC ]</a>

0 Kudos

Hi Kalyan,

Sorry I forgot to explain, that this is a work-arround

for checking whether the Row is selected or not.

For catching the event itself no method exists

up to now.

Sorry about that!

The only way is, set the Layout-Property to NO-MARK

and create a Column as a icon. Than use the Doppelklick

or hot-spot method.

BR

Michael