cancel
Showing results for 
Search instead for 
Did you mean: 

How to read the Conext node

Former Member
0 Kudos

Hello All,

I am new to webdynpro for ABAP . In my application I got stuck some where :

I have 2 context nodes:

1. CN_MNTHLY_LOC

2. Series

CN_MNTHLY_LOC contains some attributes like X , Y Z . Similarly Series Node have some other attributes like A, B, C .

Now In my code we have hardcoded the values of A, B, C like this :

method SUPPLY_POINTS .

  data:
  lt_series type if_V_DASHBOARD=>elements_series,
  series like line of lt_series.

  series-location = 'ALL'.
  series-A = '50'.
  series-B = '16'.
  series-C = '19'.
  insert series into table lt_series.


I want to remove this hardcoded values i.e 50, 16 ,19 and set this value to X, Y , Z .

Can someone please tell me how to read this context and set the value of A , B. C to X, Y , Z

Thanks

Himani

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Himani ,

data:

lo_nd_series type ref to if_wd_context_node,

lt_series type if_V_DASHBOARD=>elements_(ur node name).

ls_series type if_V_DASHBOARD=>element_(ur node name).

Now loop at lt_series into ls_series.

local variable = ls_series-series1. .

Endloop.

regards

Kuldeep

Former Member
0 Kudos

Hi Himani ,

You can use the wizard at the toolbar in WD .

When you open the wizard select the node and attribute you want to read and wizard will generate the code for you.

Regards

Kuldeep

former_member463524
Contributor
0 Kudos

Hi,

As Baskar said,

we can use the below code, if you have already defined table u can use the same instead of field symbol.

data:

lo_nd_series type ref to if_wd_context_node,

lt_series type ztt_table,

ls_Series like line of lt_series.

" get the node

lo_nd_series = wd_context->get_child_node( name = wd_this->wdctx_series ).

lo_nd_series->get_static_attributes_table( table = lt_series ).

loop at lt_series in ls_series.

if ls_series-A = '50'.

ls_Series-A = "set the value of X

endif.

endloop.

Regards,

Meera

Former Member
0 Kudos

Hi Himani,

I am not sure if i understood it correctly. Basically what you want to do is read the attributes of one context node and set the attributes of another context node with those values. Am i right??

If that is the case, you can do the following:


    DATA lo_nd_cn_mnthly_loc TYPE REF TO if_wd_context_node.
    DATA lo_nd_series TYPE REF TO if_wd_context_node.
  DATA lo_el_loc TYPE REF TO if_wd_context_element.
DATA lo_el_series TYPE REF TO if_wd_context_element.
   
   
DATA lv_A TYPE  wd_this->element_cn_mnthly_loc-A.
    

*   navigate from <CONTEXT> to <CN_MNTHLY_LOC> via lead selection
    lo_nd_cn_mnthly_loc = wd_context->get_child_node( name = wd_this->wdctx_cn_mnthly_loc ).

    lo_el_loc = lo_nd_cn_mnthly_loc->get_element().

    lo_nd_series = wd_context->get_child_node( name = wd_this->wdctx_series ).
    lo_el_series = lo_nd_series->get_element().

*   read all attributes
    lo_el_loc->get_attribute(
      EXPORTING
      NAME = 'A' "any attribute name you want to read
      IMPORTING
       VALUE =  lv_A ). 

   lo_el_series->set_attribute(
     EXPORTING
     NAME = 'X' "any attribute name you want to set
     VALUE = lv_A ).

Above, i have given the code to read an attribute from lead selected element of a context node and to set an attribute of an lead selected element of another context node.

If you want to set for all the context elements, then you would need to get all elements and then set attributes in the other node.

Hope this helps!

Best Regards,

Srilatha

Former Member
0 Kudos

Yes Srilatha,

You are right ! Context node contains the data which needs to pass to the corresponding attribute of node Series . But if I have 12 attributes in that case it will be difficult to export and import the paramenters value namually .Can you please tell me how to do this through loops & Internal Tables.

1. Read CN_Monthly_loc node .

2. Create an Internal Table of type CN_Monthly_loc node .

3. Now we have to pass this data to our corresponding fields of Series nodes.

But I dont know how to do this with code

Thanks

Himani

Former Member
0 Kudos

Hi Himani,

Okie. I was thinking that you might have different set of attributes in those two nodes.

But if you have same number of attributes and are of same type, its very simple to do.

Use get_static_attributes_table to read attributes of all elements of the first node.

One thing you try is try to bind that table of elements directly to the second node. But am not sure if this works. I dont have a system now to test. So check if it works.

If it does not,

try the following:

loop over that internal table into a work area, bind that work area using bind_structure to the second node.

Hope this helps!

Best Regards,

Srilatha

Former Member
0 Kudos
data:
   lo_nd_series           type ref to if_wd_context_node,
    lt_series                type if_V_DASHBOARD=>elements_series.
FIELD-SYMBOLS:
  <fs>                      type              if_V_DASHBOARD=>element_series.
" get the node
lo_nd_series = wd_context->get_child_node( name = wd_this->wdctx_series ).

lo_nd_series->get_static_attributes_table( table = lt_series ).

loop at lt_series assigning <fs>.
if <fs>-A = '50'.
  <fs>-A = "set the value of X
endif.
endloop.