First we have to define the method and sub programs. In the definition part of our events class, include a code as the following:
CLASS lcl_event_handler DEFINITION .
PUBLIC SECTION .
METHODS:
...
....
on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display.
....
ENDCLASS.
PUBLIC SECTION .
METHODS:
...
....
on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname
es_row_no
er_event_data
et_bad_cells
e_display.
....
ENDCLASS.
For the implementation part, code can be as follows:
CLASS lcl_event_handler IMPLEMENTATION .
.....
....
METHOD on_f4.
CLASS lcl_event_handler IMPLEMENTATION .
.....
....
METHOD on_f4.
PERFORM on_f4 USING e_fieldname
es_row_no-row_id
er_event_data
et_bad_cells
e_display
er_data_changed.
er_event_data->m_event_handled = 'X'.
ENDMETHOD. "on_f4
.....
.....
ENDCLASS .
es_row_no-row_id
er_event_data
et_bad_cells
e_display
er_data_changed.
er_event_data->m_event_handled = 'X'.
ENDMETHOD. "on_f4
.....
.....
ENDCLASS .
Within our main program after displaying the table (by method set_table_for_first_display), we have to create the event handler object and set the handlers for these events.
CREATE OBJECT gr_event_handler .
CREATE OBJECT gr_event_handler .
*--Registering handler methods to handle ALV Grid events
.....
.....
SET HANDLER gr_event_handler->on_f4 FOR gr_alvgrid .
PERFORM register_f4_fields. "set cells with search help
.....
.....
SET HANDLER gr_event_handler->on_f4 FOR gr_alvgrid .
PERFORM register_f4_fields. "set cells with search help
*§3.Optionally register ENTER to raise event DATA_CHANGED.
call method gr_alvgrid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
...... ....... ......
call method gr_alvgrid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
...... ....... ......
FORM register_f4_fields. "which fields will have F4 search help DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE .
DATA: lt_f4_data TYPE lvc_s_f4.
lt_f4_data-fieldname = 'CHARG'.
lt_f4_data-register = 'X' .
* lt_f4_data-getbefore = 'X' .
lt_f4_data-CHNGEAFTER ='X'.
lt_f4_data-fieldname = 'CHARG'.
lt_f4_data-register = 'X' .
* lt_f4_data-getbefore = 'X' .
lt_f4_data-CHNGEAFTER ='X'.
INSERT lt_f4_data INTO TABLE lt_f4.
lt_f4_data-fieldname = 'LGORT'.
lt_f4_data-register = 'X' .
* lt_f4_data-getbefore = 'X' .
lt_f4_data-CHNGEAFTER ='X'.
lt_f4_data-fieldname = 'LGORT'.
lt_f4_data-register = 'X' .
* lt_f4_data-getbefore = 'X' .
lt_f4_data-CHNGEAFTER ='X'.
INSERT lt_f4_data INTO TABLE lt_f4.
CALL METHOD gr_alvgrid->register_f4_for_fields
EXPORTING
it_f4 = lt_f4[].
ENDFORM. "register_f4_fields
EXPORTING
it_f4 = lt_f4[].
ENDFORM. "register_f4_fields
The main sub program where we handle the changed cell value is as follows:
FORM on_f4 USING P_E_FIELDNAME
ROW_ID
P_ER_EVENT_DATA
TYPE REF TO CL_ALV_EVENT_DATA
P_ET_BAD_CELLS
P_E_DISPLAY
IR_DATA_CHANGED
TYPE REF TO cl_alv_changed_data_protocol.
ROW_ID
P_ER_EVENT_DATA
TYPE REF TO CL_ALV_EVENT_DATA
P_ET_BAD_CELLS
P_E_DISPLAY
IR_DATA_CHANGED
TYPE REF TO cl_alv_changed_data_protocol.
DATA: BEGIN OF value_charg OCCURS 0, "the value table that is passed to F4 fm
charg like zpp_kpduzelt-charg,
lgort like zpp_kpduzelt-lgort,
clabs like mchb-clabs,
END OF value_charg.
charg like zpp_kpduzelt-charg,
lgort like zpp_kpduzelt-lgort,
clabs like mchb-clabs,
END OF value_charg.
DATA : ls_mod_cell TYPE lvc_s_modi ,
ls_del_cell TYPE lvc_s_moce ,
ls_good_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value .
ls_del_cell TYPE lvc_s_moce ,
ls_good_cell TYPE lvc_s_modi,
lv_value TYPE lvc_value .
DATA : ls_mod_row like line of gt_list.
.....,
.... *§5 define fields and field-symbols for data-update
field-symbols: type lvc_t_modi.
data: ls_modi type lvc_s_modi.
create object ir_data_changed.
SORT ir_data_changed->mt_mod_cells BY row_id .
.....,
.... *§5 define fields and field-symbols for data-update
field-symbols:
data: ls_modi type lvc_s_modi.
create object ir_data_changed.
SORT ir_data_changed->mt_mod_cells BY row_id .
INTO ls_mod_cell.
ENDLOOP.
when 'CHARG'.
......
* here must be the code to fill in the possible values table
* and the call to fm F4IF_INT_TABLE_VALUE_REQUEST
......
EXPORTING
retfield = 'CHARG'
value_org = 'S'
* DYNPPROG = SY-REPID
* DYNPNR = SY-DYNNR
* DYNPROFIELD = 'PRUEFLOS'
TABLES
value_tab = value_charg
* field_tab = field_tab
return_tab = return_tab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0 and return_tab-fieldval <> ''.
ls_mod_cell-row_id = row_id.
ls_mod_cell-fieldname = 'CHARG'.
move charg to lv_value.
ls_mod_cell-value = lv_value.
IMPORTING
et_fieldcatalog = lt_fcat.
create data lp_wa like line of gt_list.
assign lp_wa->* to
read table lt_fcat
with key fieldname = ls_mod_cell-fieldname into ls_fieldcat.
move ls_fieldcat-ref_table to l_tabname.
move ls_fieldcat-fieldname to l_fieldname.
assign component ls_fieldcat-fieldname
of structure wa_tab
to
*and
* fill the table.
append ls_mod_cell to
....
....
ENDIF.
....
.....
endcase.
ALSO READ:
- Implementing F4 Search Help In OO ALV Grid Display.
- List Of Transport Requests In ALV Format.
- ALV Report With User Defined Buttons In It's Toolbar.
- ALV Report Program - Colors- Using REUSE_ALV_GRID_DISPLAY_LVC.
..... Back To Index On ALV List/ Grid Display.
..... Back To MAIN INDEX.
Thanks a lot, your post was very hopeful for me expecialy in this part: er_event_data->m_event_handled = 'X'.
ReplyDelete