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: 

Drop down getting skipped when data_changed event is being triggered in ALV

0 Kudos

Hi,

I have created an ALV using CL_GUI_ALV_GRID class, in which I have used a dropdown row (editable).

I have used DATA_CHANGED event of the class to handle an other field changes.

Now because of using this event, my dropdown is being effected. When I change the value of first dropdown column, everything is fine.But immediately if I try to change another dropdown column,the dropdown is getting slipped.

I meant to say the data_changed event is being triggered and its not showing the dropdown. Again if I select on dropdown column it works fine.

Could you please help me how to solve this.

Kindly let me know if you need any other information on this.

(Easiest way of replicating this issue is create an ALV with a drop down field and set event data_changed then you will face this issue)

8 REPLIES 8

0 Kudos

Below I have given sample code to replicate the issue.

Also in the code create screen 100 and PF status 'STAT' with 3 buttons BACK,CANCEL and EXIT

DATA: go_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager. "Toolbar manager. CLASS lcl_alv_toolbar DEFINITION. PUBLIC SECTION. *Constructor METHODS: constructor IMPORTING io_alv_grid TYPE REF TO cl_gui_alv_grid, *** DATA_CHANGED data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed e_onf4 e_onf4_before e_onf4_after e_ucomm. ENDCLASS. CLASS lcl_alv_toolbar IMPLEMENTATION. METHOD constructor. * Create ALV toolbar manager instance CREATE OBJECT go_alv_toolbarmanager EXPORTING io_alv_grid = io_alv_grid. ENDMETHOD. "constructor METHOD data_changed. *** Implement suitable code IF sy-subrc = 0. ENDIF. ENDMETHOD. ENDCLASS. DATA: go_alv_toolbar TYPE REF TO lcl_alv_toolbar. TYPES: BEGIN OF ty_final, charg_c TYPE charg_d, handle TYPE int4, END OF ty_final. DATA: lt_dropdown TYPE lvc_t_drop, ls_dropdown TYPE lvc_s_drop. DATA: gt_final TYPE TABLE OF ty_final, gs_layout TYPE lvc_s_layo, gs_final TYPE ty_final. DATA: ls_fcat TYPE lvc_s_fcat, lt_fcat TYPE TABLE OF lvc_s_fcat. DATA: go_grid TYPE REF TO cl_gui_alv_grid. *** ADD BLANK LINES START-OF-SELECTION. gs_final-handle = 1. APPEND gs_final TO gt_final. APPEND gs_final TO gt_final. APPEND gs_final TO gt_final. APPEND gs_final TO gt_final. APPEND gs_final TO gt_final. APPEND gs_final TO gt_final. CALL SCREEN 100. *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE status_0100 OUTPUT. SET PF-STATUS 'STAT'. * SET TITLEBAR 'xxx'. IF go_grid IS NOT BOUND. " Create GRID object with reference to parent name CREATE OBJECT go_grid EXPORTING i_parent = cl_gui_custom_container=>default_screen. * create ALV event handler CREATE OBJECT go_alv_toolbar EXPORTING io_alv_grid = go_grid. SET HANDLER go_alv_toolbar->data_changed FOR go_grid. CLEAR ls_fcat. ls_fcat-fieldname = 'CHARG_C'. ls_fcat-tabname = 'GT_FINAL'. ls_fcat-edit = 'X'. ls_fcat-coltext = 'Change batch'. ls_fcat-drdn_field = 'HANDLE'. ls_fcat-outputlen = 10. APPEND ls_fcat TO lt_fcat. ls_dropdown-handle = 1. ls_dropdown-value = 'TEST1'. APPEND ls_dropdown TO lt_dropdown. ls_dropdown-handle = 1. ls_dropdown-value = 'TEST2'. APPEND ls_dropdown TO lt_dropdown. ls_dropdown-handle = 1. ls_dropdown-value = 'TEST3'. APPEND ls_dropdown TO lt_dropdown. ls_dropdown-handle = 1. ls_dropdown-value = 'TEST4'. APPEND ls_dropdown TO lt_dropdown. CALL METHOD go_grid->set_drop_down_table EXPORTING it_drop_down = lt_dropdown. " SET_TABLE_FOR_FIRST_DISPLAY CALL METHOD go_grid->set_table_for_first_display EXPORTING is_layout = gs_layout CHANGING it_outtab = gt_final " Data it_fieldcatalog = lt_fcat. * CALL METHOD go_grid->set_ready_for_input * EXPORTING * i_ready_for_input = 1. CALL METHOD go_grid->register_edit_event EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified EXCEPTIONS error = 1 OTHERS = 2. ENDIF. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE user_command_0100 INPUT. *** Variable declarations DATA: ok_code TYPE syst_ucomm. CONSTANTS:lc_back TYPE char4 VALUE 'BACK', lc_cancel TYPE char6 VALUE 'CANCEL', lc_exit TYPE char4 VALUE 'EXIT'. ok_code = sy-ucomm. CASE ok_code. WHEN lc_back OR lc_cancel. LEAVE TO SCREEN 0. WHEN lc_exit. LEAVE PROGRAM. WHEN OTHERS. *** Do nothing ENDCASE. ENDMODULE.

p244500
Active Contributor
0 Kudos

Hi,

I attached sample code with here you can try it.

*---------------------------------------------------------------------*
*                                 Table                               *
*---------------------------------------------------------------------*
TABLES : vbak.
*---------------------------------------------------------------------*
*       TYPE-POOLS                                                    *
*---------------------------------------------------------------------*
TYPE-POOLS : abap,rsanm.

*---------------------------------------------------------------------*
*       CONSTANTS                    Begin with GC_                   *
*---------------------------------------------------------------------*


*CONSTANTS: gc_formname_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
*           con_on                  TYPE c VALUE 'X',
*           con_off                 TYPE c VALUE ' '.
*---------------------------------------------------------------------*
*       Types                    Begin with TY_                       *
*---------------------------------------------------------------------*


TYPES : BEGIN OF ty_vbak.
        INCLUDE TYPE vbak.

TYPES : t_color TYPE lvc_t_scol,
        END OF ty_vbak.
*---------------------------------------------------------------------*
*       Internal tables          Begin with GT_                       *
*---------------------------------------------------------------------*
DATA : lt_vbak TYPE STANDARD TABLE OF ty_vbak.

*---------------------------------------------------------------------*
*       Internal ST                     Begin with GS_                *
*---------------------------------------------------------------------*
DATA : ls_vbak TYPE ty_vbak.

*---------------------------------------------------------------------*
*       Data                     Begin with GS_                       *
*---------------------------------------------------------------------*
DATA : l_rec(5)  TYPE n.
DATA : gr_table       TYPE REF TO cl_salv_table.

** Declarations for ALV Functions
DATA : gr_functions   TYPE REF TO cl_salv_functions_list.
** declaration for ALV Columns
DATA : gr_columns     TYPE REF TO cl_salv_columns_table,
       gr_column      TYPE REF TO cl_salv_column_table,
       gt_column_ref  TYPE salv_t_column_ref,
       gs_column_ref  TYPE salv_s_column_ref.


** declaration for Layout Settings
DATA : gr_layout      TYPE REF TO cl_salv_layout,
       gr_layout_key  TYPE salv_s_layout_key,
       gs_layout      TYPE salv_s_layout,
       gt_layout_info TYPE salv_t_layout_info.

** Declaration for Global Display Settings
DATA : gr_display     TYPE REF TO cl_salv_display_settings,
       lv_title       TYPE lvc_title.

** Declaration for Aggregate Function Settings
DATA : gr_aggr        TYPE REF TO cl_salv_aggregations.

** Declaration for Sort Function Settings
DATA : gr_sort        TYPE REF TO cl_salv_sorts.

** Declaration for Table Selection settings
DATA : gr_select      TYPE REF TO cl_salv_selections.

** Declaration for Top of List settings
DATA : gr_content     TYPE REF TO cl_salv_form_element.

** Class for handling Events
CLASS : lcl_handle_events DEFINITION DEFERRED.
DATA  : gr_events     TYPE REF TO lcl_handle_events,
        lr_events     TYPE REF TO cl_salv_events_table.


** Coloring of Date columns **
DATA : gt_colo        TYPE STANDARD TABLE OF lvc_s_colo,
       gs_colo        TYPE lvc_s_colo.

** Color Structure of columns **
DATA : gt_color       TYPE lvc_t_scol,
       gs_color       TYPE lvc_s_scol.

DATA: gv_not_found TYPE REF TO cx_salv_not_found.

*----------------------------------------------------------------------*
*       CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS : on_double_click FOR EVENT double_click OF cl_salv_events_table
      IMPORTING row column.
    METHODS : on_link_click FOR EVENT link_click OF cl_salv_events_table
      IMPORTING row column.
ENDCLASS.                    "lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_double_click.
    PERFORM get_ord_info USING row column.
  ENDMETHOD.                    "on_double_click
  METHOD on_link_click.
    PERFORM get_ord_info USING row column.
  ENDMETHOD.                    "on_link_click
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
*       Varient                     Begin with GV_                    *
*---------------------------------------------------------------------*


** Varient
*---------------------------------------------------------------------*
*       Field Symbols            Begin with FS_                       *
*---------------------------------------------------------------------*
FIELD-SYMBOLS : <fs_vbak> TYPE ty_vbak.

*---------------------------------------------------------------------*
*       Select Options          Begin with SO_                        *
*---------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001..
SELECT-OPTIONS : p_erdat FOR vbak-erdat. "NO-EXTENSION OBLIGATORY
PARAMETER : p_var TYPE slis_vari.
SELECTION-SCREEN END OF BLOCK b1.

*---------------------------------------------------------------------*
*       Parameters              Begin with PR_                        *
*---------------------------------------------------------------------*
*PARAMETERS: variant LIKE disvariant-variant.




AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_var.
  CLEAR : gs_layout.
  TRY.
      CALL METHOD cl_salv_table=>factory
        EXPORTING
          list_display = if_salv_c_bool_sap=>false
        IMPORTING
          r_salv_table = gr_table
        CHANGING
          t_table      = lt_vbak.
    CATCH cx_salv_msg .
  ENDTRY.


  IF gr_table IS NOT INITIAL.
    MOVE sy-repid TO gr_layout_key-report.     "Set Layout Key as Report ID"
    gr_layout = gr_table->get_layout( ).       "Get Layout of the Table"
    gr_layout->set_key( gr_layout_key ).       "Set Layout key to Layout"
    gt_layout_info = gr_layout->get_layouts( )."Get the Layouts of report"


    IF gt_layout_info[] IS NOT INITIAL.
      gs_layout = gr_layout->f4_layouts( ).    "Activate F4 Help for Layouts"
      IF gs_layout IS NOT INITIAL.
        MOVE gs_layout-layout TO p_var.
      ENDIF.
    ENDIF.


  ENDIF.


***********************************************************************
*       S T A R T   O F   S E L E C T I O N                           *
***********************************************************************




START-OF-SELECTION.


  PERFORM get_logic.


  IF sy-subrc EQ 0.
    DESCRIBE TABLE lt_vbak LINES l_rec.
    PERFORM set_color.
    PERFORM alv_grid_display.
  ENDIF.


END-OF-SELECTION.


***********************************************************************
*       E N D       O F   S E L E C T I O N                           *
***********************************************************************


*&---------------------------------------------------------------------*
*&      Form  alv_grid_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM alv_grid_display.
  CLEAR : gr_table.
  TRY.
      CALL METHOD cl_salv_table=>factory
        EXPORTING
          list_display = if_salv_c_bool_sap=>false
        IMPORTING
          r_salv_table = gr_table
        CHANGING
          t_table      = lt_vbak.
    CATCH cx_salv_msg .
  ENDTRY.
  IF gr_table IS INITIAL.
    MESSAGE 'Error Creating ALV Grid ' TYPE 'I' DISPLAY LIKE 'E'.
    STOP.
  ENDIF.
** Get functions details
  gr_functions = gr_table->get_functions( ).


** Activate All Buttons in Tool Bar
  gr_functions->set_all( if_salv_c_bool_sap=>true ).


******* Layout Settings  *******
  CLEAR : gr_layout, gr_layout_key.
  MOVE sy-repid TO gr_layout_key-report.                        "Set Report ID as Layout Key"


  gr_layout = gr_table->get_layout( ).                          "Get Layout of Table"
  gr_layout->set_key( gr_layout_key ).                          "Set Report Id to Layout"
  gr_layout->set_save_restriction( if_salv_c_layout=>restrict_none ). "No Restriction to Save Layout"
  IF p_var IS INITIAL.
    gr_layout->set_default( if_salv_c_bool_sap=>true ).         "Set Default Variant"
  ELSE.
    gr_layout->set_initial_layout( p_var ).                     "Set the Selected Variant as Initial"
  ENDIF.


******* Global Display Settings  *******
  CLEAR : gr_display.
  MOVE 'Sales Order Details' TO lv_title.
  gr_display = gr_table->get_display_settings( ).               " Global Display settings"
  gr_display->set_striped_pattern( if_salv_c_bool_sap=>true ).  "Activate Strip Pattern"
  gr_display->set_list_header( lv_title ).                      "Report Header"


******* Aggregate Function Settings *******
  gr_aggr = gr_table->get_aggregations( ).                      "Get Aggregate Functions"


******* Sort Functions *******
  gr_sort = gr_table->get_sorts( ).
  IF gr_sort IS NOT INITIAL.
    TRY.
        gr_sort->add_sort( columnname = 'ERNAM'
                           position = 1
                           sequence   = if_salv_c_sort=>sort_up
                           subtotal   = if_salv_c_bool_sap=>true
                           group      = if_salv_c_sort=>group_none
                           obligatory = if_salv_c_bool_sap=>false ).
      CATCH cx_salv_not_found .
      CATCH cx_salv_existing .
      CATCH cx_salv_data_error .
    ENDTRY.


    TRY.
        gr_sort->add_sort( columnname = 'ERDAT'
                           position = 2
                           sequence   = if_salv_c_sort=>sort_down
                           subtotal   = if_salv_c_bool_sap=>false
                           group      = if_salv_c_sort=>group_none
                           obligatory = if_salv_c_bool_sap=>false ).
      CATCH cx_salv_not_found .
      CATCH cx_salv_existing .
      CATCH cx_salv_data_error .
    ENDTRY.
  ENDIF.
******* Table Selection Settings *******
  gr_select = gr_table->get_selections( ).
  IF gr_select IS NOT INITIAL.
    gr_select->set_selection_mode( if_salv_c_selection_mode=>row_column ). "Allow single row Selection"
  ENDIF.


******* Top of List settings *******
  PERFORM top_of_page CHANGING gr_content.
  gr_table->set_top_of_list( gr_content ).


******* Event Register settings *******
  lr_events = gr_table->get_event( ).
  CREATE OBJECT gr_events.
  SET HANDLER gr_events->on_double_click FOR lr_events.
  SET HANDLER gr_events->on_link_click FOR lr_events.


** Get the columns from ALV Table
  gr_columns = gr_table->get_columns( ).
  IF gr_columns IS NOT INITIAL.
    REFRESH : gt_column_ref.
    CLEAR   : gs_column_ref.
    gt_column_ref = gr_columns->get( ).


** Get columns properties
    gr_columns->set_optimize( if_salv_c_bool_sap=>true ).
    gr_columns->set_key_fixation( if_salv_c_bool_sap=>true ).
    TRY.
        gr_columns->set_color_column( 'T_COLOR' ).
      CATCH cx_salv_data_error .
    ENDTRY.


    TRY .
        gr_column ?= gr_columns->get_column( 'ERDAT' ).
      CATCH cx_salv_not_found.
    ENDTRY.
    IF gr_column IS BOUND.
      gr_column->set_key( ).
      gr_column->set_key_presence_required( ).
    ENDIF.


    TRY .
        gr_column ?= gr_columns->get_column( 'ERZET' ).
      CATCH cx_salv_not_found.
    ENDTRY.
    IF gr_column IS BOUND.
      gr_column->set_key( ).
      gr_column->set_key_presence_required( ).
    ENDIF.


** Individual Column Properties.
        perform column_settings.

  ENDIF.
  CALL METHOD gr_table->display.
ENDFORM.                    "alv_grid_display


*&---------------------------------------------------------------------*
*&      Form  column_settings
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM column_settings.


*  TRY.
*      gr_column ?= gr_columns->get_column( 'VBELN' ).
*      gr_column->set_short_text( 'Seq. Numb' ).
*      gr_column->set_medium_text( 'Sequential Number' ).
*      gr_column->set_long_text( 'Sequential Number' ).
*
*    CATCH cx_salv_not_found INTO gv_not_found.
*      " error handling
*  ENDTRY.


  LOOP AT gt_column_ref INTO gs_column_ref.
    TRY.
        gr_column ?= gr_columns->get_column( gs_column_ref-columnname ).
      CATCH cx_salv_not_found.
    ENDTRY.
    IF gr_column IS NOT INITIAL.
** Make Mandt column invisible **
      IF gr_column->get_ddic_datatype( ) = 'CLNT'.
        gr_column->set_technical( if_salv_c_bool_sap=>true ).
      ENDIF.
** Create Aggregate function total for All Numeric/Currency Fields **
      IF gr_column->get_ddic_inttype( ) EQ 'P' OR
         gr_column->get_ddic_datatype( ) EQ 'CURR'.
        IF gr_aggr IS NOT INITIAL.
          TRY.
              gr_aggr->add_aggregation( columnname = gs_column_ref-columnname
                                        aggregation = if_salv_c_aggregation=>total ).
            CATCH cx_salv_data_error .
            CATCH cx_salv_not_found .
            CATCH cx_salv_existing .
          ENDTRY.
        ENDIF.
      ENDIF.
** Create Check box for fields with domain "XFELD"
      IF gr_column->get_ddic_domain( ) EQ 'XFELD'.
        gr_column->set_cell_type( if_salv_c_cell_type=>checkbox ).
      ENDIF.


** Set color to Date Columns **
      IF gr_column->get_ddic_datatype( ) EQ 'DATS'.
        CLEAR : gs_colo.
        MOVE 2 TO gs_colo-col.
        MOVE 1 TO gs_colo-int.
        MOVE 1 TO gs_colo-inv.
        gr_column->set_color( gs_colo ).
      ENDIF.


* Add Hotspot&Hyper Link to the column vbeln
      IF gs_column_ref-columnname EQ 'VBELN'.
        gr_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
        gr_column->set_key( if_salv_c_bool_sap=>true ).
      ENDIF.


    ENDIF.
  ENDLOOP.
ENDFORM.                    "column_settings


*&---------------------------------------------------------------------*
*&      Form  top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page CHANGING lr_content TYPE REF TO cl_salv_form_element.
  DATA : lr_grid TYPE REF TO cl_salv_form_layout_grid,
         lr_text  TYPE REF TO cl_salv_form_text,
         lr_label TYPE REF TO cl_salv_form_label,
         lr_head  TYPE string.


  MOVE 'Sales Order List' TO lr_head.
  CREATE OBJECT lr_grid.
** Header of Top of Page **
  lr_grid->create_header_information( row     = 1
                                      column  = 1
                                      text    = lr_head
                                      tooltip = lr_head ).
** Add Row **
  lr_grid->add_row( ).


** Add Label in Grid **
  lr_label = lr_grid->create_label( row = 2
                                    column = 1
                                    text = 'No of Records'
                                    tooltip = 'No of Records' ).

** Add Text in The Grid **
  lr_text = lr_grid->create_text( row = 2
                                  column = 2
                                  text = l_rec
                                  tooltip = l_rec ).
** Set Label and Text Link **
  lr_label->set_label_for( lr_text ).


** Move lr_grid to lr_content **
  lr_content = lr_grid.
ENDFORM.                    "top_of_page

*&---------------------------------------------------------------------*
*&      Form
*&---------------------------------------------------------------------*
FORM get_ord_info USING row TYPE salv_de_row
                        column TYPE salv_de_column.
  IF column EQ 'VBELN'.
    CLEAR : ls_vbak.
    READ TABLE lt_vbak INTO ls_vbak INDEX row.
    IF sy-subrc EQ 0.
      SET PARAMETER ID 'AUN' FIELD ls_vbak-vbeln.
      CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    ENDIF.
  ENDIF.
ENDFORM.                    "get_ord_info

*&---------------------------------------------------------------------*
*&      Form  set_color
*&---------------------------------------------------------------------*
* Set color to the column VBELN & NETWR for Order Value > 1000
*----------------------------------------------------------------------*
FORM set_color.
  LOOP AT lt_vbak ASSIGNING <fs_vbak> .
    IF <fs_vbak>-netwr GT 1000.
      REFRESH : gt_color.

      CLEAR : gs_color.
      MOVE 'VBELN' TO gs_color-fname.
      MOVE 3       TO gs_color-color-col.
      MOVE 0       TO gs_color-color-int.
      MOVE 0       TO gs_color-color-inv.
      APPEND gs_color TO gt_color.

      CLEAR : gs_color.
      MOVE 'NETWR' TO gs_color-fname.
      MOVE 3       TO gs_color-color-col.
      MOVE 0       TO gs_color-color-int.
      MOVE 0       TO gs_color-color-inv.
      APPEND gs_color TO gt_color.


*      MOVE gt_color TO ls_colo ."gs_color.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "set_color
*&---------------------------------------------------------------------*
*&      Form  GET_LOGIC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_logic .

  REFRESH : lt_vbak.
  SELECT * FROM vbak
    INTO CORRESPONDING FIELDS OF TABLE lt_vbak
    WHERE erdat IN p_erdat.

ENDFORM.                    " GET_LOGIC

0 Kudos

Hi,

My issue is with dropdown field,but in your code there is no dropdown field. Also I am using CL_GUI_ALV_GRID and not SALV class.

Request you to please check before answering.

Thanks

p244500
Active Contributor
0 Kudos

Hi,

I gave you different approach , with sample code. why you said drop down not available, kindly look at attachment.

ALV GRID link

https://wiki.scn.sap.com/wiki/display/Snippets/ALV-+Define+a+Dropdown+listbox+for+column

Regards,

Nawa.

DoanManhQuynh
Active Contributor
0 Kudos

What do you mean "slipped"? and what are you doing in data_changed event? you should format your code then people may read it.

0 Kudos
*&---------------------------------------------------------------------*
*& Report  ZTEST_DROPDOWN
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ztest_dropdown.


DATA: go_alv_toolbarmanager TYPE REF TO cl_alv_grid_toolbar_manager.  "Toolbar manager.


CLASS lcl_alv_toolbar DEFINITION.
  PUBLIC SECTION.
*Constructor
    METHODS: constructor
      IMPORTING
        io_alv_grid TYPE REF TO cl_gui_alv_grid,


*** DATA_CHANGED
      data_changed FOR EVENT data_changed OF cl_gui_alv_grid
        IMPORTING er_data_changed
                    e_onf4
                    e_onf4_before
                    e_onf4_after
                    e_ucomm.
ENDCLASS.


CLASS lcl_alv_toolbar IMPLEMENTATION.
  METHOD constructor.
*   Create ALV toolbar manager instance
    CREATE OBJECT go_alv_toolbarmanager
      EXPORTING
        io_alv_grid = io_alv_grid.
  ENDMETHOD.                                        "constructor




  METHOD data_changed.
*** Implement suitable code
    IF sy-subrc = 0.


    ENDIF.
  ENDMETHOD.
ENDCLASS.


DATA:
      go_alv_toolbar TYPE REF TO lcl_alv_toolbar.


TYPES: BEGIN OF ty_final,
         charg_c TYPE charg_d,
         handle  TYPE int4,
       END OF ty_final.


DATA: lt_dropdown TYPE lvc_t_drop,
      ls_dropdown TYPE lvc_s_drop.


DATA: gt_final  TYPE TABLE OF ty_final,
      gs_layout TYPE lvc_s_layo,
      gs_final  TYPE ty_final.


DATA: ls_fcat TYPE lvc_s_fcat,
      lt_fcat TYPE TABLE OF lvc_s_fcat.


DATA:  go_grid    TYPE REF TO cl_gui_alv_grid.
*** ADD BLANK LINES
START-OF-SELECTION.


  gs_final-handle = 1.
  APPEND gs_final TO gt_final.
  APPEND gs_final TO gt_final.
  APPEND gs_final TO gt_final.
  APPEND gs_final TO gt_final.
  APPEND gs_final TO gt_final.
  APPEND gs_final TO gt_final.


  CALL SCREEN 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS 'STAT'.
*  SET TITLEBAR 'xxx'.




  IF go_grid IS NOT BOUND.


    " Create GRID object with reference to parent name
    CREATE OBJECT go_grid EXPORTING i_parent = cl_gui_custom_container=>default_screen.


* create ALV event handler
    CREATE OBJECT go_alv_toolbar
      EXPORTING
        io_alv_grid = go_grid.


    SET HANDLER go_alv_toolbar->data_changed FOR go_grid.


    CLEAR ls_fcat.
    ls_fcat-fieldname = 'CHARG_C'.
    ls_fcat-tabname = 'GT_FINAL'.
    ls_fcat-edit = 'X'.
    ls_fcat-coltext = 'Change batch'.
    ls_fcat-drdn_field = 'HANDLE'.
    ls_fcat-outputlen = 10.
    APPEND ls_fcat TO lt_fcat.




    ls_dropdown-handle = 1.
    ls_dropdown-value = 'TEST1'.
    APPEND ls_dropdown TO lt_dropdown.


    ls_dropdown-handle = 1.
    ls_dropdown-value = 'TEST2'.
    APPEND ls_dropdown TO lt_dropdown.


    ls_dropdown-handle = 1.
    ls_dropdown-value = 'TEST3'.
    APPEND ls_dropdown TO lt_dropdown.




    ls_dropdown-handle = 1.
    ls_dropdown-value = 'TEST4'.
    APPEND ls_dropdown TO lt_dropdown.


    CALL METHOD go_grid->set_drop_down_table
      EXPORTING
        it_drop_down = lt_dropdown.




    " SET_TABLE_FOR_FIRST_DISPLAY
    CALL METHOD go_grid->set_table_for_first_display
      EXPORTING
        is_layout       = gs_layout
      CHANGING
        it_outtab       = gt_final " Data
        it_fieldcatalog = lt_fcat.




*    CALL METHOD go_grid->set_ready_for_input
*      EXPORTING
*        i_ready_for_input = 1.


    CALL METHOD go_grid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified
      EXCEPTIONS
        error      = 1
        OTHERS     = 2.


  ENDIF.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.


*** Variable declarations
  DATA: ok_code   TYPE syst_ucomm.


  CONSTANTS:lc_back   TYPE char4 VALUE 'BACK',
            lc_cancel TYPE char6 VALUE 'CANCEL',
            lc_exit   TYPE char4 VALUE 'EXIT'.


  ok_code = sy-ucomm.


  CASE ok_code.
    WHEN lc_back OR lc_cancel.
      LEAVE TO SCREEN 0.
    WHEN lc_exit.
      LEAVE PROGRAM.
    WHEN OTHERS.


*** Do nothing
  ENDCASE.


ENDMODULE.

0 Kudos

Above I have given sample code to replicate the issue.

Also in the code create screen 100 and PF status 'STAT' with 3 buttons BACK,CANCEL and EXIT.

The dropdown shows the list some time and sometimes it won't. (will get a better understanding if you run the sample report )

I am using data_changed to implement some code related to other field.But as soon as I register edit event the dropdown is getting effected.

How to avoid this?

DoanManhQuynh
Active Contributor
0 Kudos

I see your problem now. idk why it happended but i have a workaround:

you can call method check_changed_data in PAI instead of register event data_changed so your dropdown wont be slipped. that method also trigger data_changed event then your code there still work.