Tree Control 是最常用的Windows控件之一,在其他语言中成为"Tree View"等,ABAP的 Tree Contiol 能实现类似的功能。
本文主要介绍一下内容:
1. 实例一个简单的 Tree Control,双击取得节点的Key 和 TEXT
2. 建立有数据表接口的Tree Control 对象
3. 通过右键菜单实现 Tree Control节点的 增 删 改 功能
4. Tree Control对象与ALV Grid对象关联
××××××××××××××××××××华丽的分割线×××××××××××××××××××××××
BEGIN
(一)实例一个简单的 Tree Control,双击取得节点的Key 和 TEXT.
1. 创建一个ABAP程序
2. 在程序中添加一个屏幕100,使用屏幕制作器,建立Screen,添加屏幕对象
创建好的屏幕和对象界面如图:
屏幕元素清单
逻辑流程序
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0100.
主程序
1 *&---------------------------------------------------------------------*
2 *& Report ZHAIM_TREE_CONTROL
3 *&
4 *&---------------------------------------------------------------------*
5 *&
6 *&
7 *&---------------------------------------------------------------------*
8
9 REPORT ZHAIM_TREE_CONTROL.
10 * 功能码
11 DATA: OK_CODE TYPE SY-UCOMM,
12 SAVE_OK TYPE SY-UCOMM.
13 * key text
14 DATA: NODEKEY(20) TYPE C,
15 NODETXT(20) TYPE C.
16
17 * 定制控制对象
18 DATA: WA_CONTAINER TYPE SCRFNAME VALUE 'TREE',
19 * 客户对象
20 WA_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
21 * 实例化对象
22 WA_TREE TYPE REF TO CL_GUI_SIMPLE_TREE.
23 * 节点信息表
24 DATA: IT_NODETABLE LIKE TABLE OF MTREESNODE,
25 IW_NODETABLE TYPE MTREESNODE.
26
27 DATA WA_SPFLI TYPE TABLE OF SPFLI.
28
29 *创建一个类,实现一个双击方法
30 CLASS LCL_APPLICATION DEFINITION DEFERRED.
31
32 *&---------------------------------------------------------------------*
33 *& Class (DEFINITION) LCL_APPLICATION
34 *&---------------------------------------------------------------------*
35 * Text
36 *----------------------------------------------------------------------*
37 CLASS LCL_APPLICATION DEFINITION.
38 PUBLIC SECTION.
39 METHODS HANDLE_NODE_DOUBLE_CLICK
40 FOR EVENT NODE_DOUBLE_CLICK
41 OF CL_GUI_SIMPLE_TREE
42 IMPORTING NODE_KEY.
43 ENDCLASS. "LCL_APPLICATION
44 *&---------------------------------------------------------------------*
45 *& Class (Implementation) LCL_APPLICATION
46 *&---------------------------------------------------------------------*
47 * Text
48 *----------------------------------------------------------------------*
49 CLASS LCL_APPLICATION IMPLEMENTATION.
50
51 METHOD HANDLE_NODE_DOUBLE_CLICK.
52
53 NODEKEY = NODE_KEY.
54
55 READ TABLE IT_NODETABLE WITH KEY NODE_KEY = NODE_KEY INTO IW_NODETABLE.
56
57 NODETXT = IW_NODETABLE-TEXT.
58 ENDMETHOD.
59
60 ENDCLASS. "LCL_APPLICATION
61
62 * 双击方法的类的实例化对象 准备在PBO中分配给TREE对象
63 DATA: G_APPLICATION TYPE REF TO LCL_APPLICATION.
64
65
66 START-OF-SELECTION.
67
68 CREATE OBJECT G_APPLICATION.
69
70 CALL SCREEN 100.
71
72
73 *&---------------------------------------------------------------------*
74 *& Module USER_COMMAND_0100 INPUT
75 *&---------------------------------------------------------------------*
76 * text
77 *----------------------------------------------------------------------*
78 MODULE USER_COMMAND_0100 INPUT.
79
80 SAVE_OK = OK_CODE.
81
82 CLEAR OK_CODE.
83
84 CASE SAVE_OK.
85 WHEN '