ALV Tree

找相关的alv tree demo:se38 -> bcalv_tree*

1.创建对话屏幕

由于ALV没有专门实现的控件,需要先在对话屏幕100上增加一个用户自定义控件区域(Custom Control),名为CONTAINER1

2.demo源码

1*&---------------------------------------------------------------------* 2*& Report YALV_TREE 3*&---------------------------------------------------------------------* 4*& 5*&---------------------------------------------------------------------* 6REPORT yalv_tree. 7*&---------------------------------------------------------------------* 8*&数据对象定义 9*&---------------------------------------------------------------------* 10DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree, "树形ALV控制器引用变量 11 g_custom_container TYPE REF TO cl_gui_custom_container. "容器类引用变量 12 13DATA: gt_sflight TYPE sflight OCCURS 0, "Output-Table 14 gt_fieldcatalog TYPE lvc_t_fcat, 15 ok_code LIKE sy-ucomm, "获取100屏幕触发的功能码 16 save_ok LIKE sy-ucomm, "OK-Code 17 g_max TYPE i VALUE 255. "maximum of db records to select 18*&---------------------------------------------------------------------* 19*&事件接受类定义 20*&---------------------------------------------------------------------* 21CLASS lcl_tree_event_receiver DEFINITION. 22 23 PUBLIC SECTION. 24 "定义双击节点事件触发时的处理方法 25 METHODS handle_node_double_click 26 FOR EVENT node_double_click OF cl_gui_alv_tree 27 IMPORTING node_key sender. 28* 'sender' is an implicit event parameter that is provided by 29* ABAP Objects runtime system. It contains a reference to the 30* object that fired the event. You may directly use it to 31* call methods of this instance. 32 "其中SENDER这个参数是一个隐式的事件参数,是由ABAP对象运行系统提供,它指向了触发这个事件的实例,可以直接使用它来调用这个实例的方法。 33ENDCLASS. 34CLASS lcl_tree_event_receiver IMPLEMENTATION. 35*§3. Implement your event handler methods.定义处理方法的具体实施 36 37 METHOD handle_node_double_click. 38 DATA: lt_children TYPE lvc_t_nkey. 39*first check if the node is a leaf, i.e. can not be expanded 检查被点击的NODE几点下面有无子节点,有则展开节点。 40 41 CALL METHOD sender->get_children 42 EXPORTING 43 i_node_key = node_key 44 IMPORTING 45 et_children = lt_children. 46 47 IF NOT lt_children IS INITIAL. 48 49 CALL METHOD sender->expand_node 50 EXPORTING 51 i_node_key = node_key 52 i_level_count = 2. 53 ENDIF. 54 55 ENDMETHOD. 56 57ENDCLASS. 58 59START-OF-SELECTION. 60 61END-OF-SELECTION. 62 63 CALL SCREEN 100. 64*&---------------------------------------------------------------------* 65*& Module STATUS_0100 OUTPUT 66*&---------------------------------------------------------------------* 67*& 68*&---------------------------------------------------------------------* 69MODULE status_0100 OUTPUT. 70 SET PF-STATUS 'MAIN100'. 71 SET TITLEBAR 'TITLE'. 72 IF g_alv_tree IS INITIAL. 73 PERFORM init_tree. 74 75 CALL METHOD cl_gui_cfw=>flush 76 EXCEPTIONS 77 cntl_system_error = 1 78 cntl_error = 2. 79 IF sy-subrc NE 0. 80 CALL FUNCTION 'POPUP_TO_INFORM' 81 EXPORTING 82 titel = 'Automation Queue failure' 83 txt1 = 'Internal error:' 84 txt2 = 'A method in the automation queue' 85 txt3 = 'caused a failure.'. 86 ENDIF. 87 ENDIF. 88ENDMODULE. 89*&---------------------------------------------------------------------* 90*& Module USER_COMMAND_0100 INPUT 91*&---------------------------------------------------------------------* 92* text 93*----------------------------------------------------------------------* 94MODULE user_command_0100 INPUT. 95 save_ok = ok_code. 96 CLEAR ok_code. 97 98 CASE save_ok. 99 WHEN 'EXIT' OR 'BACK' OR 'CANC'. 100 "释放容器,退出程序 101 CALL METHOD g_custom_container->free. 102 LEAVE PROGRAM. 103 WHEN OTHERS. 104 "为正确调用工具栏按钮功能,必须调用该方法 105 CALL METHOD cl_gui_cfw=>dispatch. 106 107 ENDCASE. 108 109 CALL METHOD cl_gui_cfw=>flush. 110ENDMODULE. 111*&---------------------------------------------------------------------* 112*& Form INIT_TREE 113*&---------------------------------------------------------------------* 114*& text 115*&---------------------------------------------------------------------* 116*& --> p1 text 117*& <-- p2 text 118*&---------------------------------------------------------------------* 119FORM init_tree . 120* create container for alv-tree 121 DATA: l_tree_container_name(30) TYPE c. 122 123 l_tree_container_name = 'CONTAINER1'. 124 125 CREATE OBJECT g_custom_container 126 EXPORTING 127 container_name = l_tree_container_name 128 EXCEPTIONS 129 cntl_error = 1 130 cntl_system_error = 2 131 create_error = 3 132 lifetime_error = 4 133 lifetime_dynpro_dynpro_link = 5. 134 IF sy-subrc <> 0. 135 MESSAGE x208(00) WITH 'ERROR'(100). 136 ENDIF. 137 138* create tree control 实例化TREE控制器 139 CREATE OBJECT g_alv_tree 140 EXPORTING 141 parent = g_custom_container 142 node_selection_mode = cl_gui_column_tree=>node_sel_mode_single 143 item_selection = 'X' 144 no_html_header = 'X' 145 no_toolbar = '' 146 EXCEPTIONS 147 cntl_error = 1 148 cntl_system_error = 2 149 create_error = 3 150 lifetime_error = 4 151 illegal_node_selection_mode = 5 152 failed = 6 153 illegal_column_name = 7. 154 IF sy-subrc <> 0. 155 MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT 156 ENDIF. 157 158 DATA l_hierarchy_header TYPE treev_hhdr. 159 PERFORM build_hierarchy_header CHANGING l_hierarchy_header. 160 161* Hide columns and sum up values initially using the fieldcatalog 162*设置ALV字段 163 PERFORM build_fieldcatalog. 164 165* IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table 166* (even after this method call). You can change data of your table 167* by calling methods of CL_GUI_ALV_TREE. 168* Furthermore, the output table 'gt_outtab' must be global and can 169* only be used for one ALV Tree Control. 170 CALL METHOD g_alv_tree->set_table_for_first_display 171 EXPORTING 172 is_hierarchy_header = l_hierarchy_header 173 CHANGING 174 it_fieldcatalog = gt_fieldcatalog 175 it_outtab = gt_sflight. "table must be empty ! 此表必须一直为空,且为全局变量 176* 设置根节点,填充叶节点数据 177 PERFORM create_hierarchy. 178* 注册事件 179 PERFORM register_events. 180* Update calculations which were initially defined by field DO_SUM 181* of the fieldcatalog. (see build_fieldcatalog). 182* 更新汇总字段 183 CALL METHOD g_alv_tree->update_calculations. 184 185* Send data to frontend. 186* 前端显示数据 187 CALL METHOD g_alv_tree->frontend_update. 188ENDFORM. 189*&---------------------------------------------------------------------* 190*& Form build_hierarchy_header 191*&---------------------------------------------------------------------* 192* build hierarchy-header-information 193*----------------------------------------------------------------------* 194* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header 195*----------------------------------------------------------------------* 196FORM build_hierarchy_header CHANGING 197 p_hierarchy_header TYPE treev_hhdr. 198 199 p_hierarchy_header-heading = 'Totals/Month/Carrier/Date'(300). 200 p_hierarchy_header-tooltip = 'Flights in a month'(400). 201 p_hierarchy_header-width = 35. 202 p_hierarchy_header-width_pix = ''. 203 204ENDFORM. 205*&---------------------------------------------------------------------* 206*& Form build_fieldcatalog 207*&---------------------------------------------------------------------* 208*& text 209*&---------------------------------------------------------------------* 210*& --> P_ 211*& --> P_ 212*&---------------------------------------------------------------------* 213FORM build_fieldcatalog. 214 DATA: ls_fieldcatalog TYPE lvc_s_fcat. 215 216* The following function module generates a fieldcatalog according 217* to a given structure. 218 CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' 219 EXPORTING 220 i_structure_name = 'SFLIGHT' 221 CHANGING 222 ct_fieldcat = gt_fieldcatalog. 223 224* Now change the fieldcatalog to hide fields and to determine 225* some initial calculations for chosen fields. 226 LOOP AT gt_fieldcatalog INTO ls_fieldcatalog. 227 CASE ls_fieldcatalog-fieldname. 228* hide columns which are already displayed in our tree 229 WHEN 'CARRID' OR 'FLDATE'. 230 ls_fieldcatalog-no_out = 'X'. 231* Do some initial calculations: 232* ALV Tree uses the field 'do_sum' to declare that a function 233* for the corresponding column shall be calculated. 234* Use 'h_ftype' to set the function type (MAX, MIN, SUM, AVG). 235 WHEN 'PRICE'. 236 ls_fieldcatalog-do_sum = 'X'. 237 ls_fieldcatalog-h_ftype = 'MAX'. 238 WHEN 'SEATSMAX'. 239 ls_fieldcatalog-do_sum = 'X'. 240 ls_fieldcatalog-h_ftype = 'SUM'. 241 WHEN 'SEATSOCC'. 242 ls_fieldcatalog-do_sum = 'X'. 243 ls_fieldcatalog-h_ftype = 'AVG'. 244 ENDCASE. 245 MODIFY gt_fieldcatalog FROM ls_fieldcatalog. 246 ENDLOOP. 247 248* The fieldcatalog is provided in form 'init_tree' using method 249* set_table_for_first_display. 250ENDFORM. " build_fieldcatalog 251*&---------------------------------------------------------------------* 252*& Form CREATE_HIERARCHY 253*&---------------------------------------------------------------------* 254*& text 255*&---------------------------------------------------------------------* 256*& --> p1 text 257*& <-- p2 text 258*&---------------------------------------------------------------------* 259FORM create_hierarchy . 260* See BCALV_TREE_01 for more comments on building the hierarchy 261 DATA: ls_sflight TYPE sflight, 262 lt_sflight TYPE sflight OCCURS 0, 263 l_yyyymm(6) TYPE c, "year and month of sflight-fldate 264 l_yyyymm_last(6) TYPE c, 265 l_carrid LIKE sflight-carrid, 266 l_carrid_last LIKE sflight-carrid. 267 268 DATA: l_month_key TYPE lvc_nkey, 269 l_carrid_key TYPE lvc_nkey, 270 l_last_key TYPE lvc_nkey, 271 l_top_key TYPE lvc_nkey. 272 273* Select data 274 SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS. 275* sort table according to conceived hierarchy 276 SORT lt_sflight BY fldate+0(6) carrid fldate+6(2). 277 278* Define one top node. In this way it is possible to calculate 279* values for the whole hierarchy.添加主节点 280 CALL METHOD g_alv_tree->add_node 281 EXPORTING 282 i_relat_node_key = '' 283 i_relationship = cl_gui_column_tree=>relat_last_child 284 i_node_text = TEXT-050 285 IMPORTING 286 e_new_node_key = l_top_key. 287 288 LOOP AT lt_sflight INTO ls_sflight. 289 l_yyyymm = ls_sflight-fldate+0(6). 290 l_carrid = ls_sflight-carrid. 291 292 IF l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm 293 l_yyyymm_last = l_yyyymm. 294* month nodes 295 PERFORM add_month USING l_yyyymm 296 l_top_key 297 CHANGING l_month_key. 298* clear l_carrid_last because this is a new month 299 CLEAR l_carrid_last. 300 ENDIF. 301* Carrier nodes: 302 IF l_carrid <> l_carrid_last. "on change of l_carrid 303 l_carrid_last = l_carrid. 304 PERFORM add_carrid_line USING ls_sflight 305 l_month_key 306 CHANGING l_carrid_key. 307 ENDIF. 308* Leaf: 309 PERFORM add_complete_line USING ls_sflight 310 l_carrid_key 311 CHANGING l_last_key. 312 ENDLOOP. 313 314ENDFORM. 315*&---------------------------------------------------------------------* 316*& Form REGISTER_EVENTS 317*&---------------------------------------------------------------------* 318*& text 319*&---------------------------------------------------------------------* 320*& --> p1 text 321*& <-- p2 text 322*&---------------------------------------------------------------------* 323FORM register_events . 324 "注册前端后后端事件 325 DATA: lt_events TYPE cntl_simple_events, 326 l_event TYPE cntl_simple_event, 327 l_event_receiver TYPE REF TO lcl_tree_event_receiver. 328 329*1。获取已注册的前端事件 330 CALL METHOD g_alv_tree->get_registered_events 331 IMPORTING 332 events = lt_events. 333 "2.添加前端双击时间 334 l_event-eventid = cl_gui_column_tree=>eventid_node_double_click. 335 APPEND l_event TO lt_events. 336 337*3.重新设置前端注册时间 338 CALL METHOD g_alv_tree->set_registered_events 339 EXPORTING 340 events = lt_events 341 EXCEPTIONS 342 cntl_error = 1 343 cntl_system_error = 2 344 illegal_event_combination = 3. 345 IF sy-subrc <> 0. 346 MESSAGE e208(00) WITH '注册前端事件失败!'. "#EC NOTEXT 347 ENDIF. 348*-------------------- 349 "4.注册后端事件 350 CREATE OBJECT l_event_receiver. 351 SET HANDLER l_event_receiver->handle_node_double_click FOR g_alv_tree. 352ENDFORM. 353FORM add_carrid_line USING ps_sflight TYPE sflight 354 p_relat_key TYPE lvc_nkey 355 CHANGING p_node_key TYPE lvc_nkey. 356 357 DATA: l_node_text TYPE lvc_value, 358 ls_sflight TYPE sflight. 359 360* add node 361 l_node_text = ps_sflight-carrid. 362 CALL METHOD g_alv_tree->add_node 363 EXPORTING 364 i_relat_node_key = p_relat_key 365 i_relationship = cl_gui_column_tree=>relat_last_child 366 i_node_text = l_node_text 367 is_outtab_line = ls_sflight 368 IMPORTING 369 e_new_node_key = p_node_key. 370 371ENDFORM. " add_carrid_line 372*&---------------------------------------------------------------------* 373*& Form add_complete_line 374*&---------------------------------------------------------------------* 375FORM add_complete_line USING ps_sflight TYPE sflight 376 p_relat_key TYPE lvc_nkey 377 CHANGING p_node_key TYPE lvc_nkey. 378 379 DATA: l_node_text TYPE lvc_value. 380 381 WRITE ps_sflight-fldate TO l_node_text MM/DD/YYYY. 382 383 CALL METHOD g_alv_tree->add_node 384 EXPORTING 385 i_relat_node_key = p_relat_key 386 i_relationship = cl_gui_column_tree=>relat_last_child 387 is_outtab_line = ps_sflight 388 i_node_text = l_node_text 389 IMPORTING 390 e_new_node_key = p_node_key. 391 392ENDFORM. " add_complete_line 393*&---------------------------------------------------------------------* 394*& Form GET_MONTH 395*&---------------------------------------------------------------------* 396* text 397*----------------------------------------------------------------------* 398* -->P_P_YYYYMM text 399* <--P_L_MONTH text 400*----------------------------------------------------------------------* 401FORM get_month USING p_yyyymm 402 CHANGING p_month. 403 404 DATA: l_monthdigits(2) TYPE c. 405 406 l_monthdigits = p_yyyymm+4(2). 407 CASE l_monthdigits. 408 WHEN '01'. 409 p_month = 'January'(701). 410 WHEN '02'. 411 p_month = 'February'(702). 412 WHEN '03'. 413 p_month = 'March'(703). 414 WHEN '04'. 415 p_month = 'April'(704). 416 WHEN '05'. 417 p_month = 'May'(705). 418 WHEN '06'. 419 p_month = 'June'(706). 420 WHEN '07'. 421 p_month = 'July'(707). 422 WHEN '08'. 423 p_month = 'August'(708). 424 WHEN '09'. 425 p_month = 'September'(709). 426 WHEN '10'. 427 p_month = 'October'(710). 428 WHEN '11'. 429 p_month = 'November'(711). 430 WHEN '12'. 431 p_month = 'December'(712). 432 ENDCASE. 433 CONCATENATE p_yyyymm+0(4) '->' p_month INTO p_month. 434 435ENDFORM. " GET_MONTH 436*&---------------------------------------------------------------------* 437*& Form add_month 438*&---------------------------------------------------------------------* 439FORM add_month USING p_yyyymm TYPE c 440 p_relat_key TYPE lvc_nkey 441 CHANGING p_node_key TYPE lvc_nkey. 442 443 DATA: l_node_text TYPE lvc_value, 444 ls_sflight TYPE sflight, 445 l_month(15) TYPE c. "output string for month 446 447* get month name for node text 448 PERFORM get_month USING p_yyyymm 449 CHANGING l_month. 450 l_node_text = l_month. 451 452* add node 453 CALL METHOD g_alv_tree->add_node 454 EXPORTING 455 i_relat_node_key = p_relat_key 456 i_relationship = cl_gui_column_tree=>relat_last_child 457 i_node_text = l_node_text 458 is_outtab_line = ls_sflight 459 IMPORTING 460 e_new_node_key = p_node_key. 461 462ENDFORM. " add_month

3.运行结果

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )