Let’s Web Dynpro. Part IV

In Part III, we displayed a simple output with multiple lines as output. If you check the initial screen, it has the input fields, dates, execute button and the output table structure. In acutal project, user would not like to see the blank output table structure. Also, user would like to get an error message if the mandatory fields are missing.

In this post, we would show, how to declare the UI elements as mandatory and also how to show the output elements (in this case the output table) only when it is needed, dynamically.

On your mark, get set, go…. ?

A) Output table visibility to be dynamically controlled.

Check the blank output table with SO, Created no/by and SO Type. If you are the user, you would NOT like to see these structure, when you are in the initial screen.

Why is it displaying?

Because, we have hardcoded the UI element to be always visible (as shown in screen shot).

Solution:

Instead of hard coding it to visible, we should point it to a variable, which should be blank (false) when the user first enters the screen. Once the user hits the execute button, that variable should be flagged (true) to indicate the visibility.

How to do control the visibility?

Step 1: Define a context node (cardinality 1:1 should be enough) and define an attribute (say set_table_visible). This attribute is our variable, which we would bind with the output table visibility parameter.

Step 2: Bind the visibility property with set_table_visible attribute as shown in figure. Done!! The output structure would not be visible now.

Step 3: But, it would not be visible even if you hit execute. Because, you have not written the logic to set the attribute to true, when execute button is hit. In the method which is called on execute button, set the attribute to true, using the magical wand as shown in the screenshot.

After removing the commented lines, your code should look like below. You just need to set the variable to ‘X’ or ABAP_TRUE. Only one line of code has to be written as shown in line 43 of screenshot.

Step 4: Test it. Your output is visible only when you hit the Execute button.

B) Error message should be displayed if mandatory fields are not entered

Step 1: Make the State property of the input field to “required”. This would put a small red asterisk (*).

Begin a developer, we assume our work is done. Now Web Dynpro framework should handle it automatically. But, we need to implement one more step.

Step 2: In the event handler method which is triggered by your button (ONACTIONEXECUTE for this example), we need to write the below piece of code. Basically, it calls standard method check_mandatory_attr_on_view and give the missing mandatory fields message.

Web Dynpro would show the message in default area. We can define our message area and show the message in the place where we want in the screen.

Check the output.