Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to pass ENTER button from key borad to ALV_GRID dispaly user_command?

I have an Editable ALV GRID.

Once I change the value of the editable column, rest of the values in the row have to be changed.

I able to manage this with a button on application toolbar.

But the users want to have the same functionality built in when the ENTER button on the keyboard is pressed.

I saw some postings using methods but I am not able to utilize them properly.

Can you pl help by providing a good solution?

Thanks,

Ven

Tags:
Former Member
replied
REPORT  ztest_alv_001.
DATA: grid TYPE REF TO cl_gui_alv_grid.

*----------------------------------------------------------------------*
*       CLASS lc_handler DEFINITION
*----------------------------------------------------------------------*

CLASS lc_handler DEFINITION.
  PUBLIC SECTION.

    METHODS: handle_data_changed
               FOR EVENT data_changed OF cl_gui_alv_grid
                  IMPORTING er_data_changed
                            e_onf4 e_onf4_before e_onf4_after.


ENDCLASS.                    "lc_handler DEFINITION

*----------------------------------------------------------------------*
*       CLASS lc_handler IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lc_handler IMPLEMENTATION.

  METHOD handle_data_changed.

    BREAK-POINT.
  ENDMETHOD.                    "handle_Data_changed

ENDCLASS.                    "lc_handler IMPLEMENTATION

TYPE-POOLS: slis.
DATA: it_flight TYPE STANDARD TABLE OF sflight.
DATA: w_flag.
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
      wa_fcat LIKE LINE OF it_fieldcat.
DATA: handler TYPE REF TO lc_handler.

START-OF-SELECTION.

  SELECT * FROM sflight
  INTO TABLE it_flight
  UP TO 20 ROWS.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = sy-repid
      i_structure_name       = 'SFLIGHT'
    CHANGING
      ct_fieldcat            = it_fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  wa_fcat-edit = 'X'.
  wa_fcat-input = 'X'.
  MODIFY it_fieldcat FROM wa_fcat TRANSPORTING edit input
   WHERE fieldname = 'FLDATE'.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program     = sy-repid
      i_callback_top_of_page = 'TOP_OF_PAGE'
      i_structure_name       = 'SFLIGHT'
      it_fieldcat            = it_fieldcat
    TABLES
      t_outtab               = it_flight
    EXCEPTIONS
      program_error          = 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.
  ENDIF.

FORM top_of_page.

  IF w_flag IS INITIAL.
    CREATE OBJECT handler.

    CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
      IMPORTING
        e_grid = grid.
    SET HANDLER handler->handle_data_changed FOR grid.
    CALL METHOD grid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_enter.

  ENDIF.
ENDFORM.                    "TOP_OF_PAGE

The above code triggeres when you press enter. in this case i am handling the event using the local class handler. just check it .

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question