Classical ALV: Disable DELETE key on Keyboard in Grid

By | October 18, 2008 | Classical ALV | 4,722 | 0

Catch the event generated by DELETE-key on Keyboard & disable it in editable ALV generated using FM REUSE_ALV_GRID_DISPLAY

We have seen in the previous post how to Disable the DELETE-key in the keyboard in the editable ALV using the OO ALV class CL_GUI_ALV_GRID. Today, we will see how we can implement the same functionality using the classical ALV generated using the function module REUSE_ALV_GRID_DISPLAY.

As discussed in the previous post, to implement this we need to implement the DATA_CHANGED and the DATA_CHANGED_FINISHED event. The hurdle here is, we don’t have a event similar to DATA_CHANGED_FINISHED in OOALV in the Classical FM REUSE_ALV_GRID_DISPLAY ALV.

Whenever we generate an ALV with the FM REUSE_ALV_GRID_DISPLAY, it internally creates a object reference fo the CL_GUI_ALV_GRID. We will get that object in our program to overcome the hurdle of not having the DATA_CHANGED_FINISHED event. We will get the OO ALV object from this ALV using the FM GET_GLOBALS_FROM_SLVC_FULLSCR. We will implement the event handler class for that ALV object.

Here I am giving the full example code snippet to implement this functionality.
Code Snippet to Disable DELETE key in the Classical ALV

*& Code snippet for diabling the delete key on the keyboard in the
*&   ALV created using FM REUSE_ALV_GRID_DISPLAY
REPORT zalv_dis_del_key.
* Data to be displayed
DATAgt_sflight     TYPE TABLE OF sflight.
DATAgt_sflight1    TYPE TABLE OF sflight,
      gs_layout      TYPE slis_layout_alv,
      l_deleted      TYPE flag.
DATAo_grid TYPE REF TO cl_gui_alv_grid.
* Event Handler class for ALV Events
CLASS lcl_event_handle DEFINITION.
    METHODS handle_data_changed
      FOR EVENT data_changed OF cl_gui_alv_grid
      IMPORTING er_data_changed.
      handle_changed_finished FOR EVENT data_changed_finished
                             OF cl_gui_alv_grid
                             IMPORTING e_modified
ENDCLASS.                    "lcl_event_handle DEFINITION
DATAo_event_h TYPE REF TO lcl_event_handle.
* Selection
* Edit
  gs_layout-edit 'X'.
* Event for Top-of-page
  DATAlt_events TYPE slis_t_event.
  DATAla_events LIKE LINE OF lt_events.
  la_events-name 'TOP_OF_PAGE'.
  la_events-form 'TOP_OF_PAGE'.
  APPEND la_events TO lt_events.
* Call ABAP List Viewer (ALV)
      i_callback_program      'ZALV_DIS_DEL_KEY'
      i_callback_user_command 'USER_COMMAND'
      i_structure_name        'SFLIGHT'
      is_layout               gs_layout
      it_events               lt_events
      t_outtab                gt_sflight.
*      TOP-OF-PAGE. Also used to get the Object reference
FORM top_of_page.
  DATA lt_comment TYPE slis_t_listheader,
         la_comment TYPE slis_listheader.
* Top of page
  la_comment-typ  'H'.
  la_comment-info 'Disabled Delete Key'.
  APPEND la_comment TO lt_comment.
* Commenty write
      it_list_commentary lt_comment.
* Get the ALV object
      e_grid o_grid.
* Register the Modified event ... Important
  CALL METHOD o_grid->register_edit_event
      i_event_id cl_gui_alv_grid=>mc_evt_modified.
* Set Event handler
  CREATE OBJECT o_event_h.
  SET HANDLER o_event_h->handle_data_changed FOR o_grid.
  SET HANDLER o_event_h->handle_changed_finished FOR o_grid.
ENDFORM.                    "top_of_page
*       User Command
FORM user_command USING r_ucomm TYPE sy-ucomm
                        rs_selfield TYPE slis_selfield.
  IF r_ucomm '&DATA_SAVE'.
    MESSAGE 'You pressed the save button' TYPE 'I'.
ENDFORM.                    "user_command
* Event Handler Class implementation
CLASS lcl_event_handle IMPLEMENTATION.
  METHOD handle_data_changed.
    DATAls_deleted_rows LIKE LINE OF er_data_changed->mt_deleted_rows.
*   data is deleted or not. If yes, than fill the temporary table
*     to its copy
    DESCRIBE TABLE er_data_changed->mt_deleted_rows LINES sy-index.
    IF sy-index IS NOT INITIAL.
      l_deleted 'X'.
      gt_sflight1[] gt_sflight[].
      CLEAR er_data_changed->mt_deleted_rows.
  ENDMETHOD.                    "handle_data_changed
  METHOD  handle_changed_finished.
*   data has been deleted than set the temp data back to the main table
*   and refresh the table display
    IF l_deleted 'X'.
      gt_sflight[] gt_sflight1[].
*   message
    MESSAGE 'You can not delete any record' TYPE 'I'.
*   refresh the list display
    CALL METHOD o_grid->refresh_table_display
        finished 1
        OTHERS   2.
    IF sy-subrc NE 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDMETHOD.                    "handle_changed_finished
ENDCLASS.                    "lcl_event_handle IMPLEMENTATION


  • Moving Cursor to Next row by pressing Enter in Classical ALV
  • Classical ALV: Change Subtotal
  • Like It? Share!!

    Don't miss an Update

    Get notified of the new post, right into your inbox

    Naimesh Patel{271 articles}

    I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
    Follow :

    Explore all of his 271 articles.

    Load comments

    Comments on this Post are now closed. If you have something important to share, you can always contact me.

    You seem to be new here. Subscribe to stay connected.