Interface Methods SAP ABAP Web Dynpro

A method of a component controller can be marked as interface. In this way, it is possible to access it cross-component. This option is possible only for the methods applied to the component controllers. The methods that take place in Views orWindows can’t be marked as interface.

For a better understanding of this kind of methods, we expand the previous example. In this example, after the user enters values and presses the “SHOW” button, the context attributes of the node STUDENT of the component Y_EM_CONTEXT_RM are populated with these values. When we want to verify if the user have entered his first name, we have to define an interface method in the component controller of this component, a method that verifies if this attribute has a value or it is empty. For this purpose, we create the interface method named check_firstname().

Marking a component controller method as interface

Marking a component controller method as interface

We create this method in the component Y_EM_CONTEXT_RM, because there is the context node where the values are transferred after the user presses the “SHOW” button.

Method check_firstname implementation

We read the value of the FIRSTNAME attribute into the local variable lv_firstname.After this, we verify if this attribute has a value or it is empty. In case this attribute is empty, we want to show a message with the string ‘The Field First name is empty!’.In this case, we have used the method REPORT_ERROR_MESSAGE of interface IF_WD_MESSAGE_MANAGER. To generate a message, we can use the Web Dynpro Code Wizard.

Usage of Web Dynpro Code Wizard

Usage of Web Dynpro Code Wizard

Is not recommended this art of programming, where the language-specific text elements are entered in the source text. In this case, we have used the easy way and not the best one. In the Chap.10, we explain how we can create messages easy to use and translate, without more programming effort.

After this method is implemented, we have to go back to the component Y_EM_LAYOUT_RM. When the user presses the SHOW button, we have to call the method check_firstname from the component use.If a method is marked as interface, we can cross-component access it. This means that we can call it from our onactionshow event handler method after we define a usage at the view level.

Usage definition

Usage definition

The coding from Listing shows the implementation of onactionshow event handler method.

Method call in used controller

We can use Web Dynpro Code Wizard to generate this code.

Web Dynpro Code Wizard

Web Dynpro Code Wizard

Runtime

Runtime



Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAP ABAP Web Dynpro Topics