二维码

[Tree] RS_TREE_LIST_DISPLAY和RS_TREE_CONSTRUCT构建alv tree

Twilight发表于 2014-08-26 21:34Twilight 最后回复于 2014-08-26 21:34 [复制链接] 3871 0

程序代码:
  1. TYPE-POOLS : fibs,stree.
  2. TYPE-POOLS:slis.
  3. DATA : t_node TYPE snodetext.
  4. DATA : it_node LIKE TABLE OF t_node,
  5.        wa_node LIKE t_node.
  6. DATA: t_fieldcat    TYPE slis_t_fieldcat_ALV,
  7.       fs_fieldcat   TYPE slis_fieldcat_alv.
  8. DATA:w_repid LIKE sy-repid.
  9. *Internal Table declarations
  10. DATA: BEGIN OF fs_scarr,
  11.         carrid LIKE scarr-carrid,
  12.       END OF fs_scarr.
  13. DATA:BEGIN OF fs_spfli,
  14.         carrid LIKE spfli-carrid,
  15.         connid LIKE spfli-connid,
  16.      END OF fs_spfli.
  17. DATA:BEGIN OF fs_sflight,
  18.         carrid LIKE sflight-carrid,
  19.         connid LIKE sflight-connid,
  20.         fldate LIKE sflight-fldate,
  21.      END OF fs_sflight.
  22. DATA:BEGIN OF fs_sbook,
  23.         carrid LIKE sbook-carrid,
  24.         connid LIKE sbook-connid,
  25.         fldate LIKE sbook-fldate,
  26.         bookid LIKE sbook-bookid,
  27.      END OF fs_sbook.
  28. DATA:t_scarr LIKE TABLE OF fs_scarr,
  29.      t_spfli LIKE TABLE OF fs_spfli,
  30.      t_sflight LIKE TABLE OF fs_sflight,
  31.      t_sbook LIKE TABLE OF fs_sbook.

  32. START-OF-SELECTION.
  33.   PERFORM get_data.
  34.   PERFORM build_tree.
  35.   PERFORM display_tree.
  36. *&----------------------------------------------------------------*
  37. *&      Form  get_data
  38. *&----------------------------------------------------------------*
  39. FORM get_data .
  40.   SELECT carrid
  41.          FROM scarr
  42.          INTO TABLE t_scarr.
  43.   SELECT carrid
  44.           connid
  45.           FROM spfli
  46.           INTO TABLE t_spfli
  47.           FOR ALL ENTRIES IN t_scarr
  48.           WHERE carrid EQ t_scarr-carrid.
  49. ENDFORM.                    " get_data
  50. *&----------------------------------------------------------------*
  51. *&      Form  build_tree
  52. *&----------------------------------------------------------------*
  53. FORM build_tree .
  54.   CLEAR: it_node,
  55.          wa_node.
  56.   SORT: t_scarr BY carrid,
  57.         t_spfli BY carrid connid,
  58.         t_sflight BY carrid connid fldate,
  59.         t_sbook BY carrid connid fldate bookid.
  60.   wa_node-type = 'T'.
  61.   wa_node-name = 'Flight Details'.
  62.   wa_node-tlevel = '01'.
  63.   wa_node-nlength = '15'.
  64.   wa_node-color = '4'.
  65.   wa_node-text = 'Flight'.
  66.   wa_node-tlength ='20'.
  67.   wa_node-tcolor = 3.
  68.   APPEND wa_node TO it_node.
  69.   CLEAR wa_node.
  70.   LOOP AT t_scarr INTO fs_scarr.
  71.     wa_node-type = 'P'.
  72.     wa_node-name = 'CARRID'.
  73.     wa_node-tlevel = '02'.
  74.     wa_node-nlength = '8'.
  75.     wa_node-color = '1'.
  76.     wa_node-text = fs_scarr-carrid.
  77.     wa_node-tlength ='20'.
  78.     wa_node-tcolor = 4.
  79.     APPEND wa_node TO it_node.
  80.     CLEAR wa_node.
  81.     LOOP AT t_spfli INTO fs_spfli WHERE carrid EQ fs_scarr-carrid.
  82.       wa_node-type = 'P'.
  83.       wa_node-name = 'CONNID'.
  84.       wa_node-tlevel = '03'.
  85.       wa_node-nlength = '8'.
  86.       wa_node-color = '1'.
  87.       wa_node-text = fs_spfli-connid.
  88.       wa_node-tlength ='20'.
  89.       wa_node-tcolor = 4.
  90.       APPEND wa_node TO it_node.
  91.       CLEAR wa_node.
  92.     ENDLOOP.
  93.   ENDLOOP.
  94. ENDFORM.                    " build_tree

  95. FORM display_tree.
  96. *Fm for constructing the tree
  97.   CALL FUNCTION 'RS_TREE_CONSTRUCT'
  98.     TABLES
  99.       nodetab = it_node.
  100.   IF sy-subrc <> 0.
  101. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
  102. *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  103.   ENDIF.
  104. *FM for displaying the tree
  105.   CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
  106.     EXPORTING
  107.       callback_program     = sy-repid
  108.       check_duplicate_name = '1'
  109.       color_of_node        = '4'
  110.       color_of_mark        = '3'
  111.       color_of_link        = '1'
  112.       color_of_match       = '5'
  113.       node_length          = 30
  114.       text_length          = 75
  115.       use_control          = 'L'.
  116. ENDFORM.                    " build_tree
复制代码

程序执行效果:
alv list tree.png
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表