cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the content of context nodes in other components ?

Former Member
0 Kudos

Hi,

I have a MAIN-Component, which holds all my data in the context with many different nodes.

And I have some other components a, b, c, d, ...

In the component MAIN I have a node called 'MASSNAHME' which I want to share with component a and b.

How can I do that ? It only works for me to share the node over external context mapping for component a but not a AND b.

I also tried to get a component usage to get the content over abap coding interface->context->root_node->child_node...

but this was not working for me, the nodes were always empty.

Any hints are appreciated..

Thanks in advance

hhermann

Accepted Solutions (1)

Accepted Solutions (1)

former_member184578
Active Contributor
0 Kudos

Hi,

If you want to reuse any node  it should be an interface node.  In component controller of main component click on node and under properties, select Interface Node check box.

Hope this helps u.,

Thanks & Regards,

Kiran.

Former Member
0 Kudos

Hi Kiran,

I did this already and it works for component a, but i can't map the data to component b, too!

Regards,

hhermann

former_member184578
Active Contributor
0 Kudos

Hi,

I didn't get it clearly, Like component a, you can use your MAIN component as component usage in component b and map the node to component b.. In component b, goto component controller, click on controller usage and select interface controller of MAIN component and map the node to component b.

Regards,

Kiran.

former_member199125
Active Contributor
0 Kudos

make the node as interface node, and if you want to use in b component,

then in b component make A component as reused component, then in component controller of B , click on controller usage , select interface controller of A, then maintain the extenral context mapping between your node to your desired node.

Regards

Srinivas    

Answers (3)

Answers (3)

chengalarayulu
Active Contributor
0 Kudos

Hi Hein,

Create a node in MAIN component with INTERFACE Enabled, and map it in Components A & B and here you can easily map the node of MAIN component.

Thing is NODE SHOULD BE INTERFACE ENABLED.

Former Member
0 Kudos

Hi ,

thank you, the mapping problem is already solved. The problem with my code mentioned above is NOT solved. The child node is alwasy empty.. Maybe u have an solution or idea for this problem ?

Thanks in advance.

Regards,

hhermann

Former Member
0 Kudos

Hi Heinrich,

Please help in understanding your problem.

Are you not able to get the reference in the variable lo_root_node?

If you are able to get the reference, but not the data, then maybe you'll have to check the point at which this method is called. Maybe the node doesn't have any elements initialized at that time.

Using Web dynpro specific debugger might also help you.

Regards,

Jaspreet Singh

Former Member
0 Kudos

Hi Jaspreet,

yes, thats exactly the problem. Let me please explain.

I start the application, and all data is loaded.

I have an ALV in component "ABSCHNITTE". There is an event ON_LEAD_SELECT on this ALV.

After lead_select the called method reads the id of the selected row.

Then I would like to read the context of component "MASSNAHME" in the same method and copy the data into an internal table if the abschnittid = the id of the selected row. But the context node is always empty, but I can get the reference.

And after that i would like to put these filtered data back to context of "MASSNAHME".

Can you follow me ? Please excuse my english.

I also tried to implement an interface method in "MASSNAHME" component which imports an parameter abschnittid to do the logic of filtering data in these component, but the context node is also empty and this is very curious for me!

Regards,

hhermann

Former Member
0 Kudos

You did not map your data rite?

Former Member
0 Kudos

Hi,

of course I did!

Regards,

hhermann

Former Member
0 Kudos

Hello again,

can you now tell me please how i can get the contents over abap coding without context mappings ?

Thanks in advance

Regards,

hhermann

Former Member
0 Kudos

Hi Heinrich,

You can get the context of the used component using a code like mentioned below. I wrote this code to get the context of the standard component SALV_WD_TABLE.

DATA lo_interfacecontroller TYPE REF TO iwci_salv_wd_table .

  lo_interfacecontroller =   wd_this->wd_cpifc_alv_ref( ).

  DATA lo_api_interfacecontroller TYPE REF TO if_wd_controller.

  lo_api_interfacecontroller = lo_interfacecontroller->wd_get_api( ).

  DATA: lo_context  TYPE REF TO if_wd_context,

        lo_root_node  TYPE REF TO if_wd_context_node,

        lo_nd_data  TYPE REF TO if_wd_context_node.

  lo_context = lo_api_interfacecontroller->get_context( ).

  lo_root_node = lo_context->root_node.

  lo_nd_data = lo_root_node->get_child_node( name = 'DATA' ).

Hope it is helpful!!!

Also, Could you let us know why you don't want to use external context mapping?

Regards,

Jaspreet

Former Member
0 Kudos

Hi,

You are not going to get the data without mapping. When you add component usage to a view, you will get the interface controller of that component in you context tab below the component controller. Now you can map the interface controller to your view context.

Regards,

Fareez

Former Member
0 Kudos

Hi,

thank you for the code-snippet. I tried it, but the context node is always empty... There seems to be a problem, but I don't know the solution.

I use external mapping and it works, but there are sometimes situations where its easier to use the method over abap code.

I also tried to read context in MAIN component and make a interface method which I can call in the other component. Same problem, no content, empty node and empty table...

Thank you for the help

Regards,

hhermann

Former Member
0 Kudos

Hi Farveez,

I think it is possible to get the data from the context nodes which are marked as interface nodes.

I'll try and explain the approach of my code mentioned above:-

1. Instantiate the used controller.

2. Get the reference of the interface controller of the used controller.

3. Get the API of the interface controller using wd_get_api( ) method.

4. Get the context from the api reference using get_context( ) method. It will be of type IF_WD_CONTEXT.

5. The reference to the context obtained above will have a static attribute root_node. Get it into a local variable of type IF_WD_CONTEXT_NODE.

6. Get the child node reference which you want using get_child node methods.

7. After that get the data using methods like get_static_attributes.

I was able to check this for the used component 'SALV_WD_TABLE'. The data in the 'Data' node of this component was available in the using component's view.

We can't use the wizard in above approach. Please let me know if I am missing anything.

Heinrich, Could you check if the node is marked as interface or if it is initialized properly.

Regards,

Jaspreet

Former Member
0 Kudos

Hi Jaspreet,

yes, the node is marked as interface and i can get the data in the same component over external mapping, but not over abap code. Very strange. How can i check if it is initialized properly ?

Thanks in advance

Regards,

hhermann

Former Member
0 Kudos

Hi Jaspreet,

No need to use coding to get reference to interface controller of other component. Mapping is the best option.

1. Go to the web dynpro component in which you want to use another component and add the component which you want to access in the properties tab.

2. Now go to the properties tab of the view in which you want to access the interface controller of the external component.

3. Add the both interface controller and the component to the view.

4.Now go to the context tab.

5.Interface controller of the external component will be available on the right side.

6. Map it to your context by drag and drop.

7. Now you can process it as your local nodes and it will automatically reflect in the external component.

Try this hermann.

Regards,

Fareez

Former Member
0 Kudos

Hi Fareez,

thank you, yes this works for me. BUT, if there is a possibility to get the data over abap coding, it should work, too, you don't think so ?

Regards,

hhermann

Former Member
0 Kudos

Hi Hermann,

Japreet's code is correct. But did you added the component usage to the view. The code works assuming that you added component usage. If you share your code, we will get more chances to solve the problem.

Regards,

Fareez

Former Member
0 Kudos

Hi,

of course I've added the component usage.

Here is the code, thank you very much for your help:

DATA: lo_cmp_usage TYPE REF TO if_wd_component_usage.

lo_cmp_usage =   wd_this->wd_cpuse_cu_massnahme( ).
IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.

DATA lo_interfacecontroller TYPE REF TO ziwci_999b_prok_ke_w_massnahme .
DATA: lo_api  TYPE REF TO if_wd_controller.
DATA: lo_context TYPE REF TO if_wd_context.
DATA: lo_root_node TYPE REF TO if_wd_context_node.
DATA: lo_child_node TYPE REF TO if_wd_context_node.


lo_interfacecontroller =   wd_this->wd_cpifc_cu_massnahme( ).

lo_api = lo_interfacecontroller->wd_get_api( ).
lo_context = lo_api->get_context( ).
lo_root_node = lo_context->root_node.
lo_root_node->get_child_node(
EXPORTING

name       = 'MASSNAHME'
RECEIVING
child_node =   lo_child_node
).

Regards,

hhermann

Former Member
0 Kudos

Hi,

Where you are doing this process is important. When you do at WDDOINIT, the component will not be initialized. I have had a similar problem when I tried to call a method of different component. When a component is created it will not have any data on the context unless you enter through code or input fields.

IF lo_cmp_usage->has_active_component( ) IS INITIAL.
lo_cmp_usage->create_component( ).
ENDIF.

From this code, You create a component if its not active already and continuously you try to access the data. I think when a component is created it'll have no value on its context.

Now be precise with your problem. You get any error, or just the values are empty. If the method returns a null, it will through an error. Otherwise if it doesn't then it works fine I suppose, Only there is no data in the context.

Regards,

Fareez


Former Member
0 Kudos

Hi Fareez,

I'm not getting an error, the node is just empty.

Regards,

hhermann

Former Member
0 Kudos

Hi,

Did you check with debugger that data is present in the context. Everything other than that seems perfect.

Regards,

Fareez

Former Member
0 Kudos

Hi,

ok how can I check that properly ? Where do I have to set the breakpoints ?

Thanks in advance

Regards,

hhermann

Former Member
0 Kudos

Hi,

You said everything works fine while mapping right? Now do mapping of the interface controller to local view controller and try to check whether it contains any data, by getting static_attributes or static_attributes_table of the node. Use this for checking alone. If it contains data, then your coding way of access the node should also contain data I hope. Remember you do mapping for the purpose just debugging.

Otherwise if you do not want to map... Try to check in the external component itself by getting the static_attributes or static_attributes_table of the node.

Regards,

Fareez

Former Member
0 Kudos

Hi,

I checked it, I've created a button which triggers a method. This method reads just the context node in an internal table and there are 4 entries as I can see in the view of my app and in the debugger.

All happens in the component which delivers the data.

Regards,

hhermann

Former Member
0 Kudos

Hi,

now I've tried it over external mapping. This solution works and is OK for my UseCase.

But I'm still interested in a solution for getting the content over abap coding...

Anyway, Thank you very much for help!

Best regards,

hhermann

Former Member
0 Kudos

Thanks to all, I will try out your hints!