7
Tree View: 1. Create table view. 2. For the context node in the view change the super class of the context node class to “CL_BSP_WD_CONTEXT_NODE_TREE”. 3. Now, context node has become a tree node, we will get a tree structure symbol at context node, if not then log off and login to SAP again. 4. Make a class with “CL_BSP_WD_TREE_NODE_PROXY” as super class in se24 Tcode . 5. Just redefine get_children method of that class as it is an abstract method, now activate the class. 6. Now in view there are two methods which come from super class of context node class, as shown in figure below. 7. GET_TABLE_LINE_SAMPLE: this method is used to define fields in tree structure, by default code is generated but we can redefine it as per our need, below is the default code which forms the structure for tree as to which fields will be there in tree configuration.

Tree View Creation

Embed Size (px)

DESCRIPTION

Sample tree view creation

Citation preview

Tree View:1. Create table view.2. For the context node in the view change the super class of the context node class to CL_BSP_WD_CONTEXT_NODE_TREE.3. Now, context node has become a tree node, we will get a tree structure symbol at context node, if not then log off and login to SAP again.4. Make a class with CL_BSP_WD_TREE_NODE_PROXY as super class in se24 Tcode .5. Just redefine get_children method of that class as it is an abstract method, now activate the class.6. Now in view there are two methods which come from super class of context node class, as shown in figure below.

7. GET_TABLE_LINE_SAMPLE: this method is used to define fields in tree structure, by default code is generated but we can redefine it as per our need, below is the default code which forms the structure for tree as to which fields will be there in tree configuration.

In above case ZCUST_HIER_HIST is the attribute structure for the bol entity attached to context node.8. REFRESH: this method initializes the tree, we assign the class which was created in step 4.

In above code we iterate through the entities in collection wrapper and then for those entities who do not have a parent I make them a root node by assigning the class created in step 4 in get_proxy method. This was my requirement, one can choose the particular entities which they want and then make them root .Lv_root->expand_node( ): Call to expand( ) flags the node to be expanded which during tree formation leads to call to get_children method which we will define later.9. This refresh method attaches the class we created in step 4 with our tree context node, you will see the class under tree context node after activating refresh method, if not then log off and log in to SAP.10. Now we have two options for children to the root node, it depends on requirement, if we need same structure for the child, then we redefine the get_children method of the class created in step 4 as:DATA:lv_value_nodeTYPEREFTOcl_bsp_wd_value_node,lv_childTYPEREFTOif_bsp_wd_tree_node.

lv_child=me->node_factory->get_proxy(iv_bo=lv_value_nodeiv_parent_proxy=meiv_proxy_type='ZCL_EBH_ERH_HIST_TREE_PROXY').lv_child->expand_node().APPENDlv_childTOrt_children. By passing the same class name in get_proxy method we make recursive child of the same type.We can add as many children as we want at a level by calling the same method again and appending the children to rt_children parameter of get_children method.

11. Replace the .htm with code below.

nodeTextColumn: it defines the first node of tree on which you want expandd and collapse to happen.

12. Add below shown attribute to context node class:

13. Make event handler collapse and expand and add code below:EH_ONEXPAND:DATA:lv_tree_eventTYPEREFTOcl_thtmlb_tree.

lv_tree_event?=htmlb_event_ex.typed_context->EBHRESULT->expand_node(lv_tree_event->row_key).

EH_ONCOLLAPSE:DATA:lv_tree_eventTYPEREFTOcl_thtmlb_tree.

lv_tree_event?=htmlb_event_ex.typed_context->EBHRESULT->collapse_node(lv_tree_event->row_key).

14. Redefine do_prepare_outputDATA:lv_indexTYPEsy-tabix.DATA:lv_tree_nodeTYPEREFTOif_bsp_wd_tree_node.DATA:lv_proxy_nodeTYPEREFTOcl_bsp_wd_tree_node_proxy.DATA:lv_nTYPEi.DATA:lv_rTYPEi,lt_ebh_histTYPETABLEOFzcust_hier_hist,ls_ebh_histTYPEzcust_hier_hist,lv_iteratorTYPEREFTOif_bol_bo_col_iterator,lv_entityTYPEREFTOcl_crm_bol_entity.

super->do_prepare_output(iv_first_time=iv_first_time).

*ifnothingselected->selectalwaysthefirstnodelv_index=typed_context->EBHRESULT->selected_index.IFlv_indexEBHRESULT->get_node_by_index(1).IFlv_proxy_nodeISBOUND.typed_context->EBHRESULT->deselect_all().lv_proxy_node->if_bsp_wd_tree_node~selected=abap_true.

ENDIF.ENDIF.IFtyped_context->EBHRESULT->node_tabISINITIAL.typed_context->EBHRESULT->refresh().ENDIF.

typed_context->EBHRESULT->build_table().

lv_index=typed_context->EBHRESULT->selected_index.*ifcomingfromtheanotherpage,e.g.editmodeIFtyped_context->EBHRESULT->visible_first_row_indexISINITIAL.typed_context->EBHRESULT->visible_first_row_index=1.ELSE.*ifstayingonthesameview,e.g.positiontyped_context->EBHRESULT->visible_first_row_index=lv_index.ENDIF.

IFlv_index>typed_context->EBHRESULT->maxrowsnumber.lv_n=lv_indexDIVtyped_context->EBHRESULT->maxrowsnumber.lv_r=lv_indexMODtyped_context->EBHRESULT->maxrowsnumber.IFlv_r=0.lv_n=lv_n-1.ENDIF.lv_n=1+(lv_n*typed_context->EBHRESULT->maxrowsnumber).typed_context->EBHRESULT->visible_first_row_index=lv_n.ENDIF.15. Now redefine IF_BSP_WD_TREE_NODE~GET_ICON and do not add any code and activate.16. Tree