Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
In many scenarios the user makes changes to the data. Maybe presses Save now and then. Then wants to revert... and here are some familiar quotes (swearwords left out):
"What was the previous price on that item?"
"Or was it the one before it?"
"And the product code, do you recall that?"
"But I can't! I already pressed Save!"
"Don't they have Undo in this thing?"
Having the Undo option adds great value. This includes a scenario with a Save action: Did you save the wrong value? Undo it and Save again.
In this document we focus on simple editing of values in a form. Here is the example application:
The Undo action is made possible by holding a list of "past" actions. The same goes for Redo with "future" actions. Here is the same application with the debugging panel made visible, showing these lists:
Do, Undo and Redo
It is easy to think of this as a person going through a time axis. Undo moves us back, Redo moves us forward.
Do - change of value - moves us forward towards a "new future", as we could only have one.
Here is a basic example with values:
Action
Past
Present
Future
Starting with value A and changing to B and then C
Undo
Undo
Redo
Modeling
We hold lists for Past and Future values, that we can use in Undo / Redo actions.
When the user changes a value, we need to pass the former value to the past, but we only know the new value! So we must hold in memory the Present too. When the UI changes, we use it to get previous UI values.
Modeling steps:
1. Add a Form View and define two fields - Text (TXT1) and Date (Date1).
2. Add three Data Share elements, for the past, present and future.
3. Define the cardinality to be Record Set (0..n).
4. Define the same set of fields: Text (TXT1) and Date (Date1) fields.
5. For the present data share open from the Define Data dialog the Initialize Data dialog, and add one record.
6. Add a Panel element, set its visibility to false (in the Configuration Panel).
7. Connect Grid View elements to the Data Shares, and place them inside the Panel. They are used for debugging / testing.