<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Column Tree - Dynamic in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604963#M596917</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;refer below code... name of the customer container in screen 100 is 'CUSTOM'&lt;/P&gt;&lt;P&gt;This code add nodes at runtime... depending on the use input it reterieves the records from table T001. Number of row will depend on user input.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zpw_tree .

TABLES t001 .

DATA : i_t001 TYPE TABLE OF t001 ,
       w_t001 TYPE t001          .

DATA : g_custom_container TYPE REF TO cl_gui_custom_container,
       g_tree TYPE REF TO cl_column_tree_model.

DATA: item_table TYPE treemcitab,
      item TYPE treemcitem,
      node_key TYPE tm_nodekey.


DATA : hierarchy_header TYPE treemhhdr.

SELECT-OPTIONS : s_bukrs FOR t001-bukrs .

START-OF-SELECTION .

  SELECT *
    INTO TABLE i_t001
    FROM t001
   WHERE bukrs IN s_bukrs .


  CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE STATUS_0100 OUTPUT                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

  CREATE OBJECT g_tree
    EXPORTING
      node_selection_mode = cl_column_tree_model=&amp;gt;node_sel_mode_single
      item_selection = 'X'
      hierarchy_column_name = 'BUKRS'                       "#EC NOTEXT
      hierarchy_header = hierarchy_header
    EXCEPTIONS
      illegal_node_selection_mode = 1
      illegal_column_name = 2.

  CALL METHOD g_tree-&amp;gt;add_column
    EXPORTING
      name = 'BKTXT'
      width = 21
      header_text = 'Company Name'
    EXCEPTIONS
      column_exists       = 1
      illegal_column_name = 2
      too_many_columns    = 3
      illegal_alignment   = 4.

* create a container for the tree model
  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = 'CUSTOM'
    EXCEPTIONS
      cntl_error = 1
      cntl_system_error = 2
      create_error = 3
      lifetime_error = 4
      lifetime_dynpro_dynpro_link = 5.


  CALL METHOD g_tree-&amp;gt;create_tree_control
    EXPORTING
      parent = g_custom_container
    EXCEPTIONS
      lifetime_error = 1
      cntl_system_error = 2
      create_error = 3
      failed = 4
      tree_control_already_created = 5.

* Add node

  CLEAR item.
  item-item_name = 'BUKRS'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Companies'.
  APPEND item TO item_table.

  CLEAR item.
  item-item_name = 'BKTXT'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Company Names'.
  APPEND item TO item_table.

  CALL METHOD g_tree-&amp;gt;add_node
    EXPORTING
      node_key = 'ROOT'
      isfolder = 'X'
      item_table = item_table
    EXCEPTIONS
      node_key_exists         = 1
      node_key_empty          = 2
      illegal_relationship    = 3
      relative_node_not_found = 4
      error_in_item_table     = 5.


  LOOP AT i_t001 INTO w_t001 .

    CLEAR : item ,
            item_table .

    item-item_name = 'BUKRS'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-bukrs.
    APPEND item TO item_table.

    CLEAR item.
    item-item_name = 'BKTXT'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-butxt .
    APPEND item TO item_table.

    node_key = w_t001-bukrs .

    CALL METHOD g_tree-&amp;gt;add_node
      EXPORTING
        node_key = node_key
        relative_node_key = 'ROOT'
        relationship = cl_tree_model=&amp;gt;relat_last_child
        isfolder = ' '
        item_table = item_table
      EXCEPTIONS
        node_key_exists         = 1
        node_key_empty          = 2
        illegal_relationship    = 3
        relative_node_not_found = 4
        error_in_item_table     = 5.


  ENDLOOP.

* expand the root node
  CALL METHOD g_tree-&amp;gt;expand_node
    EXPORTING
      node_key = 'ROOT'
    EXCEPTIONS
      node_not_found = 1.

  CALL METHOD g_tree-&amp;gt;adjust_column_width
     EXPORTING
      all_columns               = 'X'     .


ENDMODULE.                 " STATUS_0100  OUTPUT
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 24 Jul 2007 09:54:36 GMT</pubDate>
    <dc:creator>Pawan_Kesari</dc:creator>
    <dc:date>2007-07-24T09:54:36Z</dc:date>
    <item>
      <title>Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604959#M596913</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have the requirement of developing thr column tree but the problem is that the number of rows that should be displayed is known only at the runtime as the entries are filtered and finally all the entries are present in an internal table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So i want to display the rows in a colum tree format.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I know the methods that are used for the Column tree but i want to know how to handle the number of rows that will be known only at the runtime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 08:48:01 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604959#M596913</guid>
      <dc:creator>Mustameer_Khan</dc:creator>
      <dc:date>2007-07-24T08:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604960#M596914</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Number of rows depend on number of records in internal table passed to method set_table_for_first_display.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Which class are you using...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Are you talking about number of columns?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 09:04:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604960#M596914</guid>
      <dc:creator>Pawan_Kesari</dc:creator>
      <dc:date>2007-07-24T09:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604961#M596915</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Im using  cl_column_tree_model . &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i have fixed number of colums but number of rows is different.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;im using the methods add_nodes,relat_last_child,add_items ...etc etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i want to know how to handle multiple items&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;n&lt;/P&gt;&lt;P&gt;where n is unknown.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 09:09:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604961#M596915</guid>
      <dc:creator>Mustameer_Khan</dc:creator>
      <dc:date>2007-07-24T09:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604962#M596916</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Call method 'add_node' as many time as you want... add_node is meant for adding row dynamically...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 09:37:11 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604962#M596916</guid>
      <dc:creator>Pawan_Kesari</dc:creator>
      <dc:date>2007-07-24T09:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604963#M596917</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;refer below code... name of the customer container in screen 100 is 'CUSTOM'&lt;/P&gt;&lt;P&gt;This code add nodes at runtime... depending on the use input it reterieves the records from table T001. Number of row will depend on user input.. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zpw_tree .

TABLES t001 .

DATA : i_t001 TYPE TABLE OF t001 ,
       w_t001 TYPE t001          .

DATA : g_custom_container TYPE REF TO cl_gui_custom_container,
       g_tree TYPE REF TO cl_column_tree_model.

DATA: item_table TYPE treemcitab,
      item TYPE treemcitem,
      node_key TYPE tm_nodekey.


DATA : hierarchy_header TYPE treemhhdr.

SELECT-OPTIONS : s_bukrs FOR t001-bukrs .

START-OF-SELECTION .

  SELECT *
    INTO TABLE i_t001
    FROM t001
   WHERE bukrs IN s_bukrs .


  CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE STATUS_0100 OUTPUT                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

  CREATE OBJECT g_tree
    EXPORTING
      node_selection_mode = cl_column_tree_model=&amp;gt;node_sel_mode_single
      item_selection = 'X'
      hierarchy_column_name = 'BUKRS'                       "#EC NOTEXT
      hierarchy_header = hierarchy_header
    EXCEPTIONS
      illegal_node_selection_mode = 1
      illegal_column_name = 2.

  CALL METHOD g_tree-&amp;gt;add_column
    EXPORTING
      name = 'BKTXT'
      width = 21
      header_text = 'Company Name'
    EXCEPTIONS
      column_exists       = 1
      illegal_column_name = 2
      too_many_columns    = 3
      illegal_alignment   = 4.

* create a container for the tree model
  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = 'CUSTOM'
    EXCEPTIONS
      cntl_error = 1
      cntl_system_error = 2
      create_error = 3
      lifetime_error = 4
      lifetime_dynpro_dynpro_link = 5.


  CALL METHOD g_tree-&amp;gt;create_tree_control
    EXPORTING
      parent = g_custom_container
    EXCEPTIONS
      lifetime_error = 1
      cntl_system_error = 2
      create_error = 3
      failed = 4
      tree_control_already_created = 5.

* Add node

  CLEAR item.
  item-item_name = 'BUKRS'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Companies'.
  APPEND item TO item_table.

  CLEAR item.
  item-item_name = 'BKTXT'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Company Names'.
  APPEND item TO item_table.

  CALL METHOD g_tree-&amp;gt;add_node
    EXPORTING
      node_key = 'ROOT'
      isfolder = 'X'
      item_table = item_table
    EXCEPTIONS
      node_key_exists         = 1
      node_key_empty          = 2
      illegal_relationship    = 3
      relative_node_not_found = 4
      error_in_item_table     = 5.


  LOOP AT i_t001 INTO w_t001 .

    CLEAR : item ,
            item_table .

    item-item_name = 'BUKRS'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-bukrs.
    APPEND item TO item_table.

    CLEAR item.
    item-item_name = 'BKTXT'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-butxt .
    APPEND item TO item_table.

    node_key = w_t001-bukrs .

    CALL METHOD g_tree-&amp;gt;add_node
      EXPORTING
        node_key = node_key
        relative_node_key = 'ROOT'
        relationship = cl_tree_model=&amp;gt;relat_last_child
        isfolder = ' '
        item_table = item_table
      EXCEPTIONS
        node_key_exists         = 1
        node_key_empty          = 2
        illegal_relationship    = 3
        relative_node_not_found = 4
        error_in_item_table     = 5.


  ENDLOOP.

* expand the root node
  CALL METHOD g_tree-&amp;gt;expand_node
    EXPORTING
      node_key = 'ROOT'
    EXCEPTIONS
      node_not_found = 1.

  CALL METHOD g_tree-&amp;gt;adjust_column_width
     EXPORTING
      all_columns               = 'X'     .


ENDMODULE.                 " STATUS_0100  OUTPUT
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 09:54:36 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604963#M596917</guid>
      <dc:creator>Pawan_Kesari</dc:creator>
      <dc:date>2007-07-24T09:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604964#M596918</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Pavan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My requirement is such that each node can have n number of items and this inturn can have items. I will try doing the example which u have suggested and get back if i have any problems with that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 09:58:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604964#M596918</guid>
      <dc:creator>Mustameer_Khan</dc:creator>
      <dc:date>2007-07-24T09:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Column Tree - Dynamic</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604965#M596919</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That not a big problem.. you will have to play with tha values of   'node_key' and 'relative_node_key'  of method add_node... for example see this version.. this will add row as child of previous row...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
REPORT zpw_tree .

TABLES t001 .

DATA : i_t001 TYPE TABLE OF t001 ,
       w_t001 TYPE t001          .

DATA : g_custom_container TYPE REF TO cl_gui_custom_container,
       g_tree TYPE REF TO cl_column_tree_model.

DATA: item_table TYPE treemcitab,
      item TYPE treemcitem,
      node_key TYPE tm_nodekey,
      parent   type tm_nodekey.


DATA : hierarchy_header TYPE treemhhdr.

SELECT-OPTIONS : s_bukrs FOR t001-bukrs .

START-OF-SELECTION .

  SELECT *
    INTO TABLE i_t001
    FROM t001
   WHERE bukrs IN s_bukrs .


  CALL SCREEN 100.

*---------------------------------------------------------------------*
*       MODULE STATUS_0100 OUTPUT                                     *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.

  CREATE OBJECT g_tree
    EXPORTING
      node_selection_mode = cl_column_tree_model=&amp;gt;node_sel_mode_single
      item_selection = 'X'
      hierarchy_column_name = 'BUKRS'                       "#EC NOTEXT
      hierarchy_header = hierarchy_header
    EXCEPTIONS
      illegal_node_selection_mode = 1
      illegal_column_name = 2.

  CALL METHOD g_tree-&amp;gt;add_column
    EXPORTING
      name = 'BKTXT'
      width = 21
      header_text = 'Company Name'
    EXCEPTIONS
      column_exists       = 1
      illegal_column_name = 2
      too_many_columns    = 3
      illegal_alignment   = 4.

* create a container for the tree model
  CREATE OBJECT g_custom_container
    EXPORTING
      container_name = 'CUSTOM'
    EXCEPTIONS
      cntl_error = 1
      cntl_system_error = 2
      create_error = 3
      lifetime_error = 4
      lifetime_dynpro_dynpro_link = 5.


  CALL METHOD g_tree-&amp;gt;create_tree_control
    EXPORTING
      parent = g_custom_container
    EXCEPTIONS
      lifetime_error = 1
      cntl_system_error = 2
      create_error = 3
      failed = 4
      tree_control_already_created = 5.

* Add node

  CLEAR item.
  item-item_name = 'BUKRS'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Companies'.
  APPEND item TO item_table.

  CLEAR item.
  item-item_name = 'BKTXT'.
  item-class = cl_column_tree_model=&amp;gt;item_class_text.
  item-text = 'Company Names'.
  APPEND item TO item_table.

  CALL METHOD g_tree-&amp;gt;add_node
    EXPORTING
      node_key = 'ROOT'
      isfolder = 'X'
      item_table = item_table
    EXCEPTIONS
      node_key_exists         = 1
      node_key_empty          = 2
      illegal_relationship    = 3
      relative_node_not_found = 4
      error_in_item_table     = 5.


  LOOP AT i_t001 INTO w_t001 .

    IF sy-tabix = 1 .
      parent = 'ROOT' .
    else.
      parent = node_key .
    endif.

    CLEAR : item ,
            item_table .

    item-item_name = 'BUKRS'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-bukrs.
    APPEND item TO item_table.

    CLEAR item.
    item-item_name = 'BKTXT'.
    item-class = cl_column_tree_model=&amp;gt;item_class_text.
    item-text = w_t001-butxt .
    APPEND item TO item_table.

    node_key = w_t001-bukrs .

    CALL METHOD g_tree-&amp;gt;add_node
      EXPORTING
        node_key = node_key
        relative_node_key = parent
        relationship = cl_tree_model=&amp;gt;relat_last_child
        isfolder = ' '
        item_table = item_table
      EXCEPTIONS
        node_key_exists         = 1
        node_key_empty          = 2
        illegal_relationship    = 3
        relative_node_not_found = 4
        error_in_item_table     = 5.


  ENDLOOP.

* expand the root node
  CALL METHOD g_tree-&amp;gt;expand_node
    EXPORTING
      node_key = 'ROOT'
    EXCEPTIONS
      node_not_found = 1.

  CALL METHOD g_tree-&amp;gt;adjust_column_width
     EXPORTING
      all_columns               = 'X'     .


ENDMODULE.                 " STATUS_0100  OUTPUT
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Jul 2007 10:25:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/column-tree-dynamic/m-p/2604965#M596919</guid>
      <dc:creator>Pawan_Kesari</dc:creator>
      <dc:date>2007-07-24T10:25:21Z</dc:date>
    </item>
  </channel>
</rss>

