Raising “pop up to confirm” dialogs in SAP web templates – part 2
When important functionality is executed in a web template by a click on a button, it is helpful to have a dialog with the user to ensure that he didn’t press the button by accident and really wants to execute certain actions. Therefore usually a small dialog window which contain texts like “Do you really want to perform this action” is presented to the user and he needs to click a “yes” or “no” button. We call this kind of dialog “pop up to confirm” dialogs. This paper demonstrates how pop up to confirm dialogs can be implemented in SAP web templates. This is modeled within the SAP standard.
Author(s): Matthias Nutt
Created on: 31 December 2013
For technical reasosn the document is split into different parts. This document is part two. Here you can find part one:Raising “pop up to confirm” dialogs in SAP web templates
4 Enhancing the main template to execute a planning functionality
To enhance the simple example we choose a scenario where a simple planning function should be executed. This requires the implementation of the planning function and another popup web template.
4.1 Creating a simple planning function
The planning modeler is started via transaction RSPLAN. There we create a planning function named DEMO_REVAL on aggregation level DEMO_ALV. As planning function type we choose the standard revaluation function and hard code the revaluation to 10% for all key figures. This simple approach is sufficient for our purpose.
4.2 Creating the revaluation popup web template
For the “pop up to confirm”-approach we follow the same principle as explained earlier. We create web template DEMO_POPUP_TO_CONFIRM_REVAL. It contains a simple question “Do you really want to add 10%?” and two buttons (“yes” and “no”). The “no” button executes command CANCEL_TEMPLATE_DIALOG. The “yes” button calls the planning function and the command OK_TEMPLATE_DIALOG. In this example we don’t hand over variables to keep things simple. So the planning function works on the data in the assigned data provider. Please refer to the screenshots for details.
At this point it is important to notice that data provider DP_MAIN_1 is not included in this pop up web template. Therefore it is not selectable directly in the dropdown box. Nevertheless pressing the key “F11” allows us to enter the name of the data provider manually. As the data provider is not defined here, the system derives it from the main template during the web template execution.
4.3 Adding a button for the planning function to the main web template
Here we modify the main web template to include a new button, which starts the revaluation pop up web template. A new button “Add 10%” is added to the button group BUTTON_GROUP_MAIN_1.
Now we can test the revaluation functionality from the main web template. We start it again and can see that new button as indicated in the screenshot below.
Clicking on “Add 10%” opens the recently created web template, which acts as a “pop up to confirm” dialog as shown in the screenshot below.
And now the numbers change if we click the “yes” button and stay the same if the “no” button is clicked. If you have more complicated planning functionality you will need to include some variable binding here as well. This was not necessary in this small example here.
4.4 Displaying messages
It is important to enhance the example further as we want to see the messages which are generated before, during or after the planning function execution. With the current approach this is not possible. To be able to see the system messages we need to use a little trick. The trick is to execute the planning function and modify the attributes of some web items, but not close the web template. Closing the web template will be done with an additional click.
There are different ways to model this behavior. We choose the following approach. The “yes” button will remain in button group BUTTON_GROUP_POPUP_REVAL1. For the “no” button a new button group BUTTON_GROUP_POPUP_REVAL_2 is created. The “no” button executes command CANCEL_TEMPLATE_DIALOG as before. The main difference is implemented in button group BUTTON_GROUP_REVAL_1. We remove the “no” button here first, because it is now defined in the other button group. Next we change the commands of the “yes” button. It will execute the following commands now:
- Execute the planning functionality as before
- Change the text of web item TEXT_POPUP_REVAL_1 to “Please check the messages and close this window”
- Hide the “no” button
- Change the “yes” button text into “close this window” and the command into OK_TEMPLATE_DIALOG
This will achieve the desired behavior. The planning functionality will be executed and the messages will be displayed. The question is transformed into an information message to the user and a “close” button appears. In addition, the “no” button disappears. The following screenshots explain the details. The first one shows the button group BUTTON_GROUP_POPUP_REVAL2 which contains the “no” button.
The next screenshot sequence shows BUTTON_GROUP_POPUP_REVAL_1 and all details for the “yes” button. We can see that all the steps are executed. First the planning function, second the text is changed, third the “no” button is hidden and finally the “yes” button is redefined.
In the second step the text is changed. The web item TEXT_POPUP_REVAL_1 contains the question. In this step a new text is assigned to the web item. This is shown in the next screenshots.
In the third step the button group BUTTON_GROUP_POPUP_REVAL2 is set to hidden. This will hide the “no” button the easy way. Please see the screenshots below for details.
4.5 Enabling dynamics for the revaluation factor
In this step we would like show more details of how variable could be handed over to the pop up to confirm dialog. Therefore we add some dynamics to the revaluation factor. Currently it was hard coded to 10%. If we search for a business example in help.sap.com, we can find a page which describes how the revaluation factor can read its value from a variable (You can find the link to that page at the end of this paper). The variable value itself gets its value from an input box in the web template. We enrich that example a bit. We use a dropdown box to determine the value of the revaluation factor. The dropdown box stores its value in the input box, which we hide from the user. So we create a variable named DEMO_REVAL for the factor directly from the planning function in the planning modeler. We open planning function DEMO_REVAL in change mode, use the F4 for field “percentage” and create the variable DEMO_REVAL. The variable input is optional and the variable is ready for input. The dimension indicator is set to number and we don’t use default values. We choose our new variable in the percentage field.
Now we need to implement the changes in the main web template DEMO_POPUP_TO_CONFIRM_MAIN. We create a new input field named INPUT_FIELD_REVAL_FACTOR and set its text to 5 and the visibility to hidden.
Next we create a new dropdown box DROPDOWN_MAIN_1, which uses a fixed list of options (5 % and 10 %). Then we model the action in a way that these values will be stored in the hidden input field INPUT_FIELD_REVAL_FACTOR. Therefore the command SET_ITEM_PARAMETERS is used to overwrite the value in the hidden input field.
In the planning function definition variable DEMO_REVAL is used. We are binding that variable to read its input from the string in hidden input field INPUT_FIELD_REVAL_FACTOR, which is defined in the main web template. As we cannot not select INPUT_FIELD_REVAL_FACTOR using the dropdown box directly again we press F11 and enter INPUT_FIELD_REVAL_FACTOR manually.
Finally we change the text in text box TEXT_POPUP_REVAL_1 to a more generic text “Do you really want to execute the revaluation?”. Then we test the main web template, which results in the following screenshots if we choose 5 % revaluation.
This example showed the potential of the approach and that is it possible to use items in the popup web templates which are defined in the main web template. This way data provider filters or selections and other web items attributes can be used to communicate and influence the behavior mutually.
Raising “pop up to confirm” dialogs in SAP web templates
SAP Help – Display Web Template as Modal Dialog
SAP Help – Close Current Web Template Dialog with Cancel
SAP Help – Close Current Web Template Dialog with OK
SAP Help – Revaluating Planning Functions
Show alert message in Web Application Designer before planning sequence execution