cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to bind elements to context

Sharathmg
Active Contributor
0 Kudos

Hello all,

As part of POC, I have created a table and have to push some dummy(hard-coded) data into the table. I have limited experience with ABAP OOPS.

To implement the code, I have the reference to context node. But, there are methods to bind element/elements/structure to the node and not to add element to node.

Now, i tried to populate the element and add it to internal tab and bind it to context node. It creates an entry in table but the data is not displayed.

The code is given below:

method WDDOINIT .

DATA lo_nd_zviposhead TYPE REF TO if_wd_context_node.

DATA lo_el_zviposhead TYPE REF TO if_wd_context_element.

DATA ls_zviposhead TYPE wd_this->element_zviposhead.

TYPES: BEGIN OF ty_itab,

node_elements TYPE REF TO if_wd_context_element,

END OF ty_itab.

DATA: element_itab TYPE table of ty_itab,

wa_element type ty_itab.

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

lo_nd_zviposhead = wd_context->get_child_node( name = wd_this->wdctx_zviposhead ).

  • @TODO handle not set lead selection

loel_zviposhead = lo_nd_zviposhead->create_element( )._

loel_zviposhead->set_attribute( name = 'FIELD1' value = '0.601.010.005')._

loel_zviposhead->set_attribute( name = 'FIELD2' value = 'Ordered')._

loel_zviposhead->set_attribute( name = 'FIELD3' value = '4')._

loel_zviposhead->set_attribute( name = 'FIELD4' value = '14')._

loel_zviposhead->set_attribute( name = 'FIELD5' value = '0')._

waelement-node_elements = lo_el_zviposhead._

append waelement to element_itab._

<< the above code which is underlined is repeated to add 3 more sets of data >>

lo_nd_zviposhead->BIND_ELEMENTS( new_items = element_itab SET_INITIAL_ELEMENTS = abap_true ).

The result is a table with 4 elements but empty.

Kindly help me to achieve the result. If any better alternative to push hard-coded data to table, do let me know.

Thank you.

regards,

Sharath

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

To add elements to the context, Please have a look at the following code:

method WDDOINIT .

" define a local structure type with all the attributes defined in the context
  types: begin of ty_element,
           category type string,
           tooltip  type string,
           date     type d,
           end of ty_element.

  data:
    node_datasource type ref to if_wd_context_node,
    element type ty_element,
    elements  type standard table of ty_element.

  node_datasource = wd_context->get_child_node( name = `DATASOURCE` ). "get the reference to the node

 element-tooltip  = 'Birth day'.
 element-date     = '20100627'.
 element-category = 'ONE'
 append element to elements. "add element to the internal table elements

 element-tooltip  = 'Birth day'.
 element-date     = '20100627'.
 element-category = 'ONE'
 append element to elements.  "add element to the internal table elements

  node_datasource->bind_table( elements ). "bind to the node
endmethod.

This works!

above code is for adding several elements at once to the context node using bind_table.

If you want to create one element and add it to the context, use the following code:

lo_el_<node> =
lo_nd_<node>->create_element( ).
lo_el_<node>->set_attribute( name = 'attr_name' value = 'attr_value')
lo_nd_<node>->bind_element(
new_item = lo_el_<node>
set_initial_elements = abap_false ).

Hope this helps!

Regards,

Srilatha

Edited by: Srilatha M on Jun 22, 2010 9:53 AM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi sharth

please refer the below code and modify as per your requirement

DATA lo_nd_scarr TYPE REF TO if_wd_context_node.
  DATA lo_el_scarr TYPE REF TO if_wd_context_element.
  DATA ls_scarr TYPE wd_this->Element_scarr.
  data: lt_scarr like TABLE  OF ls_scarr.
 

  lo_nd_scarr = wd_context->get_child_node( name = wd_this->wdctx_scarr ).
  lo_el_scarr = lo_nd_scarr->get_element( ).


	ls_scarr-carrid = 'AA'.
	ls_scarr-connid = 11.
	append ls_scarr to lt_scarr.

	ls_scarr-carrid = 'BB'.
	ls_scarr-connid = 12.

	append ls_scarr to lt_scarr.


  CALL METHOD lo_nd_scarr->BIND_TABLE
    EXPORTING
      NEW_ITEMS            = lt_scarr

Regards,

Chinnaiya P

Edited by: chinnaiya pandiyan on Jun 22, 2010 1:28 PM