Posted: Tue Sep 11, 2007 3:39 pm Post subject: Sample Tree
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.
* 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 .
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.