Friday, July 25, 2008

Example for the Implementation of an Interface Definition Component Usages Web Dynpro ABAP

The example below illustrates the principle of the interface definition and implementation by means of an actual development situation.

The static case described here is basically designed to demonstrate the principle; in the practice, it will be of limited use, because it requires all involved components of the using component to be known already at design time. And certainly, the implementation of interface definitions is most advantageous when this knowledge is missing at design time and the desired implementation of the interface is selected only at runtime. For more information on interface implementations, see the third part of this documentation: Dynamic Programming.

A central Web Dynpro component for travel expense management uses different components with related detail information, among them the components for flights, hotels and rented cars. In an interface definition IF_TRAVEL_COSTS a node is defined, which contains two attributes for open and paid costs.

This graphic is explained in the accompanying text

After the interface definition IF_TRAVEL_COSTS has been implemented in all three detail components, their component controllers now have a context node Costs. Each of these components can include this node into its own controller implementation and fill it individually.

This graphic is explained in the accompanying text

After all detail components of our example now have a separate interface, you can declare a usage of exactly this interface for the superior Travel Costs component.

This graphic is explained in the accompanying text

As with a normal component usage an instantiation of the involved components is programmed in an appropriate method of this component (for example, the method WDDOINIT of the component controller after a usage has been declared for this controller as well).

method WDDOINIT.

data: L_REF_CMP_USAGE type ref to IF_WD_COMPONENT_USAGE.

L_REF_CMP_USAGE = WD_THIS->WD_CPUSE_USAGE_HOTELS( ).

if L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) is initial.

L_REF_CMP_USAGE->CREATE_COMPONENT( COMPONENT_NAME = 'HOTELS' ).

endif.

data: L_REF_CMP_USAGE2 type ref to IF_WD_COMPONENT_USAGE.

L_REF_CMP_USAGE2 = WD_THIS->WD_CPUSE_ USAGE_FLIGHTS( ).

if L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) is initial.

L_REF_CMP_USAGE2->CREATE_COMPONENT( COMPONENT_NAME = 'FLIGHTS' ).

endif.

data: L_REF_CMP_USAGE3 type ref to IF_WD_COMPONENT_USAGE.

L_REF_CMP_USAGE3 = WD_THIS->WD_CPUSE_ USAGE_CAR_RENTAL( ).

if L_REF_CMP_USAGE->HAS_ACTIVE_COMPONENT( ) is initial.

L_REF_CMP_USAGE3->CREATE_COMPONENT( COMPONENT_NAME = 'CAR_RENTAL' ).

endif.

endmethod.

For each of these three instances, the content of the interface implementation is now available to the using component.

Example Context Mapping:

For the context of the component controller this means that a mapping can be defined to each of the three different implementations of the interface context node Costs. In the context of the component controller an appropriate node must be created for each mapping.

This graphic is explained in the accompanying text

No comments:

Archive