创建list ALV tree[RS_TREE_LIST_DISPLAY]详解编程语言

ABAP程序中的ALV显示是很常用的一种数据展示手段,除了常规的alv,有时也会用到ALV tree这种有层次结构的展示方式更好的展现数据,下面介绍一个创建list alv tree的方法:

1)用函数RS_TREE_CONSTRUCT构造alv 树的层次结构,

alv tree的节点类型(node type)分两种:T和P,区别如下:区别就是个文件夹的图标。

2017-03-13_20-44-24

2)调用函数RS_TREE_LIST_DISPLAY显示alv tree

完整代码:

用list alv tree来显示采购订单和采购订单行项目。

REPORT ztest_tree_alv. 
 
*Data declaration for additional node information 
DATA : gwa_node TYPE snodetext. 
*Internal table for nodes 
DATA : git_node LIKE TABLE OF gwa_node. 
DATA:git_ekko TYPE STANDARD TABLE OF ekko WITH HEADER LINE, 
     git_ekpo TYPE STANDARD TABLE OF ekpo WITH HEADER LINE. 
 
CLEAR :  gwa_node. 
REFRESH: git_node. 
 
SELECT * 
  FROM ekko 
  INTO TABLE git_ekko 
 UP TO 10 ROWS. 
 
SELECT * 
  INTO TABLE git_ekpo 
  FROM ekpo 
   FOR ALL ENTRIES IN git_ekko 
 WHERE ebeln = git_ekko-ebeln. 
 
gwa_node-type = 'T'.                   "第一个 
gwa_node-id   = 'FIRST'. 
gwa_node-name = '采购'. 
gwa_node-tlevel = 1.                   "层次一 
gwa_node-nlength = '15'. 
gwa_node-color = '4'. 
gwa_node-text = '采购订单信息'. 
gwa_node-tlength ='20'. 
gwa_node-tcolor = 3. 
APPEND gwa_node TO git_node. 
LOOP AT git_ekko. 
  CLEAR gwa_node. 
  gwa_node-type = 'P'. 
  gwa_node-id   = 'HEAD'. 
  gwa_node-name = '采购订单号'. 
  gwa_node-tlevel = 2.                  "层次二 
  gwa_node-nlength = '8'. 
  gwa_node-color = '1'. 
  gwa_node-text = git_ekko-ebeln. 
  gwa_node-tlength ='20'. 
  gwa_node-tcolor = 4. 
  APPEND gwa_node TO git_node. 
  CLEAR gwa_node. 
  LOOP AT git_ekpo where ebeln = git_ekko-ebeln. 
    CLEAR gwa_node. 
    gwa_node-type = 'P'. 
    gwa_node-id   = 'ITEM'. 
    gwa_node-name = '行项目'. 
    gwa_node-tlevel = 3.                  "层次三 
    gwa_node-nlength = '6'. 
    gwa_node-color = '1'. 
    gwa_node-text = git_ekpo-ebelp. 
    gwa_node-tlength ='5'. 
    gwa_node-tcolor = 4. 
    APPEND gwa_node TO git_node. 
    CLEAR gwa_node. 
  ENDLOOP. 
ENDLOOP. 
 
*Fm for constructing the tree 
CALL FUNCTION 'RS_TREE_CONSTRUCT' 
  TABLES 
    nodetab = git_node. 
 
*FM for displaying the tree 
CALL FUNCTION 'RS_TREE_LIST_DISPLAY' 
  EXPORTING 
    callback_program     = sy-repid 
    check_duplicate_name = '1' 
    color_of_node        = '4' 
    color_of_mark        = '3' 
    color_of_link        = '1' 
    color_of_match       = '5' 
    node_length          = 30 
    text_length          = 75 
    use_control          = 'L'.

运行结果:

2017-03-13_20-29-10

以上。

原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/19230.html

(0)
上一篇 2021年7月19日 22:00
下一篇 2021年7月19日 22:00

相关推荐

发表回复

登录后才能评论