cancel
Showing results for 
Search instead for 
Did you mean: 

What is the context of the Interface Controller for?

Former Member
0 Kudos

Hi All.

I am dynamically embedding components inside my main application, and hence, they all implement a common interface.

Now, I declared a context in the interface. It becomes visible in all implementing components in the component context.

I thought I could map data from it to any view or window.

But whenever I try to do it, i get an error that it's an interface and hence, I cannot instantiate it.

If I cannot use the interface context data, what is it for? And, if I can use it, what am I doing wrong?

Thanks in adv.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can map contexts in interface controllers, just as you might map from the comp controller context to a view controller context.

Or a classic example is the ALV demo. You do a reverse mapping from your context back to the ALV interface component.

You can instantiate the interface controller. But you do so for the purpose of calling methods on it.

NOTE: you must mark context elements and methods that are to be called / accessed from external component as INTERFACE element or as an INTERFACE method. Otherwise when the interface controller is generated they will not be visible/usable externally.

Cheers

Phil.

Former Member
0 Kudos

Thanks Phil.

Let me explain error I get:

Scenario is same as in my previous threads -> Dynamic component insertion.

Now, when my main component starts, from the URL, I get value of country which I want to pass to the context element -> Country of the Interface.

Inside my called component's window's handledefault: (Note here that called comp is implementing that interface. Hence the context node country appears as the comp controller's context). I map the interface node country to window's context.

When I try to read the context of my window now, at the statement

elem_comp_code = node_comp_code->get_element( ).

I get an error that the interface cannot be instantiated.

What is going wrong here?

Thanks.

Former Member
0 Kudos

Hi Aishi,

I think more info is required to help now that we talk abut dynamic component instantiation.

Which component calls what , instantiates what, when,

It is not clear to me sorry.

regards

Phil.

Former Member
0 Kudos

I dont normally just cut paste links to docu to collect points. I think they will help.

The first shows clearly code, instantiating the dynamic code and then navigating to it.

http://help.sap.com/saphelp_nw2004s/helpdata/en/77/3545415ea6f523e10000000a155106/frameset.htm

The second link is the programming guideline for WDA which includes dynamic coding examples.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/db22242d-0701-0010-28a2-aea...

Step 1 is replace the static declaration of the component usage added in the properties

of the view normally with code :

data: L_VIEW_CONTROLLER_API type ref to IF_WD_VIEW_CONTROLLER,

      L_COMPONENT_USAGE type ref to IF_WD_COMPONENT_USAGE,

      COMPONENT_NAME    type STRING.

 

if L_COMPONENT_USAGE->HAS_ACTIVE_COMPONENT( ) is initial.

   L_COMPONENT_USAGE->CREATE_COMPONENT( COMPONENT_NAME ).

endif.

Second step is to embed the interface view somewhere.

This you normally do in the window where you embed views in windows.

L_VIEW_CONTROLLER_API = WD_THIS->WD_GET_API( ).

L_VIEW_CONTROLLER_API->PREPARE_DYNAMIC_NAVIGATION(

              source_window_name          = 'W0'

              source_vusage_name          = 'MAIN_USAGE_1'

              source_plug_name            = 'TO_V1'

              target_component_name       = <component_name>

              target_component_usage      = <component_usage_name>

              target_view_name            = <interface_view_name>

              target_plug_name            = <inbound_plug_name>

              target_embedding_position   = <embedding_position> ).

If you have dynamic components that use contexts that need mapping, you still have more work to do.

A reason not use context mapping and to use methods calls to pass data in my opinion.

You need to also define, dynamic context mapping.

good luck...

Phil

Former Member
0 Kudos

Okay Phil. I'll tell my scenario in detail.

I have a main component: Z_DYN_MAIN which uses the

interface component Z_INTER which has got a context node: ORDER_VALUES -> from table VBAK, 0..n carinality, and has also got one interface method CHECK_DATA.

The ORDER_VALUES from the Interface is mapped (direct mapping) to the component controller context node ORDER_VALUES.

Now, there is a component ZDYN_1 which implements the interface Z_INTER.

Now, when I implement Z_INTER, the context node ORDER_VALUES automatically comes in the component controller of ZDYN_1.

Now, inside my main component Z_DYN_MAIN, after embedding the components dynamically, i call their method like this:

LOOP AT wd_comp_controller->component_usages INTO ls_comp_usage.

IF ls_comp_usage-component_usage->has_active_component( ) IS INITIAL.

ls_comp_usage-component_usage->create_component( ls_comp_usage-used_component ).

ENDIF.

l_intf_controller ?= ls_comp_usage-component_usage->get_interface_controller( ).

CALL METHOD l_intf_controller->check_data.

ERROR 1 :

Now, inside the component ZDYN_1, when the CHECK_DATA is called, I try to insert some values into the ORDER_VALUES context.

But as soon as I say: elem = node->get_element( ).

I get an error :

The Mapping to Node COMPONENTCONTROLLER.1.ORDER_VALUES Has Not Been Completed.

What is the reason for this? I don't have any node in the comp controller, except the interface node which appears automatically as I implemented the interface.

ERROR 2:

Inside my main component, when I try to read the values after the interface method call :

CALL METHOD node_order_values->get_static_attributes_table

IMPORTING

table = lt_order_values.

I get this error

Error when Creating Component Z_INTER. Z_INTER Is a Component Interface, Therefore, an Instance Cannot Be Created. Name of Component May Not Be Specified. (Used Component: Z_DYN_MAIN, Component Usage: USAGE1)

What is the cause of this error?

Thanks again!

Former Member
0 Kudos

Hard to follow,

since the terminology "interface" is critical here.

COMPONENT Interface

Interface controller,

interface flag on nodes etc.

And also where the mapping is done and therefore in which direction it implies is the source.

I assume you have a node attribute as external interface.

Implying it must be mapped from another source.

The mapping is done by why of reverse mapping. AKA ALV

If you refer to a controller with an unfulfilled mapping.

then runtime...boooom

You should be able to get context mapping to work, but it isnt the only way.

You may find it easier ( and I would argue from style in this way) to use methods to pass data and not contexts. You have more control with method calls.

Passing references to a context is also possible with methods calls.

Again keen to hear arguments for more context use rather than less.

I like the context for tracking changes etc but dont like it as an interface object.

Note a context can still be passed by reference using methods.

regards

Phil.

Former Member
0 Kudos

I understand that I can achieve it using methods. I just wanted to make my concepts clear regarding interface mapping.

Let me take a fresh simple example. You can try it on your system too.

Webdynpro Interface component -> Z_INTER; context node: ORDER_VALUES, cardinality 0..n; table: VBAK, select VBELN.

That's it.

Now, Webdynpro component : Z_COMP -> Used component -> Z_INTER.

Inside component controller, I declare usage of Z_INTER. Then do a direct mapping of ORDER_VALUES from Z_INTER to Z_COMP.

So the context node ORDER_VALUES is created in the Z_COMP component controller.

That's it.

Inside WDDOINIT() method of comp controller, read the context node's attribute VBELN.

The line:

elem_order_values = node_order_values->get_element( ).

gives a dump saying that:

The following error text was processed in the system : Error when Creating Component Z_INTER. Z_INTER Is a Component Interface, Therefore, an Instance Cannot Be Created. Name of Component May Not Be Specified. (Used Component: Z_COMP, Component Usage: USAGE1)

Can you tell me how do we map interface context? I guess I am not getting the concept.

Thanks again.

Answers (0)