I've added a custom button to the toolbar to upload an Excel file and display its content in an ALV grid. When the user clicks on 'save,' it appends the Excel data to the main data dictionary table. However, an issue arises with certain fields that have search help values. The ALV is unable to validate incorrect cell values that don't match the defined search help values. Interestingly, when manually inserting a row and adding data, any discrepancies prompt an error log.
MODULE display_data_0600 OUTPUT.
DATA : lwa_layout_0600 TYPE lvc_s_layo.
DATA : wa_stable_upld TYPE lvc_s_stbl.
IF <excel_table> IS ASSIGNED.
ASSIGN <excel_table> TO <all_table_new>.
UNASSIGN <excel_table>.
ENDIF.
* IF gt_cust_new_upld IS NOT INITIAL.
* CLEAR gt_cust_new_upld.
* CLEAR gt_grid_new_upld.
* ENDIF.
IF gt_cust_new_upld IS INITIAL.
CREATE OBJECT gt_cust_new_upld
EXPORTING
container_name = cust_new_upld.
CREATE OBJECT gt_grid_new_upld
EXPORTING
i_parent = gt_cust_new_upld.
CLEAR lwa_layout_0600.
lwa_layout_0600-cwidth_opt = 'X'.
CALL METHOD gt_grid_new_upld->set_table_for_first_display
EXPORTING
is_layout = lwa_layout_0600
it_toolbar_excluding = it_exclude_0500
CHANGING
it_fieldcatalog = it_cat_new
it_outtab = <all_table_new>.
IF event_new IS INITIAL.
CREATE OBJECT event_new.
ENDIF.
FIELD-SYMBOLS: <fs_data> TYPE any,
<fs_val> TYPE any.
REFRESH gt_mod.
LOOP AT <all_table_new> ASSIGNING <fs_data>.
ASSIGN COMPONENT 1 OF STRUCTURE <fs_data> TO <fs_val>.
IF sy-subrc = 0.
gt_mod-alv_indx = <fs_val>.
gt_mod-indx = <fs_val>.
gt_mod-type = 'I'.
gt_mod-save = 0.
ENDIF.
APPEND gt_mod.
UNASSIGN <fs_val>.
ENDLOOP.
***************************************************************
gt_grid_new_upld->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
gt_grid_new_upld->register_edit_event( i_event_id = cl_gui_alv_grid=>mc_evt_modified ).
SET HANDLER event_new->handle_data_changed_new_upld FOR gt_grid_new_upld.
SET HANDLER event_new->handle_toolbar_new FOR gt_grid_new_upld.
*******CHANGED**********
* SET HANDLER event_new->handle_toolbar_upld FOR gt_grid_new_upld.
SET HANDLER event_new->handle_user_command_new FOR gt_grid_new_upld.
******************************
CALL METHOD gt_grid_new_upld->set_toolbar_interactive.
ENDIF.
here <excel_table> is internal table of excel data.
How to solve this problem ?
You need to use method
CHECK_CHANGED_DATA
ofgt_grid_new_upld
at PAI of your program.It will check for consistency of foreign keys.
See program
BCALV_GRID_EDIT
for examples of editable ALV.