10-01-2008 10:12 AM
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.
10-01-2008 10: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
10-01-2008 10:30 AM
no DATA_CHANGED does not get triggerred on change of value on drop down . yes i have seen those programs .
10-01-2008 12:13 PM
>
> 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...
10-01-2008 3:42 PM
10-02-2008 6: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
10-03-2008 7: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
10-03-2008 10:32 AM
if you go with cl_gui_alv_grid=>mc_evt_enter , then after editing you need to press enter button, then also it will trigger. if you don't check check it once.
10-05-2008 10:22 PM
Hello Vikram
I tested Jose's suggestion with my sample report and as I assumed the dropdown selection does not trigger any event. However, as soon as you move the cursor to any other cell the DATA_CHANGED event is triggered.
Thanks to Jose for his input.
Regards
Uwe
10-14-2008 7:36 AM
Thanks guys for your Valuable inputs .
the event is working on enter .
thank you once again for the helpful answers
Regards,
vikram