Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Grid - mark fields as changed

Former Member
0 Kudos

I have an editable ALV grid, and when the user changes field values then the data_changed event is called correctly so I can validate the changes.

I am now implementing an upload method which replaces the values in the data table. The problem is that the control does not recognise the lines as new or changed, so does not do any checking on them or pass to the data_changed event.

I can use method if_cached_prop~set_prop ( propname = 'GridModified' propvalue = '1' )

to set the grid modified flag, but get_modified_cells returns an empty table so there are no fields passed to my data_changed implementation.

I think I could use method CHANGE_DATA_FROM_INSIDE to set the new values. However, it is marked as internal only, and it will be very tedious to fill the tables...

Is there any way to flag fields as changed?

Alternatively, if I do my checks in my upload method, is there a way to add messages to the output log?

Thanks

Michael

1 REPLY 1

Former Member

I have worked out a solution.

I can use method CHANGE_DATA_FROM_INSIDE, and as long as layout-val_data = 'X' then the data_changed method is called to do validations. However, the data in fields with errors is deleted...

My alternative solution is to store the uploaded values and when checking the data, put the uploaded values manually into er_data_changed->mt_good_cells. The trick is to manually set the grid status to modified, so that the data_changed handler implementation is called - this is done with METHOD gr_grid_0200->if_cached_prop~set_prop.

The ALV grid data is in <outtab> which has all fields of <outtab> plus a few extras

I upload from file into <data_table>.

data:

ls_mod_cell type LVC_S_MODI.

*     Add correct tabix and celltab fields.
      refresh <outtab>.
      clear <gs_outtab>.

*     Move to outtab structure and put into grid table
      loop at <data_table> assigning <data>.
        move-corresponding <data> to <gs_outtab>.
        insert <gs_outtab> into table <outtab>.

*       Store the field data for validations
        ls_mod_cell-row_id = sy-tabix.
        ls_mod_cell-tabix = sy-tabix.
        ls_mod_cell-SUB_ROW_ID = fl_uploaded.
        LOOP AT gt_fieldcat_0200 ASSIGNING <fcat>
                where tech = '' and no_out = ' '.
          ls_mod_cell-fieldname = <fcat>-fieldname.
          assign component <fcat>-fieldname of structure <data> to <value>.
          if sy-subrc = 0.
            ls_mod_cell-value = <value>.
            insert ls_mod_cell into table t_mod_cells.
          endif.
        Endloop.

      endloop.

*     Update the table display.  This resets the internal version of the data table.
      CALL METHOD gr_grid_0200->refresh_table_display.

*     Force the GridModified flag to on
      CALL METHOD gr_grid_0200->if_cached_prop~set_prop
        EXPORTING
          propname           = 'GridModified'
          propvalue          = '1'
        EXCEPTIONS
          others             = 0              .

In the local method for handle_data_changed, I can then use the stored data

*   When importing data from file, the fields are not checked
*   Add uploaded values to the data_changed tables
*   (First remove any fields which have been subsequently changed by the user)
    if t_mod_cells is not initial.
      loop at er_data_changed->mt_mod_cells into ls_mod_cell.
        delete t_mod_cells
               where row_id    = ls_mod_cell-row_id
               and   fieldname = ls_mod_cell-fieldname.
      endloop.
      insert lines of t_mod_cells into table er_data_changed->mt_good_cells.
      insert lines of t_mod_cells into table er_data_changed->mt_mod_cells.
    endif.

   ....  Validation code ...

*   Remove uploaded fields.  Otherwise any without error will blank out the value in the grid...
    delete er_data_changed->mt_good_cells where SUB_ROW_ID = fl_uploaded.
    delete er_data_changed->mt_mod_cells where SUB_ROW_ID = fl_uploaded.

*   If no errors, remove uploaded data
    if error_in_data EQ space.
      clear t_mod_cells.
    endif.