cancel
Showing results for 
Search instead for 
Did you mean: 

Proplem with reading recursive node of table tree Webdynpro ABAP

former_member187651
Active Participant
0 Kudos

Dear Gurus,

I have implemented table tree with recursive node for context in my webdynpro ABAP application. Now I am getting problem with reading the context value with event 'ONSELECT' on table. I need to refresh my ALV with  value of node attribute.

When I am trying to read the value of context attribute it always gives me parent attribute value not child attribute value. I am really stuck on this point. I have even search on SCN but did not found any satisfactory answer.

I am using following method to make my multilevel table tree:

  http://www.divulgesap.com/blog.php?p=Nzg=
http://divulgesap.com/blog.php?p=ODQ=

My Context Node is :

Please let help on this. Any suggestion is helpful to me.  

  1. Thanks..

Accepted Solutions (1)

Accepted Solutions (1)

former_member187651
Active Participant
0 Kudos

Hello All, Thanks for your great support. Although Problem of reading Recursive Node still exist, but I have done with my requirement of getting multiple level Table tree and getting the value with Onclick event of table.

Experts are welcome to give me the best solution to read the Recursive node as asked.

I have used simple Table tree with Field Symbol.................

Thanks.....

0 Kudos

Hello Chandan,

The Recursive Tree node can be read as following:

*Get the elements of the root context

  lt_elements = wd_context->get_child_node( name = 'TREE_ROOT_ELEMENT' )->get_elements( ).

* Read the root node data

  Read table lt_elements INTO lo_elements.

    lo_elements->get_static_attributes(

      IMPORTING static_attributes = ls_tree_output ).

* Get the rescursive elements

  lt_child_nodes = i_childnode->get_child_node(  name = 'TREE_ELEMENT' )->get_elements( ).

=> Now iterate the lt_child_nodes and get the child node of 'TREE_ELEMENT' again to get the next level records.

=> During each iteration, get the static attributes and append the records as desired.

Hope it was useful.

Regards,

Laks

Former Member
0 Kudos

1,5 years later it will be very useful

Answers (6)

Answers (6)

Vasantha_D
Participant
0 Kudos

Hi Chandan,


Follow the links suggested by

sreenu_b2
Explorer
0 Kudos

Hi Mishra,

Since you are using the recursive node You have to alter the lead selection to get the child node values during on select action.
for this you have to use the method SET_TREE_LEAD_SELECTION of CL_WD_DYNAMIC_TOOL .ply function.

This method result in calling the supply function again.

The supply function will trigger two times.
One for Actual parent node and second time for recursive node.

first time the node info(IF_WD_CONTEXT_NODE_INFO) of parent will not be same as Child.
Generally during this time we fill the parent tree information

second time the node info will be same

In second time what you to do is get your parent attribute values and populate your child values based on that .

In you supply_function you have write the following code.

data lr_parent_node type ref to if_wd_context_node.

*check for the node info of parent & child

 

  lr_parent_node = parent_element->get_node( ).

*Check whether the parent & child node info is same . In first run it will never be same

if lr_parent_node->get_node_info( ) = node->get_node_info( ).

*if same Here you can read your parent attribute values and populate the child node data by raedg parent attribute values

parent_element->get_attribute( exporting name = BUKID )

else.

*If not same ,generally here you populate the Parent node data

endif.

   

*write this code on select

    node = wd_context->get_child_node( 'BUCKETLIST' ).

  cl_wd_dynamic_tool=>set_table_tree_lead_selection( lead_selection = context_element

                                                                                              data_source    = node ).

*remember add this context_element of type if_wd_context_element as importing parameter to current onselect method

former_member187651
Active Participant
0 Kudos

Hello Srinivash, thanks for your reply.

I have used your code as give below: Supply function for the bucketlist:

***********************************************************************************************

method BUCKETLIST .
   DATA lv_bukid           TYPE zcpm_bucket-bukid.
   DATA lv_bukid1           TYPE zcpm_bucket-bukid.
   DATA w_bucket          LIKE LINE OF wd_comp_controller->t_bucket.
   DATA wa_bucketlist      TYPE wd_this->element_bucketlist.
   DATA lt_bucketlist      LIKE TABLE OF wa_bucketlist.

* Get the parent bucket for which the children are requested
* In the first pass, the variable lv_bukid will be blank
* then populate level 01 bucket
*    parent_element->get_attribute( EXPORTING name = `BUKID`
*                                   IMPORTING value = lv_bukid ).

****************************************************************************
*In you supply_function you have write the following code.
data lr_parent_node type ref to if_wd_context_node.
*check for the node info of parent & child
   lr_parent_node = parent_element->get_node( ).
*Check whether the parent & child node info is same . In first run it will never be same
if lr_parent_node->get_node_info( ) = node->get_node_info( ).
*if same Here you can read your parent attribute values and populate the child node data by raedg parent attribute values

parent_element->get_attribute( exporting name = `BUKID`
                                IMPORTING value = lv_bukid ).

else.

*If not same ,generally here you populate the Parent node data
parent_element->get_attribute( exporting name = `BUKID`
                                IMPORTING value = lv_bukid ).
endif.
******************************************************************
       IF lv_bukid IS NOT INITIAL.
* Get all children for the parent node
     LOOP AT wd_comp_controller->t_bucket INTO w_bucket
       WHERE prntb = lv_bukid.
       MOVE-CORRESPONDING w_bucket TO wa_bucketlist.
* If the child territory has got no child then make it a leaf
       READ TABLE wd_comp_controller->t_bucket TRANSPORTING NO FIELDS
       WITH KEY prntb = w_bucket-bukid.
       IF sy-subrc <> 0.
         wa_bucketlist-is_leaf = abap_true.
       ENDIF.
* For levels 01, 02 open the nodes by default
***      if wa_bucketlist-levl eq '01' or
***         wa_bucketlist-levl eq '02'.
***        wa_bucketlist-expanded = abap_true.
***      endif.
       APPEND wa_bucketlist TO lt_bucketlist.
       CLEAR wa_bucketlist.
     ENDLOOP.
   ELSE. "Executed only in the first pass
   LOOP AT wd_comp_controller->t_bucket INTO w_bucket WHERE levl = '01'.

*    READ TABLE wd_comp_controller->t_bucket WITH KEY levl = '01'
*    INTO w_bucket.
     IF sy-subrc EQ 0.
       MOVE-CORRESPONDING w_bucket TO wa_bucketlist.
*       wa_bucketlist-expanded = abap_true.
       APPEND wa_bucketlist TO lt_bucketlist.
       CLEAR wa_bucketlist.
     ENDIF.
     ENDLOOP.
   ENDIF.

   node->bind_table( lt_bucketlist ).
  endmethod.

*********************************************************************************

lr_parent_node->get_node_info( ) = node->get_node_info( ). Here lr_parent_node get filled only when we expand the parent, I think exactly the same way you told.

Here is the code for ONSELECT event of table:

********************************************************************************************

method ONACTIONON_SELECT .
   data node TYPE REF TO if_wd_context_node.
  *write this code on select
      node = wd_context->get_child_node( 'BUCKETLIST' ).
    cl_wd_dynamic_tool=>set_table_tree_lead_selection( lead_selection = context_element
                                                                      data_source    = node ).
   endmethod.

********************************************************************************************************

Now problem is from Onselect event we code do not calls the supply function as we can read the bukid of child.As you say it should call the supply function 'BUCKETLIST' agian.

Please tell me where I am wrong... Above is my code to create my Table tree structure.


Former Member
0 Kudos

Hi Chandan,

Try this

* Get index of currectly selected value

  index =  context_node->GET_LEAD_SELECTION_INDEX( ).

* Use index to get actual details of currently selected value

  context_node->GET_STATIC_ATTRIBUTES(

     exporting index = index

     importing STATIC_ATTRIBUTES = wa_ddvalue ).

OR try this

*NEW_LEAD_SELECTION should be an importing parameter of the method which was auto created

*There should also be an OLD_LEAD_SELECTION showing the previous selected row!

ld_index = NEW_LEAD_SELECTION->GET_INDEX( )."get index of row selected


context_node = wd_context->get_child_node( name = 'CARRIERS').

refresh: it_scarr.

* Get data contained within ABAP web dynpro table

context_node->get_static_attributes_table( importing table = it_scarr ).

* Get data contained in currently selected row of an ABAP web dynpro table

context_node->GET_STATIC_ATTRIBUTES(

exporting index = ld_index

importing STATIC_ATTRIBUTES = wa_scarr ).

Hope this helps you.

Thanks

Amol Patil

former_member187651
Active Participant
0 Kudos

hello Amol, I have tried with the code below, but it always give me Index no 1 or 2 and displays the Parent attribute value.. Please Let me know if any thing wrong I am doing....

Data: context_node type ref to if_wd_context_node.
   Data: it_scarr type STANDARD TABLE OF if_prolist=>element_bucketlist,
         wa_scarr like line of it_scarr.
   DATA: ld_index type i.


   ld_index = NEW_LEAD_SELECTION->GET_INDEX( ). "get index of row selected
    context_node = wd_context->get_child_node( name = 'BUCKETLIST').
   refresh: it_scarr.

* Get data contained within ABAP web dynpro table
   context_node->get_static_attributes_table(
     importing
       table = it_scarr ).

* Get data contained in currently selected row of an ABAP web dynpro table
   context_node->GET_STATIC_ATTRIBUTES(
      exporting index = ld_index
      importing STATIC_ATTRIBUTES = wa_scarr ).

Thanks..

former_member187651
Active Participant
0 Kudos

Dear Experts,

Problem not solved at.... Please let help on this......

Former Member
0 Kudos

Hi Chandan,

Try by using like this..

* lo_nd_node = wd_context->path_get_node( path = `NODE1.NODE2` ).

And Please go through this..

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/10f794ed-7811-2d10-30b7-9fdd89e26...

http://scn.sap.com/thread/3155107

Cheers,

Kris.

former_member187651
Active Participant
0 Kudos

Hello Krishna,

Thanks for the reply...

First thing that should must be clear that I am not using Node under Node instead I am using Recursive Node of Parent Type. In my case Rec_Bucketlist(Recursive node) is of type Bucketlist(Parent node). And I need to read the attribute for it on Select event of table tree.

I found some similar case in your second link (PDF). It is also working with Recursive Node. I have Implemented code as below as suggested in their:

*Data declaration
DATA : lo_nd_bucketlist TYPE REF TO if_wd_context_node,
         lo_el_bucketlist TYPE REF TO if_wd_context_element,
         ls_bucketlist TYPE wd_this->element_bucketlist,
         lo_nd_emps TYPE REF TO if_wd_context_node.

data ND_BUCKETLIST_REF TYPE REF TO if_wd_context_node.

*NavigatetoSUB_ORGSNode
lo_nd_bucketlist = wd_context->path_get_node( path = `bucketlist`).

*NavigatetoEMPS node
*lo_nd_emps = wd_context->get_child_node( name=wd_this->wdctx_emps ).



IF NOT lo_nd_bucketlist IS INITIAL .
wd_this->ND_BUCKETLIST_REF = lo_nd_bucketlist.
ENDIF.
IF NOT wd_this->nd_bucketlist_ref IS INITIAL .
lo_nd_bucketlist = wd_this->nd_bucketlist_ref.

*getalldeclaredattributes
lo_el_bucketlist->get_static_attributes( IMPORTING  static_attributes = ls_bucketlist ).
ENDIF.


But Successful as I got error:

RROR: Subnode PROLIST.bucketlist does not exist   (termination: RABAX_STATE)ERROR: Subnode PROLIST.bucketlist does not exist (termination: RABAX_STATE)

Please tell me where I am wrong.......

former_member187651
Active Participant
0 Kudos

Is there someone who can help me on this topic......

I am waiting for reply.....Please I am stuck....and its urgent to me.

Former Member
0 Kudos

Hi Chandan,

You cannot get the Child context values directly when ever it is a tree or multilevel.

When ever you are trying to read the value of child attribute then first you have to get the Parent context and using that Parent get the attributes of the Child context as shown in below example code.

DATA: lo_el_level1  TYPE REF TO if_wd_context_element,

         lo_nd_level2  TYPE REF TO if_wd_context_node,

         ls_level2     TYPE wd_this->element_level2,

         lt_level2     TYPE wd_this->elements_level2,

         lv_index      TYPE i.

   lo_el_level1 = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).

   IF  lo_el_level1 IS NOT INITIAL.

     lo_el_level1->get_static_attributes( IMPORTING static_attributes = ls_level2 ).

     lo_nd_level2 = lo_el_level1->get_node( ).

     lo_nd_level2->get_static_attributes_tableIMPORTING  table = lt_level2  ).

endif.

Hope this helps you.

Thanks

Phani

former_member187651
Active Participant
0 Kudos

Hello Phani,

Thanks for your reply. I need to read the attribute 'BUKID' of my context with every click.

I am using auto generated code to read the node. When I read the node with code below:

Here I am using your code like

DATA lo_nd_bucketlist TYPE REF TO if_wd_context_node.
   DATA lo_nd_bucketlist2 TYPE REF TO if_wd_context_node.
   DATA lo_el_bucketlist TYPE REF TO if_wd_context_element.
   DATA ls_bucketlist TYPE wd_this->Element_bucketlist.

  data ls_bucketlist2  TYPE wd_this->element_bucketlist.

  data lt_bucketlist2     TYPE wd_this->elements_bucketlist.

   data       lv_index      TYPE i.

* navigate from <CONTEXT> to <BUCKETLIST> via lead selection
   lo_nd_bucketlist = wd_context->get_child_node( name = wd_this->wdctx_bucketlist ).

* get element via lead selection
   lo_el_bucketlist = lo_nd_bucketlist->get_element( ).
* get all declared attributes
   lo_el_bucketlist->get_static_attributes(
     IMPORTING
       static_attributes = ls_bucketlist ).

****************************************************************************
    lo_el_bucketlist = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
    IF 
lo_el_bucketlist IS NOT INITIAL.
      lo_el_bucketlist->get_static_attributes( IMPORTING static_attributes = ls_bucketlist2 ).
      lo_nd_bucketlist2 = lo_el_bucketlist->get_node( ).
      lo_nd_bucketlist2->get_static_attributes_tableIMPORTING  table = lt_bucketlist2  ).
endif.

Now It fills the Is_bucketlist with value of parent level (1st level) with level 1.

And  lo_el_bucketlist is always null here. and your If condition is fails always......

Please tell me know where I am wrong.....

Its urgent .....



former_member187651
Active Participant
0 Kudos

when I am writting just your code:

DATA: lo_el_level1  TYPE REF TO if_wd_context_element,
           lo_nd_level2  TYPE REF TO if_wd_context_node,
           ls_level2     TYPE wd_this->element_bucketlist,
           lt_level2     TYPE wd_this->elements_bucketlist,
           lv_index      TYPE i.
     lo_el_level1 = wdevent->get_context_element( 'CONTEXT_ELEMENT' ).
 
    IF  lo_el_level1 IS NOT INITIAL.
       lo_el_level1->get_static_attributes( IMPORTING static_attributes = ls_level2 ).
       lo_nd_level2 = lo_el_level1->get_node( ).
       lo_nd_level2->get_static_attributes_tableIMPORTING  table = lt_level2  ).
  endif.

I am always getting   "lo_el_level1" blank or null.

Please let know what to do now.....

anoop_gupta2
Participant
0 Kudos

Hello Chandan ,

You can solve this problem very easily ,

All you need to do is make the Buketlist node(Parent ) cardinality as :  0 - 1 and on select event of the table / tree you can read the attribute value .

Please make sure that you call correct event . dont call you method on lead select rather call it on select .accordingly . 

former_member187651
Active Participant
0 Kudos

Hello Anoop, thanks for your reply. I have tried as you suggested but got error, as Cardinality Violation(run time error). This error is because I am Binding Node Buckelist with Internal table in the supply function for node Bucketlist. As code given below:

DATA lv_bukid           TYPE zcpm_bucket-bukid.
   DATA w_bucket          LIKE LINE OF wd_this->t_bucket.
   DATA wa_bucketlist      TYPE wd_this->element_bucketlist.
   DATA lt_bucketlist      LIKE TABLE OF wa_bucketlist.

* Get the parent bucket for which the children are requested
* In the first pass, the variable lv_bukid will be blank
* then populate level 01 bucket
     parent_element->get_attribute( EXPORTING name = 'bukid'
                                    IMPORTING value = lv_bukid ).

*******************Assigning value to Global variable bid *************************
*    CLEAR WD_THIS->BID .
*    WD_THIS->BID = LV_BUKID .
******************************************************************


       IF lv_bukid IS NOT INITIAL.
* Get all children for the parent node
     LOOP AT wd_this->t_bucket INTO w_bucket
       WHERE prntb = lv_bukid.
       MOVE-CORRESPONDING w_bucket TO wa_bucketlist.
* If the child territory has got no child then make it a leaf
       READ TABLE wd_this->t_bucket TRANSPORTING NO FIELDS
       WITH KEY prntb = w_bucket-bukid.
       IF sy-subrc <> 0.
         wa_bucketlist-is_leaf = abap_true.
       ENDIF.
* For levels 01, 02 open the nodes by default
***      if wa_bucketlist-levl eq '01' or
***         wa_bucketlist-levl eq '02'.
***        wa_bucketlist-expanded = abap_true.
***      endif.
       APPEND wa_bucketlist TO lt_bucketlist.
       CLEAR wa_bucketlist.
     ENDLOOP.
   ELSE. "Executed only in the first pass
   LOOP AT wd_this->t_bucket INTO w_bucket WHERE levl = '01'.

*    READ TABLE wd_this->t_bucket WITH KEY levl = '01'
*    INTO w_bucket.
     IF sy-subrc EQ 0.
       MOVE-CORRESPONDING w_bucket TO wa_bucketlist.
*       wa_bucketlist-expanded = abap_true.
       APPEND wa_bucketlist TO lt_bucketlist.
       CLEAR wa_bucketlist.
     ENDIF.
     ENDLOOP.
   ENDIF.


   node->bind_table( lt_bucketlist ).

Internal table T_bucket getting fillled in WDDOINIT method of Component controller when application loaded at first time.

I need to get value of Bukid on select of table each time.......

I have even tried with debug in the supply function of Bucketlist, but found this Suply function get called just first time, we used to select/Expand the bucket value, Second time this Supply Fuction do no call......

Please let me know if any doubt with issue...

Please help its urgent to me....