Application Development 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: 

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

Former Member
0 Kudos

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

1 ACCEPTED SOLUTION

former_member188685
Active Contributor
0 Kudos
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 .

3 REPLIES 3

Former Member
0 Kudos

Hi,

This is possible using OO ALV..But not sure how we can achieve the same using FM..GRID Display.

Thanks

Naren

former_member188685
Active Contributor
0 Kudos
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 .

Former Member

Hi venkatabby,

Try the below code

In this code you can handle menu button, handle toolbars for interactive list... the user defined button are created at the end of the toolbar.

CLASS lcl_event_receiver DEFINITION DEFERRED.

*type pool declarations
TYPE-POOLS : icon.
tables : mara.
*Internal table and work area declarations for dd02l

DATA: it_mara TYPE TABLE OF mara,
      wa_mara TYPE mara.

*Data declaration for alv.

DATA :it_layout TYPE lvc_s_layo,
      it_toolbar TYPE stb_button,
      c_alv TYPE REF TO cl_gui_alv_grid,
      custom_container TYPE REF TO cl_gui_custom_container,
      event_receiver TYPE REF TO lcl_event_receiver.

*Select options multiple values no ranges
SELECT-OPTIONS : s_table FOR mara-matnr.

*Initialization event
INITIALIZATION.

*Start of selection event
START-OF-SELECTION.

*SUBROUTINE FOR ALV DISPLAY
  PERFORM alvdisplay.

*Class definition
CLASS lcl_event_receiver DEFINITION.

  PUBLIC SECTION.
    CLASS-METHODS:
*handling toolbar for interactive
     handle_toolbar FOR EVENT toolbar OF cl_gui_alv_grid IMPORTING e_object e_interactive,
*handling menu button
     handle_menu_button FOR EVENT menu_button OF cl_gui_alv_grid IMPORTING e_object e_ucomm,
*On click of the menu button
     handle_user_command FOR EVENT user_command OF cl_gui_alv_grid IMPORTING e_ucomm.

ENDCLASS.                    "lcl_event_receiver DEFINITION

*Class implementation
CLASS lcl_event_receiver IMPLEMENTATION.

  METHOD handle_toolbar.
*     handle toolbar
    CLEAR it_toolbar.
    MOVE 'DETAIL' TO it_toolbar-function.
    MOVE icon_detail TO it_toolbar-icon.
    MOVE 2 TO it_toolbar-butn_type.
    APPEND it_toolbar TO e_object->mt_toolbar.
 ENDMETHOD.                    "handle_toolbar

  METHOD handle_menu_button.
*   handle own menubuttons
      IF e_ucomm = 'DETAIL'.
        CALL METHOD e_object->add_function
          EXPORTING
            fcode = 'DISPLAY'
            text  = 'DISPLAY'.
      ENDIF.
  ENDMETHOD.                    "handle_menu_button

  METHOD handle_user_command.
*  On click
      CASE e_ucomm.
        WHEN 'DISPLAY'.
          MESSAGE 'Menu Clicked' TYPE 'I'.
      ENDCASE.
  ENDMETHOD.                           "handle_user_command
ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
*&-----------------------------------------------------------------*
*&      Module  PBO  OUTPUT
*&-----------------------------------------------------------------*
*       text
*------------------------------------------------------------------*
MODULE pbo OUTPUT.
  set pf-status 'MENU'.

  CASE SY-UCOMM.
    WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
    LEAVE PROGRAM.
  ENDCASE.
  IF custom_container IS INITIAL.
* select data from table dd02l
    PERFORM fetch_mara.

* create a custom container control for our ALV Control
    CREATE OBJECT custom_container
        EXPORTING
            container_name = 'CCNT'.

* create an instance of alv control
    CREATE OBJECT c_alv
           EXPORTING i_parent = custom_container.

* Set a titlebar for the grid control
  it_layout-grid_title = 'TABLE DETAILS'.

*ALV display
    CALL METHOD c_alv->set_table_for_first_display
      EXPORTING
        i_structure_name = 'MARA'
        is_layout        = it_layout
      CHANGING
        it_outtab        = it_mara.

*Handlers for the events

    CREATE OBJECT event_receiver.
    SET HANDLER event_receiver->handle_user_command
                event_receiver->handle_menu_button
                event_receiver->handle_toolbar FOR ALL INSTANCES.
*Calling the interactive toolbar method of ALV
    CALL METHOD c_alv->set_toolbar_interactive.
  ENDIF.
ENDMODULE. " PBO  OUTPUT
*&-----------------------------------------------------------------*
*&      Module  PAI  INPUT
*&-----------------------------------------------------------------*
*       text
*-----------------------------------------------------------------*
MODULE pai INPUT.

ENDMODULE.                             " PAI  INPUT

*&----------------------------------------------------------------*
*&      form fetch_dd02l
*&----------------------------------------------------------------*
*       text
*-----------------------------------------------------------------**Subroutine to fetch data
FORM fetch_mara.
  SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE matnr IN s_table.
ENDFORM.                               " SELECT_TABLE_mara
*&-----------------------------------------------------------------*
*&      Form  ALVDISPLAY
*&-----------------------------------------------------------------*
*       text
*------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*------------------------------------------------------------------*
FORM alvdisplay .
* ALV output
  SET SCREEN 600.
ENDFORM.                    " ALVDISPLAY

Regards,

Ragu..