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: 

capturing selected rows from output

Former Member
0 Kudos

how to capture selcted rows from alv grid display.(oops)

1 ACCEPTED SOLUTION

MarcinPciak
Active Contributor
0 Kudos

Hi,

Do like this:

1) in layout structure set selection mode for multiple rows

ls_layout-sel_mode = 'A'.

2) then just call this method

call method alv->get_selected_rows importing et_row_no = lt_rows.

The parameter u201Cet_row_nou201D is of type LVC_T_ROID and returns row indexes for selected rows (but not cells or columns) in it.

Regards

Marcin

24 REPLIES 24

Former Member
0 Kudos

Hi,

Use method get_selected_rows.

Darren

0 Kudos

how can i select multiple rows in oops alv control

Former Member
0 Kudos

You may use get cursor for a single row and accordingly modify the flag corresponding to that row and thus for each selection the internal table is populated with the flag checked.

And then on the basis of the flag u can make the selection.

0 Kudos

I WANT FOR MULTIPLE SELECTIONS

Former Member
0 Kudos

Hi,

Get the Selected record.

data : w_grid_cont type ref to cl_gui_container.

data : w_alv type ref to cl_gui_alv_grid.

create object w_alv

exporting

i_parent = w_grid_cont.

call method w_alv->check_changed_data.

Select Multiple record.

Loop at itab.

itab-xflag = 'X'.

modify itab.

endloop.

Try this Method,

Thanks,

Durai.V

Edited by: Durai V on Oct 1, 2008 9:23 AM

MarcinPciak
Active Contributor
0 Kudos

Hi,

Do like this:

1) in layout structure set selection mode for multiple rows

ls_layout-sel_mode = 'A'.

2) then just call this method

call method alv->get_selected_rows importing et_row_no = lt_rows.

The parameter u201Cet_row_nou201D is of type LVC_T_ROID and returns row indexes for selected rows (but not cells or columns) in it.

Regards

Marcin

0 Kudos

Though iam using 'A' for multiple selections its not working.

0 Kudos

Please ensure you are passing ls_layout to set_table_for_first_display method.

Where do you call GET_SELECTED_ROWS ?

0 Kudos

HI

YES I AM PASSING IS_LAYOUT IN SET_FIRST_DISPLAY..... DO I NEED TO CALL GET_SELECTED ROWS ALSO

0 Kudos

Yes, you have to. Otherwise you won't be able to know which rows were selected.

It is best to use it in AT USER-COMMAND event block.


AT USER-COMMAND.

if sy-ucomm = "here your fcode for some pushbutton like i.e. GET_NO_ROWS 
 call method alv->get_selected_rows importing et_row_no = lt_rows.
endif.

Setting layout to 'A' value is just indicating that multipy rows selection can be performed,

but the activity of gettting selected rows itself is different and must be explicitly used (by calling the method get_selected_rows).

BR

Marcin

0 Kudos

hi

i did ls_layout-sel_mode = 'A'.

as well as i caleed method get selected data but its not getting anyrows filled in t_rows...

thank u

0 Kudos

hi

i am able to select only single row n am able to get the index of that row using gt_select_data ......

but i need for multiple selection i folowed what u said that is V_LAYOUT-SEL_MODE = 'A'.

can u plz guide me for multiple row selection

thank u

0 Kudos

Please give us your code. Maybe it will be easier to help you then.

0 Kudos

V_LAYOUT TYPE LVC_S_LAYO,

V_LAYOUT-SEL_MODE = 'A'.

V_LAYOUT-zebra = 'X'.

V_LAYOUT-EDIT = 'X'.

V_LAYOUT-NO_TOOLBAR = 'X'.

V_LAYOUT-GRID_TITLE = 'stock in warehouse'.

CALL METHOD GRID2->SET_TABLE_FOR_FIRST_DISPLAY

EXPORTING

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

IS_LAYOUT = V_LAYOUT

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • IT_TOOLBAR_EXCLUDING =

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

  • IT_EXCEPT_QINFO =

CHANGING

IT_OUTTAB = IT_FINAL_RAW

IT_FIELDCATALOG = IT_FIELDCAT1

  • IT_SORT =

  • IT_FILTER =

  • EXCEPTIONS

  • INVALID_PARAMETER_COMBINATION = 1

  • PROGRAM_ERROR = 2

  • TOO_MANY_LINES = 3

  • others = 4

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

CASE SY-UCOMM.

WHEN 'BACK'.

LEAVE PROGRAM.

when 'OPTIMIZE'.

data : it_rows type LVC_T_ROID..

CALL METHOD GRID2->GET_SELECTED_ROWS

IMPORTING

  • ET_INDEX_ROWS =

ET_ROW_NO = it_rows

.

0 Kudos

hi

any sugestions to modify

thank u

0 Kudos

One point to notice here is that if you set your ALV Grid as to be editable, it may override your selection mode regardless of your layout settings. Please try with removing edit mode from layout structure.

0 Kudos

hi,

i removed that but still multiple selections is not possible

0 Kudos

hi marcin,

i added checkboxes to each row and atleast can we capture the row indexes which are selected using the check boxes

0 Kudos

Hmm, strange to me, I have very similar code and it works fine. Maybe try different selection modes. Use either u2018Cu2019 or u2018Du2019 as they both work with get_selected_rows method.

0 Kudos

hi marcin

where can we find the pssibl values for sel_mode

0 Kudos

HI,

I SAW THE LINK..I HAV DONE ACCORDING TO IT BUT STILL ITS NOT WORKING........CAN U SUGEST ME THE SOLUTION FOR

...............................................i added

checkboxes to each row and atleast can we capture the row indexes which are selected using the check boxe

0 Kudos

hi marcin,

thanks for ur help up to know

thank u.

0 Kudos

Hi urmila,

I did a check with your code. I tweaked it a bit to use standard SFLIGHT table and it is working.

Don't look at that parts where SFLIGHT is used.


DATA: v_layout TYPE lvc_s_layo,
      grid2 TYPE REF TO cl_gui_alv_grid.

DATA: it_final_raw TYPE STANDARD TABLE OF sflight.   "here an example output table

START-OF-SELECTION.
"you don't use this, it's for my usage
  SELECT * FROM sflight INTO TABLE it_final_raw.  

  CREATE OBJECT grid2
    EXPORTING
      i_parent          = cl_gui_container=>screen0.

 "here is your code
  v_layout-sel_mode = 'A'.

  CALL METHOD grid2->set_table_for_first_display
    EXPORTING
      i_structure_name = 'SFLIGHT'       "populate fieldcatalog instead of SFLIGHT (as you do this in your code)
      is_layout        = v_layout
    CHANGING
      it_outtab        = it_final_raw.

  CALL SCREEN '0100'.    

*----------------------------------------------------------------------*
*  MODULE STATUS_0100 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS space.
ENDMODULE.                    "STATUS_0100 OUTPUT

*----------------------------------------------------------------------*
*  MODULE USER_COMMAND_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  CASE sy-ucomm.

  "select your desired rows as shown in the screenshot link below the code
   "then hit back button

    WHEN 'BACK'.   

      DATA : it_rows TYPE lvc_t_roid..
      CALL METHOD grid2->get_selected_rows
        IMPORTING
          et_row_no = it_rows.
     "here you will get all marked rows in it_rows table

  ENDCASE.

ENDMODULE.                    "USER_COMMAND_0100 INPUT

http://myworld.hekko.pl/alv.JPG

Sorry for being trival but sometimes it is only way for solving an issue.

It is working fine for me so it must work for you too.

BR

Marcin