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

generating trees in list

Former Member
0 Likes
456

Hi,

I have to generate a tree kind of list(nodes collapsable and expandable)based on a table.

My table is containing 3 fields relevent to this task.

one field(F1) contains nodes, second field(f2) contains the parent node of node in F1, the third field(f3) contains one of its child node.

-> A NODE IN F1 HAVING F2 AS EMPTY WILL BE A ROOT NODE WHICH COMES IN THE UPPERMOST LEVEL.

->A NODE MAY HAVE MULTIPLE CHILD NODES, i.e. DIFFERENT F3 ENTRIES WILL EXIST FOR A COMBINATION OF F1 AND F2.

My requirement is... Can anyone tell me the relevant FUNCTION MODULE which takes these fields as input and generate me tree structure(nodes collapseble and expandable) in list...???

Hi,

I have to generate a tree kind of list(nodes collapsable and expandable)based on a table.

My table is containing 3 fields relevent to this task.

one field(F1) contains nodes, second field(f2) contains the parent node of node in F1, the third field(f3) contains one of its child node.

-> A NODE IN F1 HAVING F2 AS EMPTY WILL BE A ROOT NODE WHICH COMES IN THE UPPERMOST LEVEL.

->A NODE MAY HAVE MULTIPLE CHILD NODES, i.e. DIFFERENT F3 ENTRIES WILL EXIST FOR A COMBINATION OF F1 AND F2.

My requirement is... Can anyone tell me the relevant FUNCTION MODULE which takes these fields as input and generate me tree structure(nodes collapseble and expandable) in list...???

2 REPLIES 2
Read only

Former Member
0 Likes
422

hi,

check the sample code...

REPORT  ZTEST_TREE.

TABLES: KNVH.

TYPES: BEGIN OF WORKTYPE,
         LEVEL(2),
         HKUNNR LIKE KNVH-KUNNR,
         KUNNR  LIKE KNVH-HKUNNR,
       END OF WORKTYPE.

DATA: IT_KNVH TYPE TABLE OF WORKTYPE,
      WA_KNVH LIKE LINE OF IT_KNVH,
      IT_TEMP TYPE TABLE OF WORKTYPE,
      WA_TEMP LIKE LINE OF IT_TEMP,
      IT_WORK TYPE TABLE OF WORKTYPE,
      WA_WORK LIKE LINE OF IT_WORK.

DATA : BEGIN OF IT_NODES OCCURS 0.
        INCLUDE STRUCTURE SNODETEXT.
DATA : END OF IT_NODES.

CONSTANTS: NUMBER_OF_LEVELS TYPE I VALUE 6.
PARAMETER: P_HKUNNR LIKE KNVH-HKUNNR.

START-OF-SELECTION.

* Parent = 1. hierarchy node
WA_TEMP-KUNNR = P_HKUNNR.
APPEND WA_TEMP TO IT_TEMP.
WA_WORK-KUNNR = WA_TEMP-KUNNR.
WA_WORK-LEVEL = 1.
APPEND WA_WORK TO IT_WORK.

* Reading customer hierarchy (max. 6 level)
DO NUMBER_OF_LEVELS TIMES.

  CHECK NOT IT_TEMP IS INITIAL.

  SELECT KUNNR HKUNNR
    FROM KNVH
    INTO CORRESPONDING FIELDS OF TABLE IT_KNVH
    FOR ALL ENTRIES IN IT_TEMP
    WHERE HKUNNR = IT_TEMP-KUNNR.

  LOOP AT IT_KNVH INTO WA_KNVH.
    WA_KNVH-LEVEL = SY-INDEX + 1.
    APPEND WA_KNVH TO IT_WORK.
  ENDLOOP.

  IT_TEMP[] = IT_KNVH[].

ENDDO.

* Hierarchy nodes -> tree control
LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 1.
  PERFORM MAKE_NODE.
  LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 2 AND
                                     HKUNNR = WA_WORK-KUNNR.
    PERFORM MAKE_NODE.
    LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 3 AND
                                       HKUNNR = WA_WORK-KUNNR.
      PERFORM MAKE_NODE.
      LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 4 AND
                                         HKUNNR = WA_WORK-KUNNR.
        PERFORM MAKE_NODE.
        LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 5 AND
                                           HKUNNR = WA_WORK-KUNNR.
          PERFORM MAKE_NODE.
          LOOP AT IT_WORK INTO WA_WORK WHERE LEVEL = 6 AND
                                          HKUNNR = WA_WORK-KUNNR.
            PERFORM MAKE_NODE.
          ENDLOOP.
        ENDLOOP.
      ENDLOOP.
    ENDLOOP.
  ENDLOOP.
ENDLOOP.

* Making the tree control
CALL FUNCTION 'RS_TREE_CONSTRUCT'
       TABLES
            NODETAB      = IT_NODES
       EXCEPTIONS
            TREE_FAILURE = 1.

* Display the tree control
  DATA : F15 TYPE C.
  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
       EXPORTING
            CALLBACK_PROGRAM      = SY-REPID
       IMPORTING
            F15                   = F15 .


FORM MAKE_NODE.
  IT_NODES-NAME = 'test'.
  IT_NODES-COLOR = 1.
  IT_NODES-INTENSIV = 1.
  IT_NODES-TEXT = WA_WORK-KUNNR.
  IT_NODES-TLENGTH = 16.
  IT_NODES-TLEVEL = WA_WORK-LEVEL.
  IT_NODES-TCOLOR = 1.
  IT_NODES-TINTENSIV = 1.
  APPEND IT_NODES.

ENDFORM.

Regards

vijay

Read only

Former Member
0 Likes
422

Hi narendiran,

1. Its quite simple.

2. Basically there are TWO FMs,

which do the job.

3. just copy paste in new program

and u will know the whole logic.

4.

REPORT abc.

DATA : tr LIKE TABLE OF snodetext WITH HEADER LINE.

*----


data

tr-id = '1'.

tr-tlevel = 1.

tr-name = 'amit'.

APPEND tr.

tr-id = '2'.

tr-tlevel = 2.

tr-name = 'mittal'.

APPEND tr.

tr-id = '3'.

tr-tlevel = 2.

tr-name = 'Hello'.

APPEND tr.

tr-id = '4'.

tr-tlevel = 2.

tr-name = 'Brother'.

APPEND tr.

tr-id = '5'.

tr-tlevel = 4.

tr-name = 'Brother'.

APPEND tr.

*----


display

CALL FUNCTION 'RS_TREE_CONSTRUCT'

TABLES

nodetab = tr

EXCEPTIONS

tree_failure = 1

OTHERS = 4.

CALL FUNCTION 'RS_TREE_LIST_DISPLAY'

.

regards,

amit m.