Application Development and Automation 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: 
Read only

detect rows selection in ALV using oops

Former Member
0 Likes
1,861

Hi ALL,

I HAVE An ALV OUTPUT OF RECORDS USING OOPS.

NOW I CAN SELECT ONE OR MULTIPLE ROWS OF THE OUTPUT AND I HAVE ADDED A DELETE ICON TO MY TOOL BAR.

I HAVE BACK AND EXIT BUTTON AND I HAVE CODE FOR THE SAME IN PAI.

FOR DELETE ICON SY-UCOMM IS DELE AND CONTROL COMES TO PAI

MY QUESTION IS HOW DO YOU KNOW WHICH ROW OR ROWS ARE SELETEd , IN NORMAL ABAP , a field BOX type c has a value X , but what about in ALV using OOPS.

I have no idea whether my approach is correct or wrong or do i need to something else.

Thanks

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,560

You have a method to get the selected rows :

<b>get_selected_rows</b>

CALL METHOD <ref.var. to CL_GUI_ALV_GRID>->get_selected_rows
  IMPORTING 
    ET_INDEX_ROWS = <internal table of type LVC_T_ROW>.

Take a look at <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf">ALV Gird Control (BC-SRV-ALE)</a>

Regards

10 REPLIES 10
Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,561

You have a method to get the selected rows :

<b>get_selected_rows</b>

CALL METHOD <ref.var. to CL_GUI_ALV_GRID>->get_selected_rows
  IMPORTING 
    ET_INDEX_ROWS = <internal table of type LVC_T_ROW>.

Take a look at <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVALV/BCSRVALV.pdf">ALV Gird Control (BC-SRV-ALE)</a>

Regards

Read only

Former Member
0 Likes
1,560

Hi,

Use method get_selected_rows of the ALV class, this returns the index of all rows that have been selected.

For example:

call method alv_grid1->get_selected_rows

importing

et_index_rows = lt_rows.

Read only

0 Likes
1,560

Hi Darren,

This is what i have . Iam new oops so i want to just make sure

method handle_user_command.

  • § 3.In event handler method for event USER_COMMAND: Query your

  • function codes defined in step 2 and react accordingly.

data: lt_rows type lvc_t_row.

case e_ucomm.

when 'DELETE'.

call method g_grid->get_selected_rows

importing et_index_rows = lt_rows.

DATA : WA_LT_ROWS LIKE LINE OF LT_ROWS.

LOOP AT LT_ROWS INTO WA_LT_ROWS.

DELETE I_ZFINAL INDEX WA_LT_ROWS-INDEX.

ENDLOOP.

ENDCASE.

call method g_grid->set_table_for_first_display

exporting

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

  • I_CONSISTENCY_CHECK =

  • I_STRUCTURE_NAME =

  • IS_VARIANT =

  • I_SAVE =

  • I_DEFAULT = 'X'

is_layout = g_layout

  • IS_PRINT =

  • IT_SPECIAL_GROUPS =

  • it_toolbar_excluding = pt_exclude

  • IT_HYPERLINK =

  • IT_ALV_GRAPHICS =

changing

it_outtab = i_zFINAL

it_fieldcatalog = fieldcat

  • IT_SORT =

  • IT_FILTER =

exceptions

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

others = 4

.

LET ME KNOW THANKS

Read only

0 Likes
1,560

Use <i>refresh_table_display</i> and not <i>set_table_for_first_display</i>

Regards

Read only

0 Likes
1,560

Hi,

Use the following:

method handle_user_command.

  • § 3.In event handler method for event USER_COMMAND: Query your

  • function codes defined in step 2 and react accordingly.

data: lt_rows type lvc_t_row.

case e_ucomm.

when 'DELETE'.

call method g_grid->get_selected_rows

importing et_index_rows = lt_rows.

DATA : WA_LT_ROWS LIKE LINE OF LT_ROWS.

LOOP AT LT_ROWS INTO WA_LT_ROWS.

DELETE I_ZFINAL INDEX WA_LT_ROWS-INDEX.

ENDLOOP.

ENDCASE.

call method g_grid->refresh_table_display.

Regards

Read only

0 Likes
1,560

Hi ,

Thanks

I awarded full points to you

Read only

0 Likes
1,560

Hi,

THIS IS OK RIGHT.

I JUST WANT TO MAKE SURE

data: lt_rows type lvc_t_row.

case e_ucomm.

when 'DELETE'.

call method g_grid->get_selected_rows

importing et_index_rows = lt_rows.

call method cl_gui_cfw=>flush.

if sy-subrc ne 0.

  • add your handling, for example

  • call function 'POPUP_TO_INFORM'

  • exporting

  • titel = g_repid

  • txt2 = sy-subrc

  • txt1 = 'Error in Flush'(500).

else.

DATA : WA_LT_ROWS LIKE LINE OF LT_ROWS.

LOOP AT LT_ROWS INTO WA_LT_ROWS.

DELETE I_ZFINAL INDEX WA_LT_ROWS-INDEX.

ENDLOOP.

call method g_grid->refresh_table_display.

Read only

0 Likes
1,560

Have you looked at SAP sample program BCALV_EDIT_04 (and other ones)

Regards

Read only

Former Member
0 Likes
1,560

Suchitra,

All the suggestions are good and will work. The returned value from the method get selected rows returns the index of the row number(s) selected.

Please be careful to note:

If the sort command buttons are enabled, the user may have sorted the table prior to using the delete functionality. Your internal table used to generate the ALV Grid will be in the original order unless you mimic the sort commands the user may have used. If you fail to consider this, you may delete the incorrect row from your internal table.

Just food for thought.

Quack

Read only

0 Likes
1,560

Hi all,

Thanks for your valuable suugestions and i am trying to understand from SAP standard Programs.

No offence i have split the points