Skip to Content
avatar image
Former Member

about alv ENTER event

Hi experts:

This is a dialog program,in alv,one list is edited.

If I input the data in some cell,when I press the enter key,I want to output the sum of all the cell in the list.

Thanks all.

dear Wei

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Sep 05, 2008 at 06:21 AM

    First of all set the enter event as application event so that PAI will be called .

    Let me know what is the probelm .

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Vijay Dudla

      I uesed the field reference to a table field,so I have solve the problem.here is all the code I solve this problem.thank you all!

      1.定义类

      ----


      • CLASS lcl_grid_event_receiver DEFINITION

      ----


      CLASS lcl_grid_event_receiver DEFINITION .

      PUBLIC SECTION.

      METHODS:

      • toolbar

      • FOR EVENT toolbar OF cl_gui_alv_grid

      • IMPORTING e_object e_interactive ,

      user_command

      FOR EVENT user_command OF cl_gui_alv_grid

      IMPORTING e_ucomm ,

      handle_data_changed

      FOR EVENT data_changed OF cl_gui_alv_grid

      IMPORTING er_data_changed.

      PRIVATE SECTION.

      • This flag is set if any error occured in one of the

      • following methods:

      DATA: error_in_data TYPE c.

      METHODS: check_bcje

      IMPORTING

      ps_good_bcje TYPE lvc_s_modi

      pr_data_changed TYPE REF TO cl_alv_changed_data_protocol.

      ENDCLASS. "lcl_grid_event_receiver DEFINITION

      DATA : grid_handler TYPE REF TO lcl_grid_event_receiver.

      2.定义方法

      &----


      *& Class (Implementation) lcl_grid_event_receiver

      &----


      • Text

      ----


      CLASS lcl_grid_event_receiver IMPLEMENTATION.

      **----


        • Method to handle user commands from toolbar

        **----


        METHOD user_command.

        CASE e_ucomm .

        WHEN ''.

        ENDCASE.

        ENDMETHOD. "user_command

        METHOD handle_data_changed.

        DATA: ls_good TYPE lvc_s_modi.

        error_in_data = space.

        LOOP AT er_data_changed->mt_good_cells INTO ls_good.

        CASE ls_good-fieldname.

        WHEN 'BCJE'.

        CALL METHOD check_bcje

        EXPORTING

        ps_good_bcje = ls_good

        pr_data_changed = er_data_changed.

        ENDCASE.

        ENDLOOP.

        ENDMETHOD. "handle_data_changed

        METHOD check_bcje.

        DATA bcje TYPE ekpo-netwr.

        CALL METHOD pr_data_changed->get_cell_value

        EXPORTING

        i_row_id = ps_good_bcje-row_id

        i_fieldname = ps_good_bcje-fieldname

        IMPORTING

        e_value = bcje.

        break-point.

        IF bcje IS NOT INITIAL.

        READ TABLE item into type_item1 INDEX ps_good_bcje-row_id.

        • ASSIGN item TO <ls_fieldcat1>.

        • <ls_fieldcat1>-bcje = bcje.

        type_item1-bcje = bcje.

        MODIFY item from type_item1 INDEX ps_good_bcje-row_id.

        CLEAR:item,type_item1.

        CALL METHOD alv_grid->refresh_table_display .

        ENDIF.

        ENDMETHOD. "check_planetype

        ENDCLASS. "lcl_grid_event_receiver

        3.在build_objects里添加回车事件

        IF grid_handler IS INITIAL.

        CREATE OBJECT grid_handler.

        SET HANDLER:

        grid_handler->user_command FOR alv_grid,

        grid_handler->handle_data_changed FOR alv_grid."加回车事件

        ENDIF.

        4.在初始化里加上一下语句

        CALL METHOD alv_grid->set_ready_for_input

        EXPORTING

        i_ready_for_input = 1.

        CALL METHOD alv_grid->register_edit_event

        EXPORTING

        i_event_id = cl_gui_alv_grid=>mc_evt_modified.