实例:ABAP Tree Control 使用

Tree Control 是最常用的Windows控件之一,在其他语言中成为"Tree View"等,ABAP的 Tree Contiol 能实现类似的功能,

下面实例一个简单的 Tree Control.

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 ‘BACK‘.
 86       LEAVE PROGRAM.
 87     WHEN OTHERS.
 88   ENDCASE.
 89
 90 ENDMODULE.                 " USER_COMMAND_0100  INPUT
 91 *&---------------------------------------------------------------------*
 92 *&      Module  STATUS_0100  OUTPUT
 93 *&---------------------------------------------------------------------*
 94 *       text
 95 *----------------------------------------------------------------------*
 96 MODULE STATUS_0100 OUTPUT.
 97   SET PF-STATUS ‘TREECTRL_GUIS‘.
 98   SET TITLEBAR ‘TREE CONTROL‘.
 99 IF WA_CUSTOM_CONTAINER IS INITIAL.
100   PERFORM FRM_CREATE_TREE.
101 ENDIF.
102 ENDMODULE.                 " STATUS_0100  OUTPUT
103
104 *&---------------------------------------------------------------------*
105 *&      Form  FRM_CREATE_TREE
106 *&---------------------------------------------------------------------*
107 *       text
108 *----------------------------------------------------------------------*
109 *  -->  p1        text
110 *  <--  p2        text
111 *----------------------------------------------------------------------*
112 FORM FRM_CREATE_TREE .
113   DATA: EVENTS TYPE CNTL_SIMPLE_EVENTS,
114         EVENT1 TYPE CNTL_SIMPLE_EVENT.
115 * 定制控制对象,指定tree control的容器
116   CREATE OBJECT WA_CUSTOM_CONTAINER
117    EXPORTING
118 *    PARENT                      =
119     CONTAINER_NAME              = WA_CONTAINER " 定制对象名:TREE
120 *    STYLE                       =
121 *    LIFETIME                    = lifetime_default
122 *    REPID                       =
123 *    DYNNR                       =
124 *    NO_AUTODEF_PROGID_DYNNR     =
125   EXCEPTIONS
126     CNTL_ERROR                  = 1
127     CNTL_SYSTEM_ERROR           = 2
128     CREATE_ERROR                = 3
129     LIFETIME_ERROR              = 4
130     LIFETIME_DYNPRO_DYNPRO_LINK = 5
131     others                      = 6
132     .
133
134 IF SY-SUBRC <> 0.
135 * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
136 *            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
137 ENDIF.
138
139 * 定义树对象
140   CREATE OBJECT WA_TREE
141     EXPORTING
142 *      LIFETIME                    =
143       PARENT                      = WA_CUSTOM_CONTAINER
144 *      SHELLSTYLE                  =
145       NODE_SELECTION_MODE         = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
146 *      HIDE_SELECTION              =
147 *      NAME                        =
148     EXCEPTIONS
149       LIFETIME_ERROR              = 1
150       CNTL_SYSTEM_ERROR           = 2
151       CREATE_ERROR                = 3
152       FAILED                      = 4
153       ILLEGAL_NODE_SELECTION_MODE = 5
154       others                      = 6
155       .
156   IF SY-SUBRC <> 0.
157 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
158 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
159   ENDIF.
160
161 * 通过宏定义树 节点
162 DEFINE  CREATE_TREE.
163
164   CLEAR IW_NODETABLE.
165
166   IW_NODETABLE-NODE_KEY = &1.         "节点KEY值
167   IW_NODETABLE-RELATKEY = &2.         "相关联的节点KEY值
168   IW_NODETABLE-RELATSHIP = &3.        "关联关系
169   IW_NODETABLE-HIDDEN = &4.
170   IW_NODETABLE-DISABLED = &5.
171   IW_NODETABLE-ISFOLDER = &6.         "文件夹形式
172 *  图标,可以运行程序 SHOWICON 查阅
173   IW_NODETABLE-N_IMAGE = &7.          "图标
174   IW_NODETABLE-EXP_IMAGE = &7.        "图标
175 *  IW_NODETABLE-EXPANDER.
176   IW_NODETABLE-TEXT = &8.             "节点文本
177
178   APPEND IW_NODETABLE TO IT_NODETABLE.
179
180 END-OF-DEFINITION.
181
182 CREATE_TREE ‘CN‘   ‘‘       ‘‘
183                                 ‘‘ ‘‘ ‘X‘ ‘‘ ‘中国‘.
184 CREATE_TREE ‘BEIJING‘ ‘CN‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘X‘ ‘‘ ‘北京‘.
185 CREATE_TREE ‘FENGTAI‘ ‘BEIJING‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘丰台区‘.
186 CREATE_TREE ‘HAIDIAN‘ ‘BEIJING‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘海淀区‘.
187 CREATE_TREE ‘CHAOYANG‘ ‘BEIJING‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘朝阳区‘.
188 CREATE_TREE ‘DONGCHENG‘ ‘BEIJING‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘东城区‘.
189
190 CREATE_TREE ‘SHENGHAI‘ ‘CN‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘X‘ ‘‘ ‘上海‘.
191 CREATE_TREE ‘QINGPU‘ ‘SHENGHAI‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘青浦区‘.
192 CREATE_TREE ‘HONGKOU‘ ‘SHENGHAI‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘虹口区‘.
193 CREATE_TREE ‘HUANGPU‘ ‘SHENGHAI‘ CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ‘‘ ‘‘ ‘‘ ‘@[email protected]‘ ‘黄浦区‘.
194
195 * 为TREE对象添加节点
196   CALL METHOD WA_TREE->ADD_NODES
197     EXPORTING
198       TABLE_STRUCTURE_NAME           = ‘MTREESNODE‘
199       NODE_TABLE                     =  IT_NODETABLE
200 *    EXCEPTIONS
201 *      ERROR_IN_IT_NODETABLE          = 1
202 *      FAILED                         = 2
203 *      DP_ERROR                       = 3
204 *      TABLE_STRUCTURE_NAME_NOT_FOUND = 4
205 *      others                         = 5
206           .
207   IF SY-SUBRC <> 0.
208 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
209 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
210   ENDIF.
211
212 *定义双击事件
213   EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
214   EVENT1-APPL_EVENT = ‘X‘.
215   APPEND EVENT1 TO EVENTS.
216
217 * 添加事件内表
218   CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
219     EXPORTING
220       EVENTS                    = EVENTS
221     EXCEPTIONS
222       CNTL_ERROR                = 1
223       CNTL_SYSTEM_ERROR         = 2
224       ILLEGAL_EVENT_COMBINATION = 3
225       others                    = 4
226           .
227   IF SY-SUBRC <> 0.
228 *   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
229 *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
230   ENDIF.
231 *  将已定义的双击事件分配到树对象
232   SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR WA_TREE.
233 ENDFORM.                    " FRM_CREATE_TREE
时间: 2024-12-28 11:34:54

实例:ABAP Tree Control 使用的相关文章

ABAP Tree Control的使用

Tree Control是最常用的Windows控件之一,在其他语言中,称为"Tree View"等,ABAP的Tree Control能完成相似的功能,本章主要介绍以下实例: (1)实现一个简单的Tree Control: (2)建立有数据表接口的Tree Control对象: (3)通过右键菜单完成Tree Control节点的增删修改等功能: (4)Tree Control对象与ALV Grid对象关联,实现在双击Tree节点时,变更ALV Grid的显示. 1.简单的Tree

ABAP table control例子

[转自]http://blog.csdn.net/lhx20/article/details/3039909Table control用于在screen上以表格的形式显示数据,在table control中,可以使用table elements,keywords,,templates,radio buttons,radio button groups和pushbuttons.一行可以有255个columns.每个column可以有一个title.Table control可以用来显示single

(八)树控件(Tree Control),标签控件(tab control)

树控件 基于对话框创建工程 // 01_TreeCtrlDlg.cpp : 实现文件 // #include "stdafx.h" #include "01_TreeCtrl.h" #include "01_TreeCtrlDlg.h" #include "afxdialogex.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg

ABAP实战屏幕SCREEN设计(二)

屏幕(SCREEN)是ABAP设计最重要的工作之一,SAP的单据.主数据维护等业务功能都使用屏幕,一个程序可以包含多个屏幕. 上一篇博文"ABAP实战屏幕SCREEN设计(一)"主要介绍了以下内容: (1)第一个"HELLO WORLD" Screen程序 (2)工具条和菜单设计 (3)屏幕对象 (4)数据字典关联字段 (5)逻辑流 (6)下拉框设计 本篇博文将继续介绍剩下内容,主要包含 (1)修改屏幕状态 (2)子窗口(Subscreen) (3)表条目控制 (4

ALV Tree

找相关的alv tree demo:se38 -> bcalv_tree* 1.创建对话屏幕 由于ALV没有专门实现的控件,需要先在对话屏幕100上增加一个用户自定义控件区域(Custom Control),名为CONTAINER1 2.demo源码 *&---------------------------------------------------------------------* *& Report YALV_TREE *&-------------------

ABAP的自学之路 ,初步认识ABAP &lt;一&gt;

由于工作的关系,最近需要对SAP系统进行二次开发,于是开始学习ABAP.鉴于网上对于ABAP的资料少之又少,所以自己整理一些资料. 第一章 ABAP 开发环境和总体介绍1.1 ABAP 开发环境ABAP 开发的三种环境:(1)SAP 正式系统环境:(2)SAP IDES 系统环境(学习环境):(3)MINISAP 环境.三种环境中均含有大量的例子程序,事务代码(TCODE):Abapdocu.三种环境都能够实现全部功能的 ABAP 开发(包括数据库编程).SAP 正式环境含有业务功能并能进行开发

[转]Oracle DB 管理ASM实例

? 描述使用ASM 的好处 ? 管理ASM 实例 ? 创建和删除ASM 磁盘组 ? 扩展ASM 磁盘组 ? 通过使用各种实用程序检索ASM 元数据 Automatic Storage Management Automatic Storage Management (ASM) 将文件系统与卷管理器纵向集成在一起,这是一项专门为Oracle DB 文件建立的技术.使用ASM 可管理单个对称多处理(SMP) 计算机,或通过管理集群的多个节点来支持Oracle Real Application Clus

10+ 最流行的 jQuery Tree 菜单插件

jstree – jQuery Tree Plugin With HTML & JSON Data jstree is a lightweight and flexible jQuery plugin to create tree menu from HTML & JSON data sources sources.This jQuery Plugin Support AJAX & async callback loading.It is absolutely free, open

System.Windows.Forms.Control : Component, IOleControl, IOleObject, IOleInPlaceObject, IOleInPlaceActiveObject....

#region 程序集 System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 // C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll #endregion using System.Collections; using System.ComponentModel; using Syst