Show TOC

DEMO_COMMON_ASSISTANCE1Locate this document in the navigation structure

Use

This demo application DEMO_COMMON_ASSISTANCE uses a very simple example to illustrate how the instance of an assistance class can be used by two different components. A prerequisite is that the assistance classes of both components must both have the same name.

  • Initially, both demo components, DEMO_COMMON_ASSISTANCE1 and DEMO_COMMON_ASSISTANCE2, access the assistance class CL_WD_DEMO_COMM_ASSI.

  • Component DEMO_COMMON_ASSISTANCE1 uses DEMO_COMMON_ASSISTANCE2 as subcomponent.

  • The method WDDOINIT of the component controller of DEMO_COMMON_ASSISTANCE1 uses the method l_ref_cmp_usage->create_component to instantiate the used component. To ensure that both components access the same instance of the assistance class, the reference to the current instance of the assistance class of the main component must be passed as the value for the parameter ASSISTANCE_CLASS.

    method WDDOINIT .
    data: l_ref_cmp_usage type ref to if_wd_component_usage.
    l_ref_cmp_usage =   wd_this->wd_cpuse_sub_component( ).
    if l_ref_cmp_usage->has_active_component( ) is initial.
       l_ref_cmp_usage->create_component( ASSISTANCE_CLASS = wd_assist ).
    .
    endif.
    endmethod.
                   

An instance is created for the used component and the existing instance of the assistance class (belonging to the main component) is assigned to the instance of the used component. If you pass the name of the assistance class instead of the reference variable wd_assist here, you would create a second, independent, instance of the same class.