2007 Jan 24 10:57 AM
Hi Experts,
I need to display data in ALV grid using classes and objects and it has some input fields. And has one push button on screen if user enter anything in the input fields and press push button then those values have to be stored in Data base.
If user enter any data in the input fields and trying to come back with the help of F3 or back button with out saving the modified values then i need to show one pop-up with some message.
Now my doubt is how to capture the field changes in alv grid, and i want to know in which row user has changed the data, it means that row(s) only i need to modify in data base.
How to use data_changed method for capturing modified row(s) details.
Regards,
Bujji
Hi Experts,
I need to display data in ALV grid using classes and objects and it has some input fields. And has one push button on screen if user enter anything in the input fields and press push button then those values have to be stored in Data base.
If user enter any data in the input fields and trying to come back with the help of F3 or back button with out saving the modified values then i need to show one pop-up with some message.
Now my doubt is how to capture the field changes in alv grid, and i want to know in which row user has changed the data, it means that row(s) only i need to modify in data base.
How to use data_changed method for capturing modified row(s) details.
Regards,
Bujji
2007 Jan 24 11:04 AM
1. To capture the changed field u can do like this
FORM USER_COMMAND.....
<b>Data ref1 type ref to cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = ref1.
call method ref1->check_changed_data</b>
case sy-ucomm.
when...
endcase.
2. For ur requirment , when u click back u want to popup, u can go like this
WHEN 'SAVE'.
flag = 'X'.
WHEN 'BACK'.
IF flag ne 'X'.
display popup here
clear flag.
ENDIF.
ENDFORM.
2007 Jan 24 11:22 AM
hi,
The ALV Grid has events data_changed and data_changed_finished. The former method is triggered just after the change at an editable field is perceived. Here you can make checks for the input. And the second event is triggered after the change is committed.
You can select the way how the control perceives data changes by using the method register_edit_event. You have two choices:
i. After return key is pressed: To select this way, to the parameter i_event_id pass cl_gui_alv_grid=>mc_evt_enter.
ii. After the field is modified and the cursor is moved to another field:
For this, pass cl_gui_alv_grid=>mc_evt_modifies to the same parameter.
To make events controlling data changes be triggered, you must select either way by calling this method. Otherwise, these events will not be triggered.
To control field data changes, ALV Grid uses an instance of the class CL_ALV_CHANGED_DATA_PROTOCOL and passes this via the event data_changed. Using methods of this class, you can get and modify cell values and produce error messages. Here are some of those methods:
get_cell_value
Gets the cell value. You pass the address of the cell to the interface.
modify_cell
Modifies the cell value addressed via parameters.
add_protocol_entry
Add a log entry. You make use of standard message interface with message type, message id, etc
protocol_is_visible
Make the error table visible or not.
refresh_protocol
Refreshing log entries.
With the reference of the instance, you can reach information about modifications. These useful attribute tables are:
MT_MOD_CELLS : Contains addresses of modified cells with row_ids and fieldnames.
MP_MOD_ROWS : Contains modified rows. Its type is generic.
MT_GOOD_CELLS : Contains cells having proper values
MT_DELETED_ROWS:Contains rows deleted from the list
MT_INSERTED_ROWS:Contains rows inserted to the list
Utilizing these methods and attributes you can check and give proper message and also modify the cell content.
Checking the input together with anon-input value, adding a log and modifying the cell content
FORM handle_data_changed USING ir_data_changed
TYPE REF TO cl_alv_changed_data_protocol.
DATA : ls_mod_cell TYPE lvc_s_modi ,
lv_value TYPE lvc_value .
SORT ir_data_changed->mt_mod_cells BY row_id .
LOOP AT ir_data_changed->mt_mod_cells
INTO ls_mod_cell
WHERE fieldname = 'SEATSMAX' .
CALL METHOD ir_data_changed->get_cell_value
EXPORTING i_row_id = ls_mod_cell-row_id
i_fieldname = 'CARRID'
IMPORTING e_value = lv_value .
IF lv_value = 'THY' AND ls_mod_cell-value > '500' .
CALL METHOD ir_data_changed->add_protocol_entry
EXPORTING
i_msgid = 'SU'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = 'This number can not exceed 500 for '
i_msgv2 = lv_value
i_msgv3 = 'The value is et to ''500'''
i_fieldname = ls_mod_cell-fieldname
i_row_id = ls_mod_cell-row_id .
CALL METHOD ir_data_changed->modify_cell
EXPORTING i_row_id = ls_mod_cell-row_id
i_fieldname = ls_mod_cell-fieldname
i_value = '500' .
ENDIF .
ENDLOOP .
ENDFORM. " handle_data_changed
The event data_changed makes you aware about F4 functions. It sets the appropriate parameter from the group with respect to where it was triggered. These parameters are { E_ONF4, E_ONF4_BEFORE, E_ONF4_AFTER }.
hope this helps
PLZ reward if helpful.
2007 Jan 24 1:07 PM
Hi Kumar,
I just want to know in which row the changes has been done. If possible please provide the code (if you have any).
Bujji
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |