Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Tree Display

Former Member
0 Likes
1,116

Hi guys.

I want to create a tree display based on the following SAP standard program

SAPSIMPLE_TREE_CONTROL_DEMO.

Instead of "ROOT" i would like to display all company codes.

While clicking the Company Code it should display all the plants under that specific company code.

can anyone help me out?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,004

in the standard porgram SAPSIMPLE_TREE_CONTROL_DEMO ...

The Root was defualt passed .... if you want to pass the company code then ...

write a select query for Company code and pass it ...... in the below example i am passing the <b>Purchase order list to the RooT</b>. ....

FORM create_alvtree_hierarchy .
  DATA: NODE LIKE MTREESNODE,
        ld_node type string.

  LOOP AT it_ekko INTO wa_ekko.
* Build the node table.

* Caution: The nodes are inserted into the tree according to the order
* in which they occur in the table. In consequence, a node must not
* occur in the node table before its parent node.

*   Node with key 'Root'
    <b>node-node_key = wa_ekko-ebeln.</b> " 'Root'.   "#EC NOTEXT
    " Key of the node
    CLEAR node-relatkey.      " Special case: A root node has no parent
    CLEAR node-relatship.     " node.

    node-hidden = ' '.        " The node is visible,
    node-disabled = ' '.      " selectable,
    node-isfolder = 'X'.      " a folder.
    CLEAR node-n_image.       " Folder-/ Leaf-Symbol in state "closed":
    " use default.
    CLEAR node-exp_image.     " Folder-/ Leaf-Symbol in state "open":
    " use default
    CLEAR node-expander.      " see below.
    node-text = wa_ekko-ebeln.      "'Root'.
    APPEND node TO node_table.

    LOOP AT it_ekpo INTO wa_ekpo WHERE ebeln EQ wa_ekko-ebeln.
*     Node with key wa_ekpo-ebelp    "'Child1'
      ld_node = sy-tabix.
      concatenate wa_ekpo-ebelp ld_node into ld_node.
      node-node_key = ld_node.  "'Child1'. #EC NOTEXT

*     Node is inserted as child of the node with key wa_ekpo-ebeln  "'Root'.
      node-relatkey = wa_ekpo-ebeln.  " 'Root'.
      node-relatship = cl_gui_simple_tree=>relat_last_child.

      node-hidden = ' '.
      node-disabled = ' '.
      node-isfolder = ' '.
      CLEAR node-n_image.
      CLEAR node-exp_image.
      node-expander = ' '.  " The node is marked with a '+', although
*                        it has no children. When the user clicks on the
*                        + to open the node, the event
*                        expand_no_children is fired. The programmer can
*                        add the children of the
*                        node within the event handler of the
*                        expand_no_children event
*                        (see method handle_expand_no_children
*                        of class lcl_application)

      node-text = wa_ekpo-ebelp.
      APPEND node TO node_table.

    ENDLOOP.
  ENDLOOP.

* Add nodes to alv tree
  CALL METHOD GD_TREE->ADD_NODES
    EXPORTING
      TABLE_STRUCTURE_NAME = 'MTREESNODE'
      NODE_TABLE           = NODE_TABLE
    EXCEPTIONS
      FAILED                         = 1
      ERROR_IN_NODE_TABLE            = 2
      DP_ERROR                       = 3
      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
      OTHERS                         = 5.
ENDFORM.                    " create_alvtree_hierarchy

reward points if it is usefull ..

Girish

9 REPLIES 9
Read only

Former Member
0 Likes
1,005

in the standard porgram SAPSIMPLE_TREE_CONTROL_DEMO ...

The Root was defualt passed .... if you want to pass the company code then ...

write a select query for Company code and pass it ...... in the below example i am passing the <b>Purchase order list to the RooT</b>. ....

FORM create_alvtree_hierarchy .
  DATA: NODE LIKE MTREESNODE,
        ld_node type string.

  LOOP AT it_ekko INTO wa_ekko.
* Build the node table.

* Caution: The nodes are inserted into the tree according to the order
* in which they occur in the table. In consequence, a node must not
* occur in the node table before its parent node.

*   Node with key 'Root'
    <b>node-node_key = wa_ekko-ebeln.</b> " 'Root'.   "#EC NOTEXT
    " Key of the node
    CLEAR node-relatkey.      " Special case: A root node has no parent
    CLEAR node-relatship.     " node.

    node-hidden = ' '.        " The node is visible,
    node-disabled = ' '.      " selectable,
    node-isfolder = 'X'.      " a folder.
    CLEAR node-n_image.       " Folder-/ Leaf-Symbol in state "closed":
    " use default.
    CLEAR node-exp_image.     " Folder-/ Leaf-Symbol in state "open":
    " use default
    CLEAR node-expander.      " see below.
    node-text = wa_ekko-ebeln.      "'Root'.
    APPEND node TO node_table.

    LOOP AT it_ekpo INTO wa_ekpo WHERE ebeln EQ wa_ekko-ebeln.
*     Node with key wa_ekpo-ebelp    "'Child1'
      ld_node = sy-tabix.
      concatenate wa_ekpo-ebelp ld_node into ld_node.
      node-node_key = ld_node.  "'Child1'. #EC NOTEXT

*     Node is inserted as child of the node with key wa_ekpo-ebeln  "'Root'.
      node-relatkey = wa_ekpo-ebeln.  " 'Root'.
      node-relatship = cl_gui_simple_tree=>relat_last_child.

      node-hidden = ' '.
      node-disabled = ' '.
      node-isfolder = ' '.
      CLEAR node-n_image.
      CLEAR node-exp_image.
      node-expander = ' '.  " The node is marked with a '+', although
*                        it has no children. When the user clicks on the
*                        + to open the node, the event
*                        expand_no_children is fired. The programmer can
*                        add the children of the
*                        node within the event handler of the
*                        expand_no_children event
*                        (see method handle_expand_no_children
*                        of class lcl_application)

      node-text = wa_ekpo-ebelp.
      APPEND node TO node_table.

    ENDLOOP.
  ENDLOOP.

* Add nodes to alv tree
  CALL METHOD GD_TREE->ADD_NODES
    EXPORTING
      TABLE_STRUCTURE_NAME = 'MTREESNODE'
      NODE_TABLE           = NODE_TABLE
    EXCEPTIONS
      FAILED                         = 1
      ERROR_IN_NODE_TABLE            = 2
      DP_ERROR                       = 3
      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
      OTHERS                         = 5.
ENDFORM.                    " create_alvtree_hierarchy

reward points if it is usefull ..

Girish

Read only

0 Likes
1,004

HI Girish,

I passed the values for company code and plant.

i also wrote a select statement,

SELECT BWKEY
       BUKRS

       FROM T001K

       INTO TABLE ITAB1.

But it is showing an error

<b>KEY ALREADY USED

LAST ERROR NODE KEY :1000</b>

Pls Help

Read only

0 Likes
1,004

It is showing that error and going to dump

Read only

0 Likes
1,004

Hi Dinesh,

BWKEY is the costing area. You said it's about company code and plant. That should be WERKS and BUKRS.

Check the structure of ITAB1, use select into corresponding fields of table, check the results in your table.

Regards,

Clemens

Read only

0 Likes
1,004

HI Clemens Li,

Both BWKEY and WERKS have the same values in T001W and T001K.

i used the select like this,

SELECT T001W~WERKS
       T001K~BUKRS

       INTO TABLE ITAB1

       FROM T001W INNER JOIN T001K ON T001W~BWKEY = T001K~BWKEY
                                  AND T001W~WERKS = T001K~BWKEY.

no it is showing the Error as <b>"NO EMPTY KEYS ALLOWED IN GUI MODE"</b>

and going to dump. It is showing the function module

CALL FUNCTION 'AC_FLUSH_CALL'

MESSAGE ID 'CNDP' TYPE 'X' NUMBER 006 RAISING CNTL_ERROR.

Regards

Dinesh.

Read only

0 Likes
1,004

Hi guys,

Sorry... That error was coming because i called the same Method twice.....

while debugging the values for Company Code and Plant are coming into the WA..

But it is not gettin displayed on the Custom container... The Tree also is not generated.

Read only

Former Member
0 Likes
1,004

Hi dinesh,

I think this should be an interactive one. you design all the plant nodes.

when ever you click on company code write all the plants node.

method 1:

Case sy-ucomm.

when '&IC1'.

write all the plant nodes.

make sy-page value equals to current page

endcase.

Method 2:

write the code in the event AT LINE-SELECTION.

Get the cursor value of company code and print the plants.

make sy-page value equals to current page.

Read only

Former Member
0 Likes
1,004

thanks

Read only

Former Member
0 Likes
1,004

thanks