Tree Control的基本实现步骤
首先还是要引用ABAP Tree的相关类
cl_gui_custom_container 容器一定必不可少
cl_gui_simple_tree
创建屏幕100并创建container
在100屏幕的PBO中实例化container 和Tree Control
接下来就要为Tree逐层添加节点
如果为顶层只需要分配自身的node_key即可,如果为子层则在分配node_key的同时,还要分配父层节点relatkey,之后还要分配relat_last_child属性,具体参数设置如下:
*顶层
CLEAR gt_node[] .
node-node_key = 'SO_NO'.
node-relatkey = ''. "顶层时为空
node-relatship = ''. "顶层时为空
node-hidden = ''.
node-disabled = ''.
node-isfolder = 'X'. "是否为文件夹
node-text = '订单号'.
APPEND node TO gt_node.
CLEAR node.
*二层
CLEAR node.
node-node_key = '10000000421'.
node-relatkey = 'SO_NO'. "填入父层节点KEY
node-relatship = cl_gui_simple_tree=>relat_last_child.
"访问relat_last_child属性
node-hidden = ''.
node-disabled = ''.
node-isfolder = 'X'.
node-text = 'SO编号:10000000421'.
APPEND node TO gt_node.
CLEAR node.
node-node_key = '10000000422'.
node-relatkey = 'SO_NO'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-hidden = ''.
node-disabled = ''.
node-isfolder = 'X'.
node-text = 'SO编号:10000000422'.
APPEND node TO gt_node.
*三层
CLEAR node.
node-node_key = '100'.
node-relatkey = '10000000421'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-hidden = ''.
node-disabled = ''.
node-isfolder = ''.
node-n_image = '@9Y@'. "填入ICON
node-exp_image = '@9Y@'. "填入ICON
node-text = 'SO项目号:100'.
APPEND node TO gt_node.
CLEAR node.
node-node_key = '200'.
node-relatkey = '10000000421'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-hidden = ''.
node-disabled = ''.
node-isfolder = ''.
node-n_image = '@9Y@'. "填入ICON
node-exp_image = '@9Y@'. "填入ICON
node-text = 'SO项目号:200'.
APPEND node TO gt_node.
CLEAR node.
node-node_key = '300'.
node-relatkey = '10000000422'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-hidden = ''.
node-disabled = ''.
node-isfolder = ''.
node-n_image = '@9Y@'. "填入ICON
node-exp_image = '@9Y@'. "填入ICON
node-text = 'SO项目号:300'.
APPEND node TO gt_node.
节点写好后调用add_nodes方法
CALL METHOD lo_tree->add_nodes
EXPORTING
table_structure_name = 'MTREESNODE'
gt_node = gt_node.
创建event事件方法,这里只使用了双击事件方法
CLASS lcl_application DEFINITION.
PUBLIC SECTION.
*自定义双击方法,参数为节点关键字
METHODS handle_node_double_click
FOR EVENT node_double_click
OF cl_gui_simple_tree
IMPORTING node_key.
ENDCLASS.
CLASS lcl_application IMPLEMENTATION.
METHOD handle_node_double_click.
nodekey = node_key.
READ TABLE gt_node WITH KEY node_key = node_key INTO node.
nodetext = node-text.
ENDMETHOD.
ENDCLASS.
将其引用之后在START-OF-SELECTION事件时将其实例化
DATA: lo_application TYPE REF TO lcl_application.
START-OF-SELECTION.
CREATE OBJECT lo_application.
CALL SCREEN 100.
最后完成事件方法的定义及注册
*事件内表及单个事件对象.
DATA: gt_event TYPE cntl_simple_gt_event,
gs_event TYPE cntl_simple_event.
*定义双击事件
gs_event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
gs_event-appl_event = 'X'.
APPEND gs_event TO gt_event.
*添加事件内表
CALL METHOD lo_tree->set_registered_gt_event
EXPORTING
gt_event = gt_event.
*注册双击事件
SET HANDLER lo_application->handle_node_double_click FOR lo_tree.
ENDFORM.
完成之后看一看效果