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 can I use the method 'set_selected_rows' in an internal table?

Former Member
0 Kudos

Hello,

I am having trouble using the method 'set_selected_rows'.
Here's what I have:

DATA: row TYPE lvc_t_roid.


CALL METHOD oref_alv->set_selected_rows
   EXPORTING
     it_row_no = row.

However, I don't know how to give the number of the row that I want to highlight (because there is always an error saying that I can't do 'row=3'), neither the internal table reference.

For example, I would like that, when my ABAP program executes, the third row of my internal table (inside oref_alv) becomes yellow/orange (the highlighting that happens when you click on a row.

Thank you very much!

1 ACCEPTED SOLUTION

0 Kudos

Hi,

Please try the below code in which I have made the 3rd row get selected by default when the program gets executed:

   *&---------------------------------------------------------------------*
*& Report  ZSELECTION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zselection.

DATA: it_selected TYPE lvc_t_row,
      wa_selected TYPE lvc_s_row,
      wa_sflight TYPE sflight,
      ltp_layout TYPE lvc_s_layo,
      gi_sflight TYPE STANDARD TABLE OF sflight,
      go_custom_container TYPE REF TO cl_gui_custom_container,
      go_grid             TYPE REF TO cl_gui_alv_grid.

*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------

START-OF-SELECTION.
  SET SCREEN '100'.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
* Create objects
  IF go_custom_container IS INITIAL.
    CREATE OBJECT go_custom_container
      EXPORTING
        container_name = 'ALV_CONTAINER'. "Create a screen 100 with custom container name 'ALV_CONTAINER'

    CREATE OBJECT go_grid
      EXPORTING
        i_parent = go_custom_container.

    PERFORM load_data_into_grid.
  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM load_data_into_grid .
  SELECT * FROM sflight INTO TABLE gi_sflight.

  ltp_layout-stylefname = 'CELLTAB'.
  ltp_layout-sel_mode = 'A'.

  LOOP AT gi_sflight INTO wa_sflight.
    IF sy-tabix EQ '3'.
      wa_selected-index = sy-tabix.
      APPEND wa_selected TO it_selected.
    ENDIF.
  ENDLOOP.
* Load data into the grid and display them
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'
      is_layout        = ltp_layout
      i_save           = 'A'
    CHANGING
      it_outtab        = gi_sflight.

  CALL METHOD go_grid->set_selected_rows
    EXPORTING
      it_index_rows = it_selected.

ENDFORM.                    " LOAD_DATA_INTO_GRID

NOTE: You need to create the screen 100 with custom container name as 'ALV_CONTAINER'.

Thanks,

Sathya.

4 REPLIES 4

former_member200345
Contributor
0 Kudos

Hi,

Check the standard program  BCALV_TEST_GRID_F4_HELP which may solve your queries.

uppu_narayan
Active Participant
0 Kudos

Hi Rafael,

       your is row is a internal table, and it should contain the rows that you want to select....

thanks and regards,

narayan

0 Kudos

Hi,

Please try the below code in which I have made the 3rd row get selected by default when the program gets executed:

   *&---------------------------------------------------------------------*
*& Report  ZSELECTION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  zselection.

DATA: it_selected TYPE lvc_t_row,
      wa_selected TYPE lvc_s_row,
      wa_sflight TYPE sflight,
      ltp_layout TYPE lvc_s_layo,
      gi_sflight TYPE STANDARD TABLE OF sflight,
      go_custom_container TYPE REF TO cl_gui_custom_container,
      go_grid             TYPE REF TO cl_gui_alv_grid.

*--------------------------------------------------------------------
* S T A R T - O F - S E L E C T I O N.
*--------------------------------------------------------------------

START-OF-SELECTION.
  SET SCREEN '100'.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
* Create objects
  IF go_custom_container IS INITIAL.
    CREATE OBJECT go_custom_container
      EXPORTING
        container_name = 'ALV_CONTAINER'. "Create a screen 100 with custom container name 'ALV_CONTAINER'

    CREATE OBJECT go_grid
      EXPORTING
        i_parent = go_custom_container.

    PERFORM load_data_into_grid.
  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  LOAD_DATA_INTO_GRID
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM load_data_into_grid .
  SELECT * FROM sflight INTO TABLE gi_sflight.

  ltp_layout-stylefname = 'CELLTAB'.
  ltp_layout-sel_mode = 'A'.

  LOOP AT gi_sflight INTO wa_sflight.
    IF sy-tabix EQ '3'.
      wa_selected-index = sy-tabix.
      APPEND wa_selected TO it_selected.
    ENDIF.
  ENDLOOP.
* Load data into the grid and display them
  CALL METHOD go_grid->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'
      is_layout        = ltp_layout
      i_save           = 'A'
    CHANGING
      it_outtab        = gi_sflight.

  CALL METHOD go_grid->set_selected_rows
    EXPORTING
      it_index_rows = it_selected.

ENDFORM.                    " LOAD_DATA_INTO_GRID

NOTE: You need to create the screen 100 with custom container name as 'ALV_CONTAINER'.

Thanks,

Sathya.

Former Member
0 Kudos

Hey guys,

It worked!!
Thanks so much for your help.