07-03-2014 9:50 AM
Hi All,
I have a requirement to raise error message form editable oops alv . After entering the data and then press SAVE button .
Please help.
Thanks in Advance
07-03-2014 11:32 AM
Hi,
First handle you error in method
* Class to handle error after data change
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
*In the definition part of this method you can handle error message by using method *'add_protocol_entry'
* Identify columns which were changed and new input values of one row.
* Table er_data_changed->mt_good_cells holds all cells that
* are valid according to checks against their DDIC data.
* No matter in which order the input was made this table is
* ordered by rows (row_id). For each row, the entries are
* sorted by columns according to their order in the fieldcatalog
* (not the defined order using field COL_POS but the order
* given by the position of the record in the fieldcatalog).
* The order is relevant if new inputs in several columns of
* the same row are dependent.
* Loop over table MT_GOOD_CELLS to get the modified cells and
* their values.
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
data: urf_data_changed TYPE REF TO cl_alv_changed_data_protocol.
SORT er_data_changed->mt_good_cells BY row_id.
LOOP AT er_data_changed->mt_good_cells INTO lwa_good_cells.
CALL METHOD urf_data_changed->add_protocol_entry
EXPORTING
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = lwa_good_cells-fieldname
i_msgv2 = 'Field is blank/Invalid format'
i_fieldname = lwa_good_cells-fieldname " field on for which error message will be displayed
i_row_id = lwa_good_cells-row_id.
ENDLOOP.
07-03-2014 10:09 AM
Hi SK,
This can be achieved using the DATA_CHANGED event of the ALV. From within the event handler method for this event, you need to call a private method of the event handler class to handle the errors. From within this method, you have to check the entered data for correctness and if error is there, then you have to add the errors using the add_protocol_entry method and has to set a private variable of the event handler class.
From within the event handler class, if the private variable is set you have to call the display_protocol method.
Sample code can be obtained from the program BCALV_EDIT_03.
Regards,
Abijith
07-03-2014 10:49 AM
Means, user will press save button then :
you need to validate the data of alv grid and raise error if wrong data else save ?
07-03-2014 11:44 AM
07-03-2014 11:32 AM
Hi,
First handle you error in method
* Class to handle error after data change
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
*In the definition part of this method you can handle error message by using method *'add_protocol_entry'
* Identify columns which were changed and new input values of one row.
* Table er_data_changed->mt_good_cells holds all cells that
* are valid according to checks against their DDIC data.
* No matter in which order the input was made this table is
* ordered by rows (row_id). For each row, the entries are
* sorted by columns according to their order in the fieldcatalog
* (not the defined order using field COL_POS but the order
* given by the position of the record in the fieldcatalog).
* The order is relevant if new inputs in several columns of
* the same row are dependent.
* Loop over table MT_GOOD_CELLS to get the modified cells and
* their values.
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
data: urf_data_changed TYPE REF TO cl_alv_changed_data_protocol.
SORT er_data_changed->mt_good_cells BY row_id.
LOOP AT er_data_changed->mt_good_cells INTO lwa_good_cells.
CALL METHOD urf_data_changed->add_protocol_entry
EXPORTING
i_msgid = '0K'
i_msgno = '000'
i_msgty = 'E'
i_msgv1 = lwa_good_cells-fieldname
i_msgv2 = 'Field is blank/Invalid format'
i_fieldname = lwa_good_cells-fieldname " field on for which error message will be displayed
i_row_id = lwa_good_cells-row_id.
ENDLOOP.
07-03-2014 12:25 PM
07-03-2014 12:27 PM
You Declare and Implement this method globally at Declarations itself.
07-07-2014 7:31 AM
Hi SK,
In PAI you can handle error by using method 'check_changed_data'. This method will return output table with updated values that were entered on editable cells.
DATA: rf_grid TYPE REF TO cl_gui_alv_grid,
* Call method check_changed_data to check the error if any
CALL METHOD rf_grid->check_changed_data.
Now in PAI you can validate entered data one by one by putting loop on the displayed internal table and if any error exist then display error message by normal message statement.
ex:-
Loop at ta_output into wa_output
* do data validation if error found
MESSAGE e048(zotc) WITH wa_final-dvbeln.
Endloop.
07-03-2014 11:36 AM
HI SK,
Write a Local class (Event Handeler) to handel the events. In Editable ALV once the user enter a value, CL_GUI_ALV_GRID will raise an event called DATA_CHANGED.
1. Define and Implement a local class to handle that event.
In the implementation of this class you need to get data from imported object to an internal table, then compare the same with the ALV output table.
* Local Class to handler the events raised from the ALV Grid
CLASS LCL_EVENT_HANDLER DEFINITION.
PUBLIC SECTION.
* Method to handel EDIT event, DATA_CHANGED of CL_GUI_ALV_GRID
METHODS : ON_DATA_CHANGE FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
IMPORTING ER_DATA_CHANGED.
ENDCLASS.
* Event handler class Implementation
CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
METHOD ON_DATA_CHANGE.
DATA : LT_MODIFY TYPE LVC_T_MODI,
LS_MODIFY TYPE LVC_S_MODI.
* Copying changed data into intenal table from Object
LT_MODIFY = ER_DATA_CHANGED->MT_MOD_CELLS.
* Modifying the ouptut table with the changed values
IF LT_MODIFY[] IS NOT INITIAL.
*Compare the ALV Output table with LT_MODIFY
ENDIF.
ENDMETHOD.
ENDCLASS.
Then raise a message on required condition in the same method.
Note: To trigger the above method, you need to set event handler before displaying ALV (before calling method SET_TABLE_FOR_FIRST_DISPLAY)
* Creating object for the Local event handler class
CREATE OBJECT GR_HANDLER.
* Set handler (call method of Event_handler) to handler Edit event
SET HANDLER GR_HANDLER->ON_DATA_CHANGE FOR GR_GRID.
Regards,
Vijay