通过配置生成一个树形菜单,并提供单击项目时打开项目对应的程序,功能上类似于SAP标准的区域菜单功能,只是菜单的项目可通过自定配置表配置。
1.SAP标准区域菜单:WEDI
2.自定义树形管理菜单
3.配置表
3.1.ZTFI_069
MANDT MANDT CLNT 3 0 集团
ZLEVL ZELEVEL CHAR 1 0 平台层级
NODKY ZENODKY CHAR 2 0 平台节点
RTKEY ZERTKEY CHAR 2 0 平台父节点
PGMNA PROGRAMM CHAR 40 0 ABAP 程序名称
TCODE TCODE CHAR 20 0 事务代码
3.2.ZTFI_069_01
MANDT MANDT CLNT 3 0 集团
NODKY ZENODKY CHAR 2 0 平台节点
SPRAS SPRAS LANG 1 0 语言代码
NODKT P_99S_CLUSTER_NODE_TEXT CHAR 40 0 节点描述
3.3.程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
REPORT ZFID_001. *----------------------------------------------------------------------* * 类型池定义 *----------------------------------------------------------------------* *----------------------------------------------------------------------* * 数据库表声明 *----------------------------------------------------------------------* *----------------------------------------------------------------------* * 声明类型 *----------------------------------------------------------------------* TYPES:TY_NODE_TABLE TYPE STANDARD TABLE OF MTREESNODE WITH DEFAULT KEY. TYPES:BEGIN OF TY_NODE, ZLEVL TYPE CHAR1, NODKY TYPE CHAR12, RTKEY TYPE CHAR12, PGMNA TYPE CHAR40, TCODE TYPE TCODE, NODKT TYPE CHAR40, END OF TY_NODE. *----------------------------------------------------------------------* * 变量 常量 定义 *----------------------------------------------------------------------* DATA: GCL_CLS TYPE REF TO ZCL_CM_GUI_ALV, "汇票类 GCL_TREE TYPE REF TO CL_GUI_SIMPLE_TREE, GT_EVENT TYPE CNTL_SIMPLE_EVENTS, GS_EVENT TYPE CNTL_SIMPLE_EVENT, GT_NODE_TABLE TYPE TY_NODE_TABLE, OK_CODE TYPE SY-UCOMM, SAVE_OK TYPE SY-UCOMM, GT_NODE_DATA TYPE TABLE OF TY_NODE. CREATE OBJECT GCL_CLS. *&---------------------------------------------------------------------* *& Selection Screen/选择屏幕 *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& INITIALIZATION/选择屏幕前初始化 * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& at selection-screen output/选择屏幕开始 * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Start-of-selection/开始选择屏幕 * *&---------------------------------------------------------------------* START-OF-SELECTION. *---调用屏幕 PERFORM FRM_CALL_SCREEN. *&---------------------------------------------------------------------* *& end-of-selection/结束选择屏幕(程序结束处理,输出等) * *&---------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Form FRM_CALL_SCREEN *&---------------------------------------------------------------------* *& Call screen *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_CALL_SCREEN . CALL SCREEN 9000. ENDFORM. *&---------------------------------------------------------------------* *& Module STATUS_9000 OUTPUT *&---------------------------------------------------------------------* *& 屏幕状态栏 *&---------------------------------------------------------------------* MODULE STATUS_9000 OUTPUT. SET PF-STATUS 'STAT9000'. SET TITLEBAR 'TIT9000'. ENDMODULE. *&---------------------------------------------------------------------* *& Module USER_COMMAND_9000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_9000 INPUT. PERFORM FRM_USER_COMMAND. ENDMODULE. *&---------------------------------------------------------------------* *& Form FRM_USER_COMMAND *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_USER_COMMAND . CLEAR:SAVE_OK. SAVE_OK = OK_CODE. CLEAR OK_CODE. CASE SAVE_OK. WHEN 'BACK'. LEAVE TO SCREEN 0. WHEN OTHERS. ENDCASE. ENDFORM. *&---------------------------------------------------------------------* *& Module MOD_OUT_TREE OUTPUT *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* MODULE MOD_OUT_TREE OUTPUT. *---从配置表获取平台节点 PERFORM FRM_GET_TREE_NODE . *---处理屏幕容器 IF GT_NODE_DATA IS NOT INITIAL. PERFORM FRM_PROCESS_CONTANER. ELSE. MESSAGE TEXT-001 TYPE 'E'. ENDIF. ENDMODULE. *&---------------------------------------------------------------------* *& Form FRM_GET_TREE_NODE *&---------------------------------------------------------------------* *& 获取 tree 节点 *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_GET_TREE_NODE . *----获取Tree 节点数据 CLEAR GT_NODE_DATA. SELECT A~ZLEVL A~NODKY A~RTKEY A~PGMNA A~TCODE B~NODKT INTO TABLE GT_NODE_DATA FROM ZTFI_069 AS A INNER JOIN ZTFI_069_01 AS B ON A~NODKY = B~NODKY WHERE B~SPRAS = SY-LANGU. SORT GT_NODE_DATA BY ZLEVL NODKY. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_PROCESS_CONTANER *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_PROCESS_CONTANER . IF GCL_TREE IS INITIAL. *----创建容器 TRY. GCL_CLS->CREATE_SIMPLE_TREE( EXPORTING IO_CONTAINER = 'TREE' CHANGING IO_TREE = GCL_TREE ). CATCH CX_SY_REF_IS_INITIAL INTO DATA(LC_ERROR). DATA(LV_ERROR) = LC_ERROR->IF_MESSAGE~GET_TEXT( ). ENDTRY. *----注册事件 *---类属性赋值 GCL_CLS->REPID = SY-REPID. GCL_CLS->NODE_DOUBLE_CLICK = 'FRM_HANDLE_NODE_DOUBLE_CLICK'. CLEAR:GT_EVENT, GS_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 GCL_TREE->SET_REGISTERED_EVENTS EXPORTING EVENTS = GT_EVENT EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 ILLEGAL_EVENT_COMBINATION = 3. SET HANDLER GCL_CLS->HANDLE_NODE_DOUBLE_CLICK FOR GCL_TREE. "SET HANDLER GCL_CLS->HANDLE_EXPAND_NO_CHILDREN FOR GCL_TREE. PERFORM FRM_ADD_TREE_NODE. ELSE. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_ADD_TREE_NODE *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_ADD_TREE_NODE . DATA:LV_NODKEY TYPE TV_NODEKEY. TYPES TY_MTREESNODE TYPE STANDARD TABLE OF MTREESNODE WITH EMPTY KEY. DATA: LT_NODE TYPE TY_MTREESNODE. * LS_NODE TYPE MTREESNODE. DATA(LT_LINE) = GT_NODE_DATA. SORT LT_LINE BY ZLEVL DESCENDING. *----最大层级 IF LT_LINE IS NOT INITIAL. READ TABLE LT_LINE INTO DATA(LS_LINE) INDEX 1. IF SY-SUBRC EQ 0. DATA(LV_LEVL) = LS_LINE-ZLEVL. ENDIF. ENDIF. LOOP AT GT_NODE_DATA INTO DATA(LS_NODE_DATA). * IF LS_NODE_DATA-ZLEVL NE 0. AUTHORITY-CHECK OBJECT 'ZBOE02' ID 'ZNODKY' FIELD LS_NODE_DATA-NODKY. IF SY-SUBRC EQ 0. DATA(LV_DISP) = 'X'. ENDIF. ENDIF. IF LS_NODE_DATA-ZLEVL = 0 OR LV_DISP = 'X'. LT_NODE = VALUE #( BASE LT_NODE ( NODE_KEY = LS_NODE_DATA-NODKY RELATKEY = COND #( LET T = '0' IN WHEN T <> LS_NODE_DATA-NODKY THEN LS_NODE_DATA-RTKEY ) EXPANDER = COND #( LET T = LV_LEVL IN WHEN T <> LS_NODE_DATA-ZLEVL THEN ABAP_TRUE ) RELATSHIP = COND #( LET T = LV_LEVL IN WHEN T = LS_NODE_DATA-ZLEVL THEN CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD ) TEXT = LS_NODE_DATA-NODKT ) ). ENDIF. CLEAR LV_DISP. ENDLOOP. IF GCL_TREE IS NOT INITIAL. TRY. CALL METHOD GCL_TREE->ADD_NODES EXPORTING TABLE_STRUCTURE_NAME = 'MTREESNODE' NODE_TABLE = LT_NODE[] EXCEPTIONS FAILED = 1 ERROR_IN_NODE_TABLE = 2 DP_ERROR = 3 TABLE_STRUCTURE_NAME_NOT_FOUND = 4 OTHERS = 5. IF SY-SUBRC <> 0. ENDIF. CATCH CX_ROOT INTO DATA(LC_ERROR). DATA(LV_ERROR) = LC_ERROR->IF_MESSAGE~GET_TEXT( ). ENDTRY. IF LV_ERROR IS INITIAL. *--默认转开顶层 READ TABLE GT_NODE_DATA INTO DATA(LS_NODEKEY) WITH KEY ZLEVL = 0. IF SY-SUBRC EQ 0. LV_NODKEY = LS_NODEKEY-NODKY. CALL METHOD GCL_TREE->EXPAND_NODE EXPORTING NODE_KEY = LV_NODKEY. ENDIF. ENDIF. ENDIF. ENDFORM. *&---------------------------------------------------------------------* *& Form FRM_HANDLE_NODE_DOUBLE_CLICK *&---------------------------------------------------------------------* *& text *&---------------------------------------------------------------------* *& --> p1 text *& <-- p2 text *&---------------------------------------------------------------------* FORM FRM_HANDLE_NODE_DOUBLE_CLICK USING NODE_KEY. *---根据节点获取要跳转的程序 READ TABLE GT_NODE_DATA INTO DATA(LS_NODE) WITH KEY NODKY = NODE_KEY. IF SY-SUBRC EQ 0. AUTHORITY-CHECK OBJECT 'ZBOE03' ID 'ZNODKY' FIELD LS_NODE-NODKY. IF SY-SUBRC NE 0. MESSAGE E076(ZMFIF01). ELSE. IF LS_NODE-PGMNA IS NOT INITIAL. SUBMIT (LS_NODE-PGMNA) VIA SELECTION-SCREEN AND RETURN. ELSE. MESSAGE TEXT-002 TYPE 'I'. ENDIF. ENDIF. ENDIF. ENDFORM. |
3.4.GUI 状态
创建GUI状态:STAT9000
创建GUI标题:TIT9000