cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with cardinality when creating a context node dynamically

Former Member
0 Kudos

Hi,

I defined the following context tree:

VIEW120 (cardinality 1:1)

.. V120_T_TABLE1 (cardinality 0:n)

What I want to do is to add a context node at runtime.

However, I fail - the node is created without error, but the when calling get_child_node on the parent, the new node isn't found (reference to NULL).

The surprising bit is: If I change the cardinality of V120_T_TABLE1 to 1:1, it works fine.

The coding is as follows:

data o_attr_node_info type ref to if_wd_context_node_info.

data o_node_info2 type ref to if_wd_context_node_info.

data o_attr_context_node type ref to if_wd_context_node.

o_context_node = pi_o_context->get_child_node( name = 'VIEW120' ).

  • pi_o_context is the root node

o_context_node = o_context_node->get_child_node( name = 'V120_T_TABLE1' ).

o_node_info = o_context_node->get_node_info( ).

o_attr_node_info =

o_node_info->add_new_child_node(

name = '_ATTR'

is_mandatory = abap_true

is_multiple = abap_false

static_element_type = 'Z01AL_FW_FEWD_BIND_UI_PROP'

).

o_node_info2 = o_attr_node_info->get_parent( ).

  • Looks ok, is V120_T_TABLE1

o_attr_context_node = o_context_node->get_child_node( name = '_ATTR' ).

  • NULL ...

Has anyone any idea???

Best regards

Lars

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello, Lars,

My guess is: as it's a 0..N node, when you dinamically add the node, it's not been initialized, as the parent node is empty (no elements). So, when you try to get its reference, it doesn't exist yet. That's why when you set the cardinality of the node to 1..N (or 1..1) it doesn't generate the error, as the WD4A framework initializes the parent node with at least one element, that can have a child node.

What happens if you initialize your node before trying to get a reference to it? For exemple, a bind_table (or bind_element) call before:

 o_attr_context_node = o_context_node->get_child_node( name = '_ATTR' ).

Regards,

Andre

Former Member
0 Kudos

Hi Andre,

sorry for not writing it earlier, the parent node, for which I fail to create the child node, has got elements. At an earlier state I did bind a table to it already.

Best regards

Lars

Former Member
0 Kudos

Lars, good morning (at least here in Brazil

What happens if you change the IS_MANDATORY of method ADD_NEW_CHILD_NODE from abap_true to ABAP_FALSE? This parameters obliges you to have at least one element...

Regards,

Andre

Former Member
0 Kudos

Lars, another tip:

If you debug and enter WebDynpro tool in debugger, can you reach your _ATTR node?

Regards,

Andre

Former Member
0 Kudos

Hi Andre,

thanks for your replies.

I played with IS_MANDATORY, but the situation hasn't changed.

What do you mean with "enter WebDynpro tool in debugger"?

Since I need a 1:1 cardinality on the new node only, I stopped trying to create a node at runtime. Instead I create new attributes to the existing node, which works absolutely fine.

Although the original problem has not been solved, I close this thread now, since I found another solution ...

Best regards

Lars

Answers (0)