So far, we have used only context attributes that were defined in the view context.When we want to share data among different controllers, we have to define a context mapping.
A context mapping can be an internal context mapping or an external context mapping. An internal mapping relationship can be defined between any pair of controllers within the same WD component, whereas the external mapping defines a mapping across the borders of a WD component.
Internal Context Mapping
As mentioned before, the mechanism for sharing data among different controllers within the same WD component is known as internal context mapping.For a better understanding of this mechanism, we create the same example from data binding, but in this case we create the two groups GRP_STUDENT_READ and GRP_STUDENT_WRITE, in different views. At runtime, we display the view V_VIEW1.When the user presses the “SHOW” button, we display the second view V_VIEW2. The WD component structure is presented.
WD component structure
We cannot create the context node in the view context, because we need the values of this attributes not only in the view V_VIEW1, but in the view V_VIEW2 as well.In this case,we create the node STUDENT in the context of component controller.In this way,through context mapping, we can access the context of the component controller via a view controller.Context mapping doesn’t cause the duplication of data.The nodes in the view controllers only hold a reference to the mapping context node from the component controller.
Internal context mapping
We firstly create the context node of the component controller. After this, we make a context mapping between the context of the view V_VIEW1 and the context node of component controller. As a result, the entire context node STUDENT is mapped.In the same way, we proceed to make a context mapping between the context of the view V_VIEW2 and the context of component controller.Consequently,we have to create the view layout for the views V_VIEW1,V_VIEW2 and the data binding.Data stored in the context of the component.
The mapping result
controller can be used within a view if we have firstly made a context mapping.The schematic representation is presented.
Intern context mapping, data binding
The lines between controllers symbolize the context mapping, and the lines between view controllers and the views layout symbolize the data binding.In the view V_VIEW1, we create the group GRP_STUDENT_WRITE and then we can use the view context to create a “Container Form”.Because we want to show both views in the same window,after the user presses the “SHOW” Button we use a ViewContainerUIElement.
View layout for V_VIEW1
We have to embed the view V_VIEW2 in the ViewContainerUIElement.
Embed view V_VIEW2
We have to embed the view V_VIEW2 in the ViewContainerUIElement (Fig.).
Embed view V_VIEW2
After creating an application,we can see the result. At runtime, the User Interface is the same as for the data binding (example – Fig.)The difference is the context mapping. In this case, the context is not defined in the view context, but in the context of the component controller, and can be accessed through context mapping. The data reside in the context node of the component controller context, and the context node of the views controller simply holds a reference to this.
External Context Mapping
External mapping is a cross-component mapping and can be directly mapping or reversely mapping. We can create an external context mapping if we have firstly declared a usage for the component that holds the respective context and the respective context node has been marked as interface.
As a briefly description of this kind of mapping, we can say that the external mapping of direct mapping type is a cross-component mapping in which the main component directly access the data (represented through the context structure) of the used component.
For a better understanding of this type of mapping, we create the same example for the internal mapping, but in this case we create two WD components.The component Y_EM_LAYOUT has two Views used to create the user interface.To hold the data entered by the user, we use the context node STUDENT.To be able to access this context node, we have to define a component usage.In WD, the component Y_EM_LAYOUT defines a usage of the component Y_EM_CONTEXT.
WD component structure
In real cases, a faceless component is useful if several components access the same set of data. This type of component can be used to create a model for a multicomponent application.We firstly create the context node in component controller of the component Y_EM_CONTEXT. We keep the same context node STUDENT, but in this case we create an interface node. If this node has not defined the interface type, we cannot access it from another component.
Context node structure
The component Y_EM_LAYOUT has two Views used to create the user interface. To hold the data entered by the user, we use the context node STUDENT. To be able to access this context node, we have to define a component usage.In WD, the component Y_EM_LAYOUT defines a usage of the component Y_EM_CONTEXT
Defining a Usage in a component
After the usage is defined, we have to create a controller usage in the component controller. We need to use the component Y_EM_CONTEXT,the component use (named CONTEXT) and, hence, we need the INTERFACECONTROLLER
Controller usage definition
The next step is to define a mapping. In this case, it is an external mapping, because the node we use to define the mapping is outside the component
Defining an external mapping
As a result, the entire context node is mapped.
The mapping result
In the Methods tab, we have to verify in the wddoinit( ) Hook Method if it is aninstance of the used component. The coding from Listing shows how we canverify this and how can be created in case it doesn’t exist.
Checking an instance of the used component
By using the method HAS_ACTIVE_COMPONENTof the IF_WD_COMPONENT_USAGE, we verify if the usage has an active component.If the component has already been initialized, the logic moves on otherwise, we create an instance of the component by using the CREATE_COMPONENT method of the same interface. We must ensure that the external component has been instantiated before the interface controller is accessed.
It is recommendable to create a usage for a component only in the moment we need it.In our little example, we have to create the usage in the wdDoInit Hook method, but,in case we use navigations plugs to navigate to a used component,it is recommendable to create the usage in the method used to fire the respective plug.
Further, we can proceed as in the previous example: we create an internal mapping between the context node of the component controller and the context view of the views V_VIEW1 and V_VIEW2. After this, we can create the data binding.All these are schematically presented.The line between WD components symbolizes the external direct context mapping, the lines between component controller and views controllers symbolize internal mapping, and the lines between view controllers and views layout symbolize the data binding.
As a briefly description of this king of mapping, we can say that the external mapping of the reverse mapping type is a cross-component mapping in which the data (represented through the context structure) are put at our disposal by the main component.
To realise the screen based on them, we use the interface view of the used component.For a better understanding of this type of mapping, we create the same example from direct mapping,where we change only the implementation part. We create two WD components, named Y_EM_CONTEXT_RM and Y_EM_LAYOUT_RM. The WD components structure is presented.We define, in the component Y_EM_CONTEXT_RM, the context node STUDENT.This component has no view, because we embedded here the interface view
Schematic representation of an external direct mapping
WD components structure
of the component Y_EM_LAYOUT_RM.The component Y_EM_LAYOUT_RM implements the user interface,making usage of the component Y_EM_CONTEXT_RM required to have access to the STUDENT node. Schematically, all these are presented.We firstly create the context node in the component controller of the component Y_EM_CONTEXT_RM, by using the same context node STUDENT and interface node.
Schematic representation of an external reverse mapping
The component Y_EM_LAYOUT_RM implements the user interface. In component controller, we create a node named STUDENT, with the same structure as the node STUDENT from the component controller of the component Y_EM_CONTEXT_RM.
After creating the node, we make an internal mapping, we create the user interface and make the data binding. Another solution is to copy the component Y_EM_LAYOUT and to make the proper changes. We can copy this component by right-clicking on the component name, and choose “Copy” from the contextual menu. We have to specify a name for the new component and a package where we want to save this component.We define a usage of the component Y_EM_CONTEXT_RM and create an external mapping, reverse mapping.
Interface node, Input element
Context structure after usage and mapping
After entering the coding required to verify if it is an instance of the used component, we can save and activate.For the next step, we go back to the component Y_EM_CONTEXT_RM, where we have to define a usage for the component Y_EM_LAYOUT_RM, required to be able to embed its interface view.
After this, we can embed the interface view of the component for which we have defined only the usage. The Framework generates a corresponding interface view when we create a window. This interface can be embedded by other component,after the usage was defined. To embed the interface view or windows of the Y_EM_LAYOUT_RM component, we proceed in the same way as for embedding the views.
Defining the usage
Y_EM_LAYOUT_RM component, we proceed in the same way as for embedding the views.
After entering the coding required to verify if an instance of the used component exists, we can save, activate and run the application.
SAP ABAP Web Dynpro Related Tutorials
|SAP ABAP Tutorial|
SAP ABAP Web Dynpro Related Interview Questions
|SAP ABAP Interview Questions||SAP ABAP Web Dynpro Interview Questions|
|Sap Abap Hr Interview Questions||SAP ABAP Dictionary Interview Questions|
|SAP ABAP Enhancement Interview Questions||SAP ABAP Module Pool Interview Questions|
|SAP ABAP Report Developer Interview Questions||SAP ABAP Data Dictionary Interview Questions|
|SAP ABAP ALV Reports Interview Questions|
Sap Abap Web Dynpro Tutorial
Sap Easy Access
Designing A Web Dynpro Component
Context Nodes And Attributes At Design Time
Data Binding, Context Mapping And Interface Methods
View Controller Methods
Layout Ui Elements
User Interface Elements (ui Elements) Static And Dynamic Programming
Messages, Exceptions And Web Dynpro Abap
Writing Multilanguage Applications
Alv And Select Options
Integrating A Web Dynpro Application Into The Sap Netweaver Portal
Web Dynpro And Authorization
Web Dynpro Mind Map
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.