SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Sample Tree



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1637

PostPosted: Tue Sep 11, 2007 3:39 pm    Post subject: Sample Tree Reply with quote

Code:
REPORT ZVVMUR12 .

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 = WA_WORK-KUNNR.
  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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.