cancel
Showing results for 
Search instead for 
Did you mean: 

How to get attribute value of a node

Former Member
0 Kudos

Hi experts

I have a mapped node in my view context from component controller context. This node consists of 2 value attributes inside

Example:

NODE1 -


> Cardinality 1..1, seleciton 1..1

-- x_date -


> type DATS

-- x_years -


> dec3

How do I get the attribute value attr1 and attr2 ??

Here is my code in my view method

DATA: lr_node_info TYPE REF TO if_wd_context_node_info,

l_date TYPE dats,

l_xyears TYPE i.

lr_node_info = wd_context->get_node_info( ).

lr_node_info = lr_node_info->get_child_node('NODE1').

l_date = lr_node_info->get_attribute( name = 'X_DATE' ).

l_xyears = lr_node_info->get_attribute( name = 'X_YEARS' ).

It does not seems to work since it says < the result type of the function method can not be converted into the result type L_DATE>

I try to understand why but not sucessful, please help and thank you for your kindness

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Dean,

i will tell you the easy way, use the code wizard. When you are inside the View Method

Press CTRL + F7. There is option to read context Attribute, select this radio button option and then thru F4 you can select the Attribute You want to read. Code is automatically generated with variable declaration.!!

Alternatively , Assume your VIEW was called V_MyView, you can read attribute values in method as below.

method getyear.

DATA:

node_node1 TYPE REF TO if_wd_context_node,

elem_node1 TYPE REF TO if_wd_context_element,

stru_node1 TYPE if_v_podetails=>element_node1 .

*navigate from <CONTEXT> to <UTILITY> via lead selection

node_node1 = wd_context->get_child_node( name = if_v_MyView=>wdctx_node1 ).

*get element via lead selection

elem_node1 = node_node1->get_element( ).

*get all declared attributes

elem_node1->get_static_attributes(

IMPORTING

static_attributes = stru_node1 ).

"stru_node1 will have value

data: lv_date type DATS.

data: lv_year type dec3.

"x_date can be accessed as

lv_date = stru_node1-x_date.

"y_years can be accessed

lv_year = stru_node1-x_years .

endmethod.

Greetings

Prashant

Answers (2)

Answers (2)

former_member402443
Contributor
0 Kudos

Hi Dean,

Regading uour problem of reading the attributes value of the context node, you have to use the code wizard. that ia avaliable on the top toolbar when you are inside the View Method

There is option to read context select that radio button option and then thru F4 help

if you can select the node then Code is automatically generated with variable declaration.!!

Like this :

DATA lo_nd_node1 TYPE REF TO if_wd_context_node.

DATA lo_el_node1 TYPE REF TO if_wd_context_element.

DATA ls_node1 TYPE wd_this->element_node1.

DATA lv_x_date LIKE ls_node1-x_date.

DATA lv_x_year LIKE ls_node1-x_year.

  • navigate from <CONTEXT> to <NODE1> via lead selection

lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).

  • get element via lead selection

lo_el_node1 = lo_nd_node1->get_element( ).

  • get all declared attributes

lo_el_node1->get_static_attributes(

IMPORTING

static_attributes = ls_node1 ).

lv_x_date = ls_node1-x_date.

lv_x_date = ls_noe1-x_year.

if you can select the attribute then Code is automatically generated with variable declaration.!!

DATA lo_nd_node1 TYPE REF TO if_wd_context_node.

DATA lo_el_node1 TYPE REF TO if_wd_context_element.

DATA ls_node1 TYPE wd_this->element_node1.

DATA lv_x_date LIKE ls_node1-x_date.

  • navigate from <CONTEXT> to <NODE1> via lead selection

lo_nd_node1 = wd_context->get_child_node( name = wd_this->wdctx_node1 ).

  • get element via lead selection

lo_el_node1 = lo_nd_node1->get_element( ).

  • get single attribute

lo_el_node1->get_attribute(

EXPORTING

name = `X_DATE`

IMPORTING

value = lv_x_date ).

Hopes this will helps you.

Regard

Manoj Kumar

Former Member
0 Kudos

Hi,

You can use Code Wizard for this. You can read the value of node/attribute. Use the same line of code for setting the values as well with small change.

There is only export parameter & no import parameters in the case of set attribute value.

Best Regards

Ravi