Vous êtes sur la page 1sur 6

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_node TYPE REF TO cl_bsp_wd_value_node,
lv_child
TYPE REF TO if_bsp_wd_tree_node.
lv_child = me->node_factory->get_proxy(
iv_bo = lv_value_node
iv_parent_proxy = me
iv_proxy_type = 'ZCL_EBH_ERH_HIST_TREE_PROXY' ).
lv_child->expand_node( ).
APPEND lv_child TO rt_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.


<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<%@extension name="thtmlb" prefix="thtmlb" %>
<%@extension name="chtmlb" prefix="chtmlb" %>
<%@extension name="xhtmlb" prefix="xhtmlb" %>
<%@extension name="crm_bsp_ic" prefix="crmic" %>
<%@extension name="bsp" prefix="bsp" %>
<chtmlb:configTree id="EBHRESULT"
nodeTable="<%=EBHRESULT->node_tab %>"
nodeTextColumn="NODE_ID"
onCollapseNode="collapse"
onExpandNode="expand"

onRowSelection="select"
selectionMode="SINGLESELECT"
ajaxDeltaHandling=" "
selectedRowIndex="<%=EBHRESULT->selected_index %>"
type="COLUMN"
table="//EBHRESULT/Table"
nodeTextColumnDescription="<%= otr(CRM_IC_APPL_CH_HIST/EXPAND_TREE) %>
"
allRowsEditable="TRUE"
visibleFirstRow="<%=EBHRESULT->visible_first_row_index %>"
visibleRowCount="<%=EBHRESULT->maxRowsNumber %>"
noFrame="X"
personalizable="TRUE"/>
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_event

TYPE REF TO cl_thtmlb_tree.

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

EH_ONCOLLAPSE:
DATA: lv_tree_event

TYPE REF TO cl_thtmlb_tree.

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

14.Redefine do_prepare_output
DATA: lv_index
TYPE sy-tabix.
DATA: lv_tree_node
TYPE REF TO if_bsp_wd_tree_node.
DATA: lv_proxy_node TYPE REF TO cl_bsp_wd_tree_node_proxy.
DATA: lv_n
TYPE i.
DATA: lv_r
TYPE i,
lt_ebh_hist
TYPE TABLE OF zcust_hier_hist,
ls_ebh_hist
TYPE zcust_hier_hist,
lv_iterator
TYPE REF TO if_bol_bo_col_iterator,
lv_entity
TYPE REF TO cl_crm_bol_entity.

super->do_prepare_output( iv_first_time = iv_first_time ).

* if nothing selected -> select always the first node


lv_index = typed_context->EBHRESULT->selected_index.

IF lv_index < 0.
lv_index = 1.
lv_proxy_node ?= typed_context->EBHRESULT->get_node_by_index( 1 ).
IF lv_proxy_node IS BOUND.
typed_context->EBHRESULT->deselect_all( ).
lv_proxy_node->if_bsp_wd_tree_node~selected = abap_true.
ENDIF.
ENDIF.
IF typed_context->EBHRESULT->node_tab IS INITIAL.
typed_context->EBHRESULT->refresh( ).
ENDIF.
typed_context->EBHRESULT->build_table( ).

lv_index = typed_context->EBHRESULT->selected_index.
* if coming from the another page, e.g. edit mode
IF typed_context->EBHRESULT->visible_first_row_index IS INITIAL.
typed_context->EBHRESULT->visible_first_row_index = 1.
ELSE.
* if staying on the same view, e.g. position
typed_context->EBHRESULT->visible_first_row_index = lv_index.
ENDIF.
IF lv_index > typed_context->EBHRESULT->maxrowsnumber.
lv_n = lv_index DIV typed_context->EBHRESULT->maxrowsnumber.
lv_r = lv_index MOD typed_context->EBHRESULT->maxrowsnumber.
IF lv_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

Vous aimerez peut-être aussi