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

DELETE ROWS ON ALV GRID

Former Member
0 Likes
5,274

Hi experts,

We have one trouble with alv programming. We've programmed one dynpro with an OO alv grid (cl_alv_grid).

We've made this alv editable because we want to change the value of the rows, our issue is about deleting the whole row, if the user select the row and press keyword button 'del' the row is deleted...we want to avoid this functionality..

We want to have our alv editable and we want to protect deletion of rows with button 'del', we've seen constant 'MC_LYSTYLE_NO_DELETE_ROWS' on class definition but we have no idea on how to use it..

Someone knows if it's possible to implement this?

Kind regards.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,027

The constant you are referring should be used as a part of the STYLE. You can use it as a part of the LAYOUT of the grid.

Regards,

Ravi

Note : Please mark all the helpful answers

5 REPLIES 5
Read only

Former Member
0 Likes
2,028

The constant you are referring should be used as a part of the STYLE. You can use it as a part of the LAYOUT of the grid.

Regards,

Ravi

Note : Please mark all the helpful answers

Read only

0 Likes
2,027

Hi Ravikumar,

Thanks for your answer but...

In which property of the layout do we have to assign this constant?

Kind Regards.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,027

This is pretty easy to take care of, here is some code.

You want to fill up the LT_EXCLUDE table and pass it when

you are setting for first display. See the code in <b>BOLD</b>.




************************************************************************
*      Module  ALV_0100  OUTPUT
************************************************************************
MODULE ALV_0100 OUTPUT.

  DATA: VARIANT TYPE  DISVARIANT.
  DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

  VARIANT-REPORT = SY-REPID.
  VARIANT-USERNAME = SY-UNAME.

* Create Controls
  CREATE OBJECT ALV_CONTAINER
         EXPORTING CONTAINER_NAME = 'ALV_CONTAINER'.

*   create Event Receiver
  CREATE OBJECT EVENT_RECEIVER.
  CREATE OBJECT ALV_GRID
         EXPORTING  I_PARENT =  ALV_CONTAINER.

*  Populate Field Catalog
  PERFORM GET_FIELDCATALOG.

<b>* Optionally restrict generic functions to 'change only'.
* (The user shall not be able to add new lines).
  PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.</b>

* Set selection mode to "D"  --  Multiple Lines
  LAYOUT-SEL_MODE = 'D'.

  CALL METHOD ALV_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
           IS_LAYOUT              = LAYOUT
<b>           IT_TOOLBAR_EXCLUDING   = LT_EXCLUDE</b>
           IS_VARIANT             = VARIANT
           I_SAVE                 = 'A'
           I_STRUCTURE_NAME       = 'IALV'
      CHANGING
           IT_OUTTAB       = IALV[]
           IT_FIELDCATALOG = FIELDCAT[].

*   handler for ALV grid
  SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR ALV_GRID.

ENDMODULE.


***********************************************************************
*      Form  EXCLUDE_TB_FUNCTIONS
***********************************************************************
<b>FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
* Only allow to change data not to create new entries (exclude
* generic functions).

  DATA LS_EXCLUDE TYPE UI_FUNC.

  LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
  APPEND LS_EXCLUDE TO PT_EXCLUDE.


ENDFORM.</b>

Regards,

Rich Heilman

Read only

Former Member
0 Likes
2,027

Hi Fernando,

if you don't want that Button why can't you exclude that.

can you make it clear, if you want to disable only few cases then you have to have an extra field in itab .

and you have apply to those records..

1.you need to add one extra field in the internal table.

HANDLE_STYLE TYPE LVC_T_STYL

2. before calling the metho set_table_display...

write your own conditions , in my case i am checking for flag is 'X' or not..

LOOP AT IT_FINAL INTO LS_OUTTAB WHERE FLAG = 'X'.
    V_INDEX = SY-TABIX.
    LS_EDIT-FIELDNAME = 'FIELD1'.
    LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_NO_DELETE_ROW.
    LS_EDIT-STYLE2 = SPACE.
    LS_EDIT-STYLE3 = SPACE.
    LS_EDIT-STYLE4 = SPACE.
    LS_EDIT-MAXLEN = 8.
    INSERT LS_EDIT INTO TABLE LT_EDIT.
    LS_EDIT-FIELDNAME = 'FIELD2'.
    LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_NO_DELETE_ROW.
    LS_EDIT-STYLE2 = SPACE.
    LS_EDIT-STYLE3 = SPACE.
    LS_EDIT-STYLE4 = SPACE.
    LS_EDIT-MAXLEN = 8.
    INSERT LS_EDIT INTO TABLE LT_EDIT.
    LS_EDIT-FIELDNAME = 'FIELD5'.
    LS_EDIT-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_NO_DELETE_ROW.
    LS_EDIT-STYLE2 = SPACE.
    LS_EDIT-STYLE3 = SPACE.
    LS_EDIT-STYLE4 = SPACE.
    LS_EDIT-MAXLEN = 8.
    INSERT LS_EDIT INTO TABLE LT_EDIT.
    INSERT LINES OF LT_EDIT INTO TABLE LS_OUTTAB-HANDLE_STYLE.
    MODIFY IT_FINAL INDEX V_INDEX FROM LS_OUTTAB  TRANSPORTING
                                      HANDLE_STYLE.

  ENDLOOP.

3. psss the style name to layout

GS_LAYOUT-STYLEFNAME = 'HANDLE_STYLE'.

Regards

vijay

Message was edited by: Vijay Babu Dudla

Read only

Former Member
0 Likes
2,027

Hi,

1. first find out the function code of that button 'NEW' from the attributes tab of class CL_GUI_ALV_GRID. ( go to SE24, see the attributes, scroll down to use attributes of type UI_FUNC, you will get the function code of DELETING A ROW'. the function code is &LOCAL&DELETE_ROW.

2. Now pass this to parameter IT_TOOLBAR_EXCLUDING :

DATA : t_toolbars TYPE ui_functions.

DATA : wa_tool TYPE LINE OF ui_functions.

wa_tool = '&LOCAL&DELETE_ROW'.

append wa_tool to t_toolbars.

CALL METHOD grid1->set_table_for_first_display

EXPORTING

i_structure_name = 'MARA'

is_layout = wa_layout

it_toolbar_excluding = t_toolbars

CHANGING

it_outtab = t_mara

  • IT_FIELDCATALOG =

  • IT_SORT =

  • IT_FILTER =

EXCEPTIONS

invalid_parameter_combination = 1

program_error = 2

too_many_lines = 3

OTHERS = 4