11-13-2019 3:40 PM
Hi there!
I often use the ALV grid in my programs. But mostly I use it for displaying data. The more I have to deal with the event DATA_CHANGED of CL_GUI_ALV_GRID the more I get annoyed because I always begin from scratch.
Each time I am not sure about how to deal with different actions.
Do you have a best practice template or some information about when to do what?
Some examples for some tricky actions in the grid:
Copying lines
In this case the MT_INSERTED_ROWS is filled and tells on which index the line has been copied.
Additionally the copied values are given in MT_GOOD_CELLS which need to be transferred.
If you do some validation checks here the user will get annoyed because of course the key is duplicate now (must be changed after copying lines), maybe dates are invalid (date in the past).
Checking and displaying key fields
Key fields normally should not be changed. If there are entries from the database, then they cannot be changed.
If there are new inserted entries I could change the key values as long as the data as not been saved.
Key fields must be set to read-only...
additional checks
after having inserted or changed data, I would like to validate the entries, like
Checks, that might be done when checking data and not of necessity when directly entered the field value. For example at USER_COMMAND &CHECK or after all entries have been updated.
In this case I might not have the protocol object and therefore I cannot display errors or warnings in this protocol. If I force to use a protocol object, it is not properly filled so that I cannot define a field or line where the error occured.
I am glad about any hints about how to generally deal with DATA_CHANGED.
Cheers
~Enno
johann.fleitner2 28f4b37a40894f18a22abc696b8154f4 maybe? 🙂
11-13-2019 5:03 PM
I got some hints (thanks pjl 😄 )...
There is one weird thing: If you change an entry using MODIFY_CELL, a new entry will be added to MT_GOOD_CELLS WITHOUT A VALUE!! That's weird but okay; the entry will be updated in MP_MOD_ROWS.
11-13-2019 10:25 PM
Hi,
I have done a lot with editable ALV GRID, but to be honest – many years ago. But I try to tell you my findings (as far as I remember).
Events DATA_CHANGED / DATA_CHANGED_FINISHED
I use the DATA_CHANGED event to get the updated and inserted data. I have always my own “GOOD_CELLS” in my developments, so after some additional checks (valid values, duprec) in the DATA_CHANGED event, I move the MOD_CELLS of the grid to a global GOOD_CELLS table in my development. I use the DATA_CHANGED_FINISHED to update the internal data table based on my own GOOD_CELLS table.
Delete, Insert, Copy
I always define my own functions for delete, insert or copy. I don’t use the standard alv functions because I want to handle as much as possible in my own handler class.
The handler class looks like this:
Save / Process changes
Like the delete/insert function, I use my own “SAVE” function.
Maybe it's not the best way to use the alv grid class, but it worked for me. - If you want to go in this direction, I would have to check my developments to give you more details.
lgf
11-13-2019 10:31 PM
Thanks for your answer!
I often heard that own insert and delete functions are used. Meanwhile I think it is because the implemented behaviour has not been understood. Thanks to Peter I understood today how this works.
The dynamic update/insert/ delete seems to be the hardest part... 😄