‎2007 Aug 09 3:06 PM
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
‎2007 Aug 09 3:12 PM
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
‎2007 Aug 09 3:12 PM
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
‎2007 Aug 09 3:19 PM
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.
‎2007 Aug 09 3:21 PM
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
‎2007 Aug 09 3:28 PM
‎2007 Aug 09 3:34 PM
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
‎2007 Aug 09 3:36 PM
‎2007 Aug 09 3:37 PM
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.
‎2007 Aug 09 3:37 PM
‎2007 Aug 09 3:51 PM
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
‎2007 Aug 09 3:55 PM
Hi all,
Thanks for your valuable suugestions and i am trying to understand from SAP standard Programs.
No offence i have split the points