cancel
Showing results for 
Search instead for 
Did you mean: 

How to use TreeByKeyTableColumn (with sample code)

Former Member
0 Kudos

Hi Guys,

Can anyone tell me How to bind data with TreeByKeyTableColumn ? (with sample code). Is it possible to add checkbox with TreeByKeyTableColumn? Kindly aware me further in this regards....

Thanks,

Ravin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

in the webdynpro component WDT_TREE_TABLE_BY_KEY in your system you have an example with coding

grtz,

Koen

Answers (5)

Answers (5)

Former Member
0 Kudos

So, Here i'm closing this issue....If any one able to make checkbox as first column in same table having TreeBytableColumn (which will be master column) then kindly reply me...

Former Member
0 Kudos

Hi

Answering to following question

How to bind data with TreeByKeyTableColumn

Create the Context

Click on the Context tab of the view. Create a node name it as "AIR_LINES". Set the Cardinality as 0...N. Make it a Singleton Node. Give a method name in supply function column by name "GENERATE_TREE".

Then we will create attributes required for the tree column. We require 5 attributes

1. Attribute which contains the current level of the node. Create an attribute called "NODE_LEVEL" of type STRING.

2. Attribute which contains the parent level of the node. Create an attribute called "PARENT_LEVEL" of type STRING.

3. Attribute which contains the contents of the node. Create an attribute called "NODE_CONTENT" of type STRING.

4. Attribute which contains X or Space depending upon the node is expanded or not. Create an attribute called "EXPANDED" of type WDY_BOOLEAN.

5. Attribute which contains X or Space depending upon the type of the node, whether the node is a branch or a leaf. Create an attribute called "IS_LEAF" of type WDY_BOOLEAN.

Click on the layout tab of the view. Add UI element of type Table, give the name as 'Tree Table'. Bind the DATASOURCE property of the table to the AIR_LINES node of the view context.

Give heading to the table as "Booking Details".

Right click on table node crated and chose Insert Master Column.

Name it as "TREE_NODE" and chose TreeByKeyTableColumn from the dropdown

Bind the 4 properties with context attributes we have already created.

Expanded -> Expanded.

Is_leaf -> Is_leaf.

Parent_key -> Parent_level

Row_key -> Node_level

Give heading to the tree node in the text field.

Insert a cell editor in the tree column and chose the type as Text view.

Bind the text property of the text view to the NODE_CONTENT attribute of the context.

Similarly create a table column to display the second column i.e. Node type.

Right click -> Insert table column -> Give the heading in the text property of the header (Node Type).

Right click -> Insert Cell Editor -> Bind the text property to NODE_TYPE attribute of the context.

Click on the Methods tab of the view. You will find the method of type supply function which we created during the creation of node. Double click and write the following code.

METHOD generate_tree .

          • Ideally this code must go to a method of a class which will return four internal tables

          • start of Model code

TYPES : BEGIN OF ty_scarr, " Air line Table

carrid TYPE s_carr_id,

END OF ty_scarr.

TYPES : BEGIN OF ty_spfli, " Flight Connection Table

carrid TYPE s_carr_id,

connid TYPE s_conn_id,

END OF ty_spfli.

TYPES : BEGIN OF ty_sflight, " Flight Table

carrid TYPE s_carr_id,

connid TYPE s_conn_id,

fldate TYPE s_date,

END OF ty_sflight.

TYPES : BEGIN OF ty_sbook, " Flight Booking Table

carrid TYPE s_carr_id,

connid TYPE s_conn_id,

fldate TYPE s_date,

bookid TYPE s_book_id,

END OF ty_sbook.

DATA : lt_scarr TYPE TABLE OF ty_scarr.

DATA : lt_spfli TYPE TABLE OF ty_spfli.

DATA : lt_sflight TYPE TABLE OF ty_sflight.

DATA : lt_sbook TYPE TABLE OF ty_sbook.

DATA : ls_scarr TYPE ty_scarr.

DATA : ls_spfli TYPE ty_spfli.

DATA : ls_sflight TYPE ty_sflight.

DATA : ls_sbook TYPE ty_sbook.

SELECT carrid

FROM scarr

INTO TABLE lt_scarr

UP TO 2 ROWS.

IF lt_scarr[] IS NOT INITIAL.

SELECT carrid connid

FROM spfli

INTO TABLE lt_spfli

FOR ALL ENTRIES IN lt_scarr

WHERE carrid EQ lt_scarr-carrid.

IF lt_spfli[] IS NOT INITIAL.

SELECT carrid connid fldate

FROM sflight

INTO TABLE lt_sflight

FOR ALL ENTRIES IN lt_spfli

WHERE carrid EQ lt_spfli-carrid

AND connid EQ lt_spfli-connid.

        • For an additional level of branching

  • IF lt_spfli[] IS NOT INITIAL.

*

  • SELECT carrid connid fldate bookid

  • FROM sbook

  • INTO TABLE lt_sbook

  • FOR ALL ENTRIES IN lt_sflight

  • WHERE carrid EQ lt_sflight-carrid

  • AND connid EQ lt_sflight-connid

  • AND fldate EQ lt_sflight-fldate.

*

  • ENDIF.

ENDIF.

ENDIF.

          • End of Model code

          • Start of code for generation the tree

  • data declaration

DATA lt_table TYPE wd_this->elements_air_lines.

DATA ls_table LIKE LINE OF lt_table.

DATA lvl1_index TYPE string.

DATA lvl2_index TYPE string.

DATA lvl3_index TYPE string.

DATA lvl4_index TYPE string.

        • Level 1

LOOP AT lt_scarr INTO ls_scarr.

lvl1_index = sy-tabix.

condense lvl1_index.

  • create a row

ls_table-node_level = lvl1_index. " 1 st level

ls_table-parent_level = ''. " No parent

ls_table-node_content = ls_scarr-carrid.

ls_table-node_type = 'Air Line'.

ls_table-is_leaf = abap_false.

INSERT ls_table INTO TABLE lt_table.

clear ls_table.

        • Level 2

LOOP AT lt_spfli INTO ls_spfli.

lvl2_index = sy-tabix.

condense lvl2_index.

  • create a row

concatenate lvl1_index `.` lvl2_index into ls_table-node_level.

ls_table-parent_level = lvl1_index. " Parent 1 st level

ls_table-node_content = ls_spfli-connid.

ls_table-node_type = 'Flight Connection'.

ls_table-is_leaf = abap_false.

INSERT ls_table INTO TABLE lt_table.

clear ls_table.

        • Level 3

LOOP AT lt_sflight INTO ls_sflight.

lvl3_index = sy-tabix.

condense lvl3_index.

  • create a row

concatenate lvl1_index `.` lvl2_index `.` lvl3_index into ls_table-node_level.

concatenate lvl1_index `.` lvl2_index into ls_table-parent_level.

ls_table-node_content = ls_sflight-fldate.

ls_table-node_type = 'Flight'.

ls_table-is_leaf = abap_true.

INSERT ls_table INTO TABLE lt_table.

clear ls_table.

          • If you want an additional level it can be programmed like this

          • Level 4

*LOOP AT lt_sbook INTO ls_sbook.

  • lvl4_index = sy-tabix.

  • condense lvl4_index.

*

    • create a row

  • concatenate lvl1_index `.` lvl2_index `.` lvl3_index `.` lvl4_index into ls_table-node_level.

  • concatenate lvl1_index `.` lvl2_index `.` lvl3_index into ls_table-parent_level.

*

  • ls_table-node_content = ls_sbook-bookid.

  • ls_table-node_type = 'Booking'.

  • ls_table-is_leaf = abap_true. " as its the final level in our hier archy

  • INSERT ls_table INTO TABLE lt_table.

*

*

  • ENDLOOP.

ENDLOOP.

ENDLOOP.

ENDLOOP.

  • bind all the elements

node->bind_table(

new_items = lt_table

set_initial_elements = abap_true ).

*

ENDMETHOD.

Former Member
0 Kudos

Did you solve the problem?

-

Achyut

Former Member
0 Kudos

When you use TreeByTableColumn then it will become master column and it won't allow the checkbox as first column in that case.

Former Member
0 Kudos

Hi,

You can add checkbox in one more column and not as master column,

Following link to Wiki gives you code as well ,

[Integration of Tree Structure in a Table using Webdynpro Abap|https://www.sdn.sap.com/irj/sdn/wiki?path=/display/profile/2007/09/11/integrationofTreeStructureinaTableusingWebdynpro+Abap]

-

Achyut

Former Member
0 Kudos

Hi Guys,

Thanks for your input but I have already used TreeByTableCloum and it works fine and i know its possible to add Checkbox also in TableColumn, only the thing i want to know is that Checkbox Column as first column while having TreeByTableColumn also in that table which is not possible,,,,,,,

Thanks,

Ravin Joshi

former_member182190
Active Participant
0 Kudos

Hi Ravin,

Its not possible as theTreebykey will be a master column .

You can have Checkbox as the second column only.

Regards,

Ismail.

Former Member
0 Kudos

Thanks Ismail, as rest of all i bind it with table except first-column as checkbox.....

former_member182190
Active Participant
0 Kudos

Hi Ravin,

To add a checkbox along with a Treebykey, you need to create a table with

one column as the Tree( this will be the master column) and a second column

as checkbox.

Hope this helps.

Regards,

Ismail.

Former Member
0 Kudos

Actually, i want the checkbox column is ahead of treebytablecolumn for selection purpose, is it possible?