Skip to Content
author's profile photo Former Member
Former Member

Problem on ALV GRID CONTROL

HI ,

I have created an OO based ALV GRID ( 6columns) .

I n this ALV i have a dropdown box on one column.

I want that on change of the value on drop down box the other dependent columns (othe 5 columns) should be filled with some data .

i am not able to find out any event when we change the value in the drop down list box .

is there any event which gets triggered on change of value in the drop down box .

Please help .

regards,

vikram.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 01, 2008 at 09:30 AM

    no DATA_CHANGED does not get triggerred on change of value on drop down . yes i have seen those programs .

    Add a comment
    10|10000 characters needed characters exceeded

    • >

      > no DATA_CHANGED does not get triggerred on change of value on drop down . yes i have seen those programs .

      Yes it will trigger, I did one program, it is triggering. Do you have any local event handler for DATA_CHANGED event.

      check the reply in this thread...

  • Posted on Oct 01, 2008 at 09:18 AM

    >is there any event which gets triggered on change of value in >the drop down box .

    if you set the handler / register the edit event then DATA_CHANGED event will trigger.

    Did you see the programs

    BCALV_EDIT_06

    BCALV_EDIT_07

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 01, 2008 at 02:42 PM

    HI Vikram,

    Please check this thread

    Check our friend UWE reply in this thread --> alv-changing-internal-table-in-datachanged-event

    datachangedfinish-event

    Hope this would help you.

    Good luck

    Narin

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 02, 2008 at 05:10 AM

    Hello Vikram

    It appears that chosing a value from a dropdown box does not trigger any event itself (not even any F4-related event).

    I assume the ALV grid works similar like an Excel worksheet. If you change a cell value which is part of a sum function then you first have to hit the ENTER button before the sum is updated.

    In order to implement your requirement I have copied BCALV_EDIT_06 and have made the following changes:

    (1) Event handler class for DATA_CHANGED:

    ...
    *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
    
    
    CLASS lcl_eventhandler DEFINITION.
    
      PUBLIC SECTION.
    
        CLASS-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
              e_ucomm
              sender.
    
    ENDCLASS.                    "lcl_eventhandler DEFINITION
    
    
    *----------------------------------------------------------------------*
    *       CLASS lcl_eventhandler IMPLEMENTATION
    *----------------------------------------------------------------------*
    *
    *----------------------------------------------------------------------*
    CLASS lcl_eventhandler IMPLEMENTATION.
    
      METHOD handle_data_changed.
        BREAK-POINT.
    
        CALL METHOD cl_gui_cfw=>set_new_ok_code
          EXPORTING
            new_code = 'REFRESH'
    *      IMPORTING
    *        rc       =
            .
    
      ENDMETHOD.                    "handle_data_changed
    
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    
    
    
    DATA: ok_code LIKE sy-ucomm,
          save_ok LIKE sy-ucomm,
    ...
    

    (2) Register EDIT event and SET HANDLER (routine CREATE_AND_INIT_ALV):

    ...
    * Define a drop down table.
      PERFORM set_drdn_table.
    
      CALL METHOD g_grid->register_edit_event
        EXPORTING
          i_event_id = cl_gui_alv_grid=>mc_evt_enter
        EXCEPTIONS
          error      = 1
          OTHERS     = 2.
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
      SET HANDLER:
        lcl_eventhandler=>handle_data_changed FOR g_grid.
    
    
      SELECT * FROM sbook INTO TABLE pt_outtab UP TO g_max ROWS."#EC CI_NOWHERE
    ...
    

    (3) Event handler HANDLE_DATA_CHANGED just trigger PAI:

    *---------------------------------------------------------------------*
    *       MODULE PAI INPUT                                              *
    *---------------------------------------------------------------------*
    MODULE pai INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'EXIT'.
          PERFORM exit_program.
    
        WHEN 'REFRESH'.
          PERFORM refresh_list.
    
        WHEN OTHERS.
    *     do nothing
      ENDCASE.
    ENDMODULE.                    "pai INPUT
    
    *&---------------------------------------------------------------------*
    *&      Form  REFRESH_LIST
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    FORM refresh_list .
    * define local data
      DATA: ls_outtab   LIKE LINE OF gt_outtab.
    
      LOOP AT gt_outtab INTO ls_outtab.
        IF ( ls_outtab-wunit = 'KG' ).
          ls_outtab-class = 'C'.
        ELSE.
          ls_outtab-class = 'F'.
        ENDIF.
        MODIFY gt_outtab FROM ls_outtab INDEX syst-tabix.
      ENDLOOP.
    
      CALL METHOD g_grid->refresh_table_display
    *    EXPORTING
    *      is_stable      =
    *      i_soft_refresh =
    *    EXCEPTIONS
    *      finished       = 1
    *      others         = 2
              .
      IF sy-subrc <> 0.
    *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    
    ENDFORM.                    " REFRESH_LIST
    

    Procedure:

    1) Choose value from dropdown list

    2) Hit enter button

    3) Value in column CLASS changes according to chosen dropdown value

    Regards

    Uwe

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 03, 2008 at 06:13 AM

    Hi Vikram,

    Just an addition to the above post...

    If we register the cl_gui_alv_grid=>mc_evt_modified event,

    the data_changed event ll be raised at any user-action(Even placing the cursor on another cell)

    after modifying a cell...

    Kindly check the below code...

    *----------------------------------------------------------------------*
    *       CLASS lcl_event_responder DEFINITION                           *
    *----------------------------------------------------------------------*
    CLASS lcl_event_responder DEFINITION.
      PUBLIC SECTION.
        DATA  : ls_changed_cell TYPE  lvc_s_modi,
                lv_language     TYPE  spras..
        METHODS refresh_changed_data  FOR EVENT data_changed
                                      OF cl_gui_alv_grid
                                      IMPORTING er_data_changed
                                                e_ucomm.
    
    ENDCLASS.                    "event_responder DEFINITION
    
    DATA: go_handler         TYPE REF TO lcl_event_responder,
          go_grid            TYPE REF TO cl_gui_alv_grid,
          go_dummy_container TYPE REF TO cl_gui_container,
          gt_fieldcat        TYPE lvc_t_fcat,
          gv_language        TYPE spras VALUE 'E',
          gt_outtab          TYPE TABLE OF makt WITH HEADER LINE.
    
    CALL SCREEN 100.
    
    *---------------------------------------------------------------------*
    *       MODULE PBO OUTPUT                                             *
    *---------------------------------------------------------------------*
    MODULE pbo OUTPUT.
      SET PF-STATUS 'BASIC'.
      PERFORM create_and_init_alv CHANGING gt_outtab[]
                                           gt_fieldcat.
    ENDMODULE.                    "pbo OUTPUT
    *---------------------------------------------------------------------*
    *       MODULE PAI INPUT                                              *
    *---------------------------------------------------------------------*
    MODULE pai INPUT.
      LEAVE PROGRAM.
    ENDMODULE.                    "pai INPUT
    
    
    
    *&---------------------------------------------------------------------*
    FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
                                      pt_fieldcat TYPE lvc_t_fcat.
    
      CHECK go_grid IS NOT BOUND.
    
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = go_dummy_container.
    
      PERFORM build_display_table.
    
      PERFORM build_fieldcat CHANGING pt_fieldcat.
    
      PERFORM set_drdn_table.
    
      go_grid->set_table_for_first_display( CHANGING it_fieldcatalog      = pt_fieldcat
                                                     it_outtab            = pt_outtab ).
    
      go_grid->set_ready_for_input( 1 ).
    
    * raises the 'data_changed' event when we select another cell/any action after changing the data
      go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_modified ).
    
      CREATE OBJECT go_handler.
    
      SET HANDLER go_handler->refresh_changed_data FOR go_grid.
    
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&---------------------------------------------------------------------*
    FORM build_display_table.
      FREE gt_outtab.
      SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
    ENDFORM.                               "build_display_table
    *&---------------------------------------------------------------------*
    FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
    
      DATA ls_fcat TYPE lvc_s_fcat.
    
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'MAKT'
        CHANGING
          ct_fieldcat      = pt_fieldcat.
    
      LOOP AT pt_fieldcat INTO ls_fcat.
        IF    ls_fcat-fieldname EQ 'SPRAS'.
          ls_fcat-edit       = abap_true..
          ls_fcat-drdn_hndl  = '1'.
          ls_fcat-outputlen  = 8.
          ls_fcat-checktable = '!'.        "do not check foreign keys
          MODIFY pt_fieldcat FROM ls_fcat.
        ENDIF.
      ENDLOOP.
    
    ENDFORM.                               "build_fieldcat
    *&---------------------------------------------------------------------*
    FORM set_drdn_table.
    
      CHECK go_grid->offline( ) IS INITIAL.
    
      DATA: lt_dropdown TYPE lvc_t_drop,
            ls_dropdown TYPE lvc_s_drop.
    
      ls_dropdown-handle = '1'.
      ls_dropdown-value  = 'EN'.
      APPEND ls_dropdown TO lt_dropdown.
    
      ls_dropdown-handle = '1'.
      ls_dropdown-value  = 'DE'.
      APPEND ls_dropdown TO lt_dropdown.
    
      CALL METHOD go_grid->set_drop_down_table
        EXPORTING
          it_drop_down = lt_dropdown.
    
    ENDFORM.                                " set_drdn_table
    *&---------------------------------------------------------------------*
    FORM change_display_table USING pv_language pv_rowno TYPE i.
      READ TABLE gt_outtab INDEX pv_rowno.
      SELECT SINGLE * FROM makt INTO gt_outtab WHERE matnr = gt_outtab-matnr AND spras = pv_language.
      IF sy-subrc EQ 0.
        DELETE gt_outtab INDEX pv_rowno.
        INSERT gt_outtab INDEX pv_rowno.
      ELSE.
        CLEAR : gt_outtab-maktx,
                gt_outtab-maktg.
        DELETE gt_outtab INDEX pv_rowno.
        INSERT gt_outtab INDEX pv_rowno.
      ENDIF.
    ENDFORM.                    "change_display_table
    
    *---------------------------------------------------------------------*
    *       CLASS event_responder IMPLEMENTATION                          *
    *---------------------------------------------------------------------*
    CLASS lcl_event_responder IMPLEMENTATION.
      METHOD refresh_changed_data.
        READ TABLE er_data_changed->mt_mod_cells INTO ls_changed_cell INDEX 1.
        CALL FUNCTION 'CONVERSION_EXIT_ISOLA_INPUT'
          EXPORTING
            input  = ls_changed_cell-value
          IMPORTING
            output = lv_language.
        PERFORM change_display_table USING lv_language ls_changed_cell-row_id.
        go_grid->refresh_table_display( ).
      ENDMETHOD.                    "click
    ENDCLASS.                    "event_responder IMPLEMENTATION

    Cheers,

    Jose.

    Edited by: Jose on Oct 3, 2008 10:19 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 14, 2008 at 06:36 AM

    Thanks guys for your Valuable inputs .

    the event is working on enter .

    thank you once again for the helpful answers

    Regards,

    vikram

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.