Application Development 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: 

How to add 3rd child in simple tree.

Former Member
0 Kudos

Dear All

I have been able to add root, child1 and child2 using class CL_GUI_SIMPLE_TREE.

But when i try to add the child3, it gives an error 'Invalid access to database interface'. Please do let me know if there is any constraint in using CL_GUI_SIMPLE_TREE.

6 REPLIES 6

andreas_mann3
Active Contributor
0 Kudos

here's a piece of code:

       add 1 to childnr.
        concatenate 'child' childnr into childname.
        NODE-NODE_KEY =  childname.
        NODE-ISFOLDER = 'X'.
        NODE-EXPANDER = 'X'.
        ITEM-NODE_KEY = childname.
        move childname to vtab-childname.

        add 1 to dateinr.
        NODE-NODE_KEY =  dateinr.
        ITEM-NODE_KEY = node-node_key.
        move dateinr to vtab-childname.
      modify vtab from wa.
      APPEND ITEM TO ITEM_TABLE.
      APPEND NODE TO NODE_TABLE.
*Datum
      clear item.
      ITEM-NODE_KEY = NODE-NODE_KEY.
      ITEM-ITEM_NAME = '2'.
      ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
      ITEM-LENGTH = 10.
      ITEM-USEBGCOLOR = 'X'.
      ITEM-TEXT = vtab-datum.
      APPEND ITEM TO ITEM_TABLE.
*Größe
      clear item.
      ITEM-NODE_KEY = NODE-NODE_KEY.
      ITEM-ITEM_NAME = '3'.
      ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
      ITEM-LENGTH = 10.
      ITEM-USEBGCOLOR = 'X'.
      ITEM-TEXT = vtab-len.
      APPEND ITEM TO ITEM_TABLE.
*und los
    CALL METHOD G_TREE->ADD_NODES_AND_ITEMS
      EXPORTING
        NODE_TABLE = NODE_TABLE
        ITEM_TABLE = ITEM_TABLE
        ITEM_TABLE_STRUCTURE_NAME = 'MTREEITM'
      EXCEPTIONS
        FAILED = 1
        CNTL_SYSTEM_ERROR = 3
        ERROR_IN_TABLES = 4
        DP_ERROR = 5
        TABLE_STRUCTURE_NAME_NOT_FOUND = 6.
    IF SY-SUBRC <> 0.
      MESSAGE A000.
    ENDIF.

A.

Former Member
0 Kudos

Hi Madhu,

Could you please post your code?

There is no restriction regarding the number of child you can have.

You have to check if you set the name and parents for child3 correctly.

Regards,

Walter

0 Kudos

Dear Walter

Please find below the code.

SELECT * FROM SFLIGHT INTO TABLE IT_SFLIGHT.

IF CUST_CONTAINER IS INITIAL.

CREATE OBJECT CUST_CONTAINER EXPORTING CONTAINER_NAME = 'CCPAR'.

CREATE OBJECT EASY_SPLITTER EXPORTING PARENT = CUST_CONTAINER

ORIENTATION = 1.

CONTAINER1 = EASY_SPLITTER->TOP_LEFT_CONTAINER.

CONTAINER2 = EASY_SPLITTER->BOTTOM_RIGHT_CONTAINER.

CREATE OBJECT ALV EXPORTING I_PARENT = CONTAINER2.

CREATE OBJECT TREE EXPORTING PARENT = CONTAINER1

NODE_SELECTION_MODE = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE.

EVENT-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.

EVENT-APPL_EVENT = 'X'. " process PAI if event occurs

APPEND EVENT TO EVENTS.

CALL METHOD TREE->SET_REGISTERED_EVENTS EXPORTING EVENTS = EVENTS.

IF APPLICATION IS INITIAL.

CREATE OBJECT APPLICATION.

SET HANDLER APPLICATION->HANDLE_DOUBLE_CLICK FOR TREE.

ENDIF.

PERFORM BUILD_TABLE USING NODE_TABLE.

CALL METHOD 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.

IF SY-SUBRC <> 0.

  • MESSAGE A000.

ENDIF.

ENDIF.

FORM BUILD_TABLE USING P_NODE_TABLE TYPE NODE_TABLE_TYPE.

DATA: L_CARRTEXT TYPE TM_NODETXT,

L_CONNTEXT TYPE TM_NODETXT,

L_FLTEXT TYPE TM_NODETXT.

DATA : NODE TYPE MTREESNODE.

SORT IT_SFLIGHT BY CARRID CONNID FLDATE.

LOOP AT IT_SFLIGHT INTO WA_SFLIGHT.

AT FIRST.

NODE-NODE_KEY = '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 = 'CARRID'.

APPEND NODE TO NODE_TABLE.

ENDAT.

AT NEW CARRID.

  • Node with key 'Child1'

NODE-NODE_KEY = WA_SFLIGHT-CARRID. "#EC NOTEXT

" Key of the node

" Node is inserted as child of the node with key 'Root'.

NODE-RELATKEY = 'Root'.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-HIDDEN = ' '.

NODE-DISABLED = ' '.

NODE-ISFOLDER = 'X'.

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_SFLIGHT-CARRID.

APPEND NODE TO NODE_TABLE.

ENDAT.

AT NEW CONNID.

  • Node with key 'Child2'

NODE-NODE_KEY = WA_SFLIGHT-CONNID. "#EC NOTEXT

" Key of the node

" Node is inserted as child of the node with key 'Root'.

NODE-RELATKEY = WA_SFLIGHT-CARRID.

NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.

NODE-HIDDEN = ' '.

NODE-DISABLED = ' '.

NODE-ISFOLDER = 'X'.

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_SFLIGHT-CONNID.

APPEND NODE TO NODE_TABLE.

ENDAT.

  • Node with key 'Child3'

NODE-NODE_KEY = WA_SFLIGHT-FLDATE. "#EC NOTEXT

" Key of the node

" Node is inserted as child of the node with key 'Root'.

NODE-RELATKEY = WA_SFLIGHT-CONNID.

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_SFLIGHT-FLDATE.

APPEND NODE TO NODE_TABLE.

ENDLOOP.

Message was edited by:

Madhu Shankar Nair

0 Kudos

Dear Madhu,

I tried your code in my system and everything works fine.

You say that when you comment the part regarding the 3rd child it works and when you uncomment it you have an error?

Can you describe the error?

Former Member
0 Kudos

http://help.sap.com/saphelp_nw04/helpdata/en/c2/abfceffbacd24185ec7af8a3a2e76a/content.htm,

check this if this is helpful award points dear,

thank you

Former Member
0 Kudos

Problem solved as advised by Andreas