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 row selection event

Panneer
Advisor
Advisor
0 Kudos

Hi,

I have alv grid using cl_gui_alv_grid. I want to capture the row selection event and display the detail below the table.

how do I capture the row selection.? I want to display the details below as and when the row selection changed.

Regards

Panneer

17 REPLIES 17

kesavadas_thekkillath
Active Contributor
0 Kudos

There is a lot in [SDN|http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=55249]

uwe_schieferstein
Active Contributor
0 Kudos

Hello Paneer

The event you are looking for is delayed_changed_sel_callback

For a sample report you may have a look at RSEIDOC2 (= tcode WE02 ).


***INCLUDE CLASS_ALV .
* LOCAL CLASSES: Definition für ALV Ereignisse
CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.

    METHODS:
    handle_delayed_changed_sel_cb
        FOR EVENT delayed_changed_sel_callback OF cl_gui_alv_grid,
...


METHOD handle_delayed_changed_sel_cb.

data: lt_rows TYPE lvc_t_row.
data: l_row   TYPE lvc_s_row.

  CALL METHOD grid->get_selected_rows
           IMPORTING et_index_rows = lt_rows.
  CALL METHOD cl_gui_cfw=>flush.
  read table lt_rows index 1 transporting no fields.
  if sy-subrc ne 0.
    exit.
  endif.
  perform fill_special_values tables lt_rows.

  need_refresh = 'N'.

  set screen 100.
  leave screen.

ENDMETHOD.

It goes without saying that you must suppress multiple row selection in order to use this event.

Regards

Uwe

0 Kudos

Hi Uwe,

thanks for your response, I tried with delayed_changed_sel_callback. But it did not work. I did not get the event in my handler method. But you mentioned about disabling multiselection. Could you please tell how can I suppress the multiselection.

Regards

Panneer

Former Member
0 Kudos

Hi Panneer,

If you are displaying your output on a screen say screen 0100, then in the PAI of the screen in the user-command write the following code,

This is the pre-requiste


ls_variant-report = sy-cprog.

gs_layout-zebra = 'X'.

gs_layout-sel_mode = 'A'. this will allow line selection to be active

CALL METHOD alv_grid_E->set_table_for_first_display

EXPORTING

is_layout = gs_layout pass the above GS_LAYOUT here

is_variant = ls_variant

i_save = 'A'

  • i_default = 'X'

it_toolbar_excluding = lt_exclude

CHANGING

it_outtab = it_monthly

it_fieldcatalog = it_fieldcat.

CLEAR gt_fieldcat.


Then in the PAI of screen 100 write this,

when 'POST'. button placed in the Application Toolbar for an event after selecting the required rows

DATA:et_index_rows TYPE lvc_t_row,

et_row_no TYPE lvc_t_roid,

wa_et_row_no LIKE LINE OF et_row_no,

n TYPE i,

row_id TYPE i.

DATA: alv_vbeln TYPE vbeln,

mess_text(30) TYPE c,

txt_vbeln(10) TYPE c.

DATA : wa_acchd LIKE acchd.

CLEAR:et_index_rows,et_row_no.

CALL METHOD alv_grid_e->get_selected_rows

IMPORTING

et_index_rows = et_index_rows

et_row_no = et_row_no.

DESCRIBE TABLE et_index_rows LINES n.

IF n GT 0.

LOOP AT et_row_no INTO wa_et_row_no.

READ TABLE it_monthly INTO wa_monthly INDEX wa_et_row_no-row_id.

IF sy-subrc = 0.

PERFORM subroutine.

endif.

endloop.

endif.

ENDCASE.

Hope it helps you,

Please revert if you have any queries.

Regards,

Abhijit G. Borkar

0 Kudos

Hi,

Thanks for the suggestions. But I dont want to press another button after selecting a row. is delayed_callbackthe only way to solve this problem?

Regards,

Panneer

0 Kudos

Hi,

There must be some event that will be triggered when you have selected a row if you don't want to use the above method suggested by me then you will have to follow the method suggested by Uwe.

If you don't want to use that also then you may have to find a work-around or an event that is suitable in your case(e.g. Double click, etc).

Hope it helps you,

Abhijit G. Borkar

0 Kudos

Hi Abhijit,

My problem is also similar kind of. Method CALL METHOD Grid->get_selected_rows giving right no. selected records first time and process these records by POST button and hence show these records in next alv grid. but when i came back to 1st ALV by pressing BACK button on 2nd ALV then if I again select records on the same 1st ALV grid the same Method CALL METHOD Grid->get_selected_rows fires again. but this times it wouldn't give the selected records. I mean first time this gives me correct no. of selected records but 2nd time wouldn't.

Kindly suggest me.

Thanx.

Robin

former_member1245113
Active Contributor
0 Kudos

Hi Panneer,

Check the below thread. Once you select the Radio Button the User Command is triggered.

http://wiki.sdn.sap.com/wiki/display/Snippets/ABAP-RadioButtonsinALVGRIDREPORT

In the Form user Command 
 CLEAR selfield. " Clear the SELFIELD.
Here after you select a radio button PAI is triggered.
By clearing you can avoid multiselection.
TO highlight the selected row just change the row color

Cheerz

Ram

former_member583013
Active Contributor
0 Kudos

You have the option of using the double click event if you wish...

* EVENT RECEIVER
  create object: event_receiver.

* EVENT
  set handler: event_receiver->handle_double_click for gc_grid.

  call method gc_grid->set_table_for_first_display
    exporting
      is_layout       = ls_layout
      is_variant      = ls_variant
      i_save          = 'A'
      i_default       = 'X'
    changing
      it_outtab       = gt_alv_data
      it_fieldcatalog = lt_fcat
      it_sort         = lt_sort.

************************************************************************
*** CLASS lcl_event_receiver DEFINITION
************************************************************************
class lcl_event_receiver definition.

  public section.

    methods:

      handle_double_click
        for event double_click of cl_gui_alv_grid
        importing e_row.

endclass.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*

class lcl_event_receiver implementation.

*---------------------------------------------------------------------*
* DEFINE handle_toolbar
*---------------------------------------------------------------------*
  method handle_double_click.

    check e_row-index gt 0.

    read table gt_alv_data into wa_alv_data index e_row-index.
    if sy-subrc = 0.

      set parameter id 'VK1' field wa_alv_data-salesdeal.
      call transaction 'VB23' and skip first screen.

    endif.

  endmethod.                    "HANDLE_TOOLBAR

endclass.                    "lcl_event_receiver_main IMPLEMENTATION

0 Kudos

Hi All,

thanks for all the responses. I will clarify my requirement. I am developing this UI in accessible complaint way, meaning without using mouse, the user should be able to use the UI. I currently have the following problem.

1. How can I disable multiple selection. All the selection mode 'A' to 'D' allows multiple selections. Even if I say 'no_rowmark' it allows multiple selection via keyboard (Shift+Space). How can I achive single selection in AlV grid. Also I dont want the user to select mulitple rows and then get the error.

Regards,

Panneer

0 Kudos

Hello,

Did you get a chance to disable multiple selection from the alv grid display.

If you did, please let me know how you got it.

Regards

0 Kudos

Hi

About single selection mode, I think is to late for this answer, but I hope it will be useful for future searchs, if you want to allow only 1 row selected at time you should assign B to Selection Mode:

gs_layout-sel_mode = 'B'.

Using this option the grid alow to select just a row, it doesn't matter if you try with the mouse or the keyboard, but you wouldn't find a selection button, you must click the row you want to select.

Regards

0 Kudos

More detail example, also works with multiple selections:

data go_alv type ref to cl_gui_alv_grid.
data go_handler type ref to lcl_event_receiver.

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
class lcl_event_receiver definition.
  public section.
    methods delayed_change_select
            for event delayed_changed_sel_callback of cl_gui_alv_grid.
endclass.                    "lcl_event_receiver DEFINITION

*----------------------------------------------------------------------*
*       CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
class lcl_event_receiver implementation.
  method delayed_change_select.
    message 'Selection changed' type 'S'.
  endmethod.                    "delayed_change_selection
endclass.                    "lcl_event_receiver IMPLEMENTATION

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
module status_0100 output.
  data lt_fcat_lvc type lvc_t_fcat.
  data lt_fcat_alv type slis_t_fieldcat_alv.
  data ls_layo type lvc_s_layo.

  set pf-status 'MAIN'.

  if go_alv is initial.
    ...

    ls_layo-sel_mode = 'A'.
*   ls_layo-sel_mode = 'B'.    "Also works
*   ls_layo-sel_mode = 'C'.    "Also works
*   ls_layo-sel_mode = 'D'.    "Also works

    ...

    call method go_alv->set_table_for_first_display
      exporting
        is_layout       = ls_layo
      changing
        it_fieldcatalog = lt_fcat_lvc
        it_outtab       = gt_data[].

    create object go_handler.
    set handler go_handler->delayed_change_select for go_alv.
  

    call method go_alv->register_delayed_event

      exporting

        i_event_id = cl_gui_alv_grid=>mc_evt_delayed_change_select.
  endif.
endmodule.                 " STATUS_0100  OUTPUT

0 Kudos

This works perfectly...   thank you Evgeni.  (no need for user button at all).

code is executed roughly 3 seconds after the event - i guess thats why they call is delayed.

0 Kudos

Glad to help you.

You can set any delay inreriting your own class from the standard ALV and set value at the constructor.

*--------------------------------------------------------------*

*       CLASS lcl_gui_alv_grid IMPLEMENTATION

*--------------------------------------------------------------*

class lcl_gui_alv_grid implementation.

  method constructor.

    super->constructor( i_parent ).

    me->set_delay_change_selection( 300 ).

  endmethod.                    "constructor

endclass.                    "lcl_gui_alv_grid IMPLEMENTATION

Former Member
0 Kudos

Hi,the most important thing is that pass the correct vaue to the ' gs_layout'. Code as below:

*§ALV Layout:

     CLEAR gs_layout.

     gs_layout-zebra = 'X'.

     gs_layout-cwidth_opt = 'X'.

*    gs_layout-no_rowmark = 'X'.

*    gs_layout-sel_mode   = 'B'.

*    gs_layout-box_fname = 'ZSEL'.

     l_event-eventid = cl_gui_alv_grid=>mc_evt_delayed_change_select.

     CALL METHOD g_alv_grid->register_delayed_event

       EXPORTING

         i_event_id = l_event-eventid

       EXCEPTIONS

         OTHERS     = 1.

     "ALV FIELDCAT:

     PERFORM frm_alv_fieldcat.

     "ALV EXCLUDE BUTTON

     PERFORM frm_alv_exclude.

     "ALV DISPLAY

*    PERFORM frm_alv_display.

     CREATE OBJECT event_receiver.                                  "vh

     SET HANDLER event_receiver->handle_delayed_changed_sel_cb      "vh

                                FOR g_alv_grid.

     SET HANDLER event_receiver->handle_user_command FOR g_alv_grid.      "vh

     SET HANDLER event_receiver->handle_toolbar FOR g_alv_grid.           "vh

     SET HANDLER event_receiver->handle_double_click FOR g_alv_grid.      "vh

     CALL METHOD g_alv_grid->set_table_for_first_display

       EXPORTING

         is_layout            = gs_layout

         it_toolbar_excluding = gt_exclude

         i_default            = 'X'

         i_save               = 'A'

       CHANGING

         it_fieldcatalog      = gt_fieldcat[]

         it_outtab            = gt_output[].

Former Member
0 Kudos

Hi Experts,

Currently developing my ABAP skills,

I have a formula which contains brackets ((([SEL34])/1000)/([SEL27]+([SEL28]*6.0924)))

I would like to have code which checks the opening brackets and closing brackets.

it should if the opening and closing brackets does not match its should prompt and error message that opening and closing brackets are not equal or something.

at the moment I have already a loop which looks like this.

FORM GET_EXISTING_RECORDS.

   SELECT *

     FROM table_config

     INTO Table lt_table_config.

   SELECT *

       FROM Table_header

       INTO TABLE LT_table_header.

* First Check on Selection IDs between Header and Config Tables.


   LOOP AT LT_table_header. ASSIGNING <FS>. "INTO GWA_LT_table_header..

     ASSIGN COMPONENT 'xx100004' OF STRUCTURE <FS> TO <FS_1>.


     READ TABLE lt_table_config INTO GWA_table_config WITH KEY XX100004 = <FS_1>."GWA_Table_config-XX100004.

     IF SY-SUBRC <> 0.

       WRITE:   <FS_1>, 'HEADER ID not found in Config Table '.

     ENDIF.

   ENDLOOP.

ENDFORM.


here i would like to have a form that checks the brackets opened and closed in a formula

table_header contains all the formulas.



I hope to receive some advise.


Rabie Hamidi