ALV Tree demo(WBS元素分层显示)[引用别人的]

原文地址:http://www.xuebuyuan.com/1666753.html

按层次显示WBS编码及描述,附加节点双击展开事件和Item双击跳转CJ03功能。

因为本人懒,本例代码都是从标准的BCALV_TREE_01和BCALV_TREE_02拷贝过来修改的,结构不好请别见怪。

REPORT  zmac_alvtree_test.

DATA: g_alv_tree         TYPE REF TO cl_gui_alv_tree,
      g_custom_container TYPE REF TO cl_gui_custom_container.

TYPES: BEGIN OF ty_wbs,
        posid  TYPE prps-posid,
        post1  TYPE prps-post1,
        stufe  TYPE prps-stufe,
       END OF ty_wbs.

DATA: gt_wbs TYPE STANDARD TABLE OF ty_wbs,
      gs_wbs TYPE ty_wbs.

DATA: ok_code LIKE sy-ucomm,
      save_ok LIKE sy-ucomm,           "OK-Code
      g_max TYPE i VALUE 255.

DATA: gt_fcat  TYPE  lvc_t_fcat,
      gs_fcat  TYPE  lvc_s_fcat.

*----------------------------------------------------------------------*
*       CLASS lcl_tree_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_tree_event_receiver DEFINITION.

  PUBLIC SECTION.
    METHODS handle_node_double_click
      FOR EVENT node_double_click OF cl_gui_alv_tree
      IMPORTING node_key sender.
    METHODS handle_item_double_click
      FOR EVENT item_double_click OF cl_gui_alv_tree
      IMPORTING fieldname node_key.
ENDCLASS.                    "lcl_tree_event_receiver DEFINITION
******************************************************************
CLASS lcl_tree_event_receiver IMPLEMENTATION.

  METHOD handle_node_double_click.
    DATA: lt_children TYPE lvc_t_nkey.

    CALL METHOD sender->get_children
      EXPORTING
        i_node_key  = node_key
      IMPORTING
        et_children = lt_children.

    IF NOT lt_children IS INITIAL.

      CALL METHOD sender->expand_node
        EXPORTING
          i_node_key    = node_key
          i_level_count = 2.
    ENDIF.

  ENDMETHOD.                    "handle_node_double_click

  METHOD handle_item_double_click.
    DATA: l_value TYPE lvc_value,
          l_layi  TYPE lvc_t_layi,
          l_layn  TYPE lvc_s_layn .

    CALL METHOD g_alv_tree->get_outtab_line
      EXPORTING
        i_node_key     = node_key
      IMPORTING
        e_outtab_line  = gs_wbs
        e_node_text    = l_value
        et_item_layout = l_layi
        es_node_layout = l_layn
      EXCEPTIONS
        node_not_found = 1
        OTHERS         = 2.
    IF sy-subrc = 0.
      SET PARAMETER ID ‘PRO‘ FIELD gs_wbs-posid.
      CALL TRANSACTION ‘CJ03‘ AND SKIP FIRST SCREEN.
    ENDIF.

  ENDMETHOD.                    "handle_item_double_click

ENDCLASS.                    "lcl_tree_event_receiver IMPLEMENTATION

END-OF-SELECTION.

  CALL SCREEN 100.

*&---------------------------------------------------------------------*
*&      Module  PBO  OUTPUT
*&---------------------------------------------------------------------*
*       process before output
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.

  SET PF-STATUS ‘MAIN100‘.
  SET TITLEBAR ‘MAINTITLE‘.

  IF g_alv_tree IS INITIAL.
    PERFORM init_tree.

    CALL METHOD cl_gui_cfw=>flush
      EXCEPTIONS
        cntl_system_error = 1
        cntl_error        = 2.
    IF sy-subrc NE 0.
      CALL FUNCTION ‘POPUP_TO_INFORM‘
        EXPORTING
          titel = ‘Automation Queue failure‘(801)
          txt1  = ‘Internal error:‘(802)
          txt2  = ‘A method in the automation queue‘(803)
          txt3  = ‘caused a failure.‘(804).
    ENDIF.
  ENDIF.

ENDMODULE.                             " PBO  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  PAI  INPUT
*&---------------------------------------------------------------------*
*       process after input
*----------------------------------------------------------------------*
MODULE pai INPUT.
  save_ok = ok_code.
  CLEAR ok_code.

  CASE save_ok.
    WHEN ‘EXIT‘ OR ‘BACK‘ OR ‘CANC‘.
      PERFORM exit_program.

    WHEN OTHERS.
      CALL METHOD cl_gui_cfw=>dispatch.

  ENDCASE.

  CALL METHOD cl_gui_cfw=>flush.
ENDMODULE.                             " PAI  INPUT

*&---------------------------------------------------------------------*
*&      Form  init_tree
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM init_tree.

  DATA: l_tree_container_name(30) TYPE c.

  l_tree_container_name = ‘CCONTAINER1‘.

  CREATE OBJECT g_custom_container
    EXPORTING
      container_name              = l_tree_container_name
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      lifetime_dynpro_dynpro_link = 5.
  IF sy-subrc <> 0.
    MESSAGE x208(00) WITH ‘ERROR‘(100).
  ENDIF.

* create tree control
  CREATE OBJECT g_alv_tree
    EXPORTING
      parent                      = g_custom_container
      node_selection_mode         = cl_gui_column_tree=>node_sel_mode_single
      item_selection              = ‘X‘
      no_html_header              = ‘X‘
      no_toolbar                  = ‘‘
    EXCEPTIONS
      cntl_error                  = 1
      cntl_system_error           = 2
      create_error                = 3
      lifetime_error              = 4
      illegal_node_selection_mode = 5
      failed                      = 6
      illegal_column_name         = 7.
  IF sy-subrc <> 0.
    MESSAGE x208(00) WITH ‘ERROR‘.                          "#EC NOTEXT
  ENDIF.

  DATA l_hierarchy_header TYPE treev_hhdr.
  PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
  PERFORM build_fieldcategory.

  CALL METHOD g_alv_tree->set_table_for_first_display
    EXPORTING
      is_hierarchy_header = l_hierarchy_header
    CHANGING
      it_outtab           = gt_wbs   "table must be empty !
      it_fieldcatalog     = gt_fcat.

  PERFORM create_hierarchy.
  PERFORM register_events.

  CALL METHOD g_alv_tree->frontend_update.

ENDFORM.                               " init_tree
*&---------------------------------------------------------------------*
*&      Form  build_hierarchy_header
*&---------------------------------------------------------------------*
*       build hierarchy-header-information
*----------------------------------------------------------------------*
*      -->P_L_HIERARCHY_HEADER  strucxture for hierarchy-header
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING
                               p_hierarchy_header TYPE treev_hhdr.

  p_hierarchy_header-heading = ‘Wbs number‘(300).
  p_hierarchy_header-tooltip = ‘WBS‘(400).
  p_hierarchy_header-width = 50.
  p_hierarchy_header-width_pix = ‘ ‘.

ENDFORM.                               " build_hierarchy_header
*&---------------------------------------------------------------------*
*&      Form  exit_program
*&---------------------------------------------------------------------*
*       free object and leave program
*----------------------------------------------------------------------*
FORM exit_program.

  CALL METHOD g_custom_container->free.
  LEAVE PROGRAM.

ENDFORM.                               " exit_program
*&---------------------------------------------------------------------*
*&      Form  create_hierarchy
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM create_hierarchy.

  DATA: ls_wbs TYPE ty_wbs,
        lt_wbs TYPE ty_wbs OCCURS 0.

  DATA: lt_nodes TYPE TABLE OF lvc_nkey WITH HEADER LINE,
        l_cur_node TYPE lvc_nkey,
        l_former_stufe TYPE prps-stufe,
        l_index  TYPE i.

  SELECT posid post1 stufe FROM prps INTO TABLE lt_wbs UP TO 200 ROWS.

  SORT lt_wbs BY posid.

  LOOP AT lt_wbs INTO ls_wbs.

    IF ls_wbs-stufe = ‘1‘.
      REFRESH lt_nodes.
      l_index = ls_wbs-stufe.
      PERFORM add_nodes USING    ls_wbs
                                 ‘‘
                        CHANGING l_cur_node.
      READ TABLE lt_nodes INDEX l_index.
      IF sy-subrc NE 0.
        APPEND l_cur_node TO lt_nodes.
      ENDIF.

    ELSEIF ls_wbs-stufe > l_former_stufe.      "on change of l_yyyymm
      l_index = ls_wbs-stufe - 1.
      READ TABLE lt_nodes INDEX l_index.

      PERFORM add_nodes USING    ls_wbs
                                 lt_nodes
                        CHANGING l_cur_node.
*---->保存新的当前节点
      APPEND l_cur_node TO lt_nodes.
    ELSEIF ls_wbs-stufe < l_former_stufe.
      l_index = ls_wbs-stufe - 1.
      READ TABLE lt_nodes INDEX l_index.

      PERFORM add_nodes USING    ls_wbs
                                 lt_nodes
                        CHANGING l_cur_node.
*---->将当前节点及之后后的所有临时存储节点KEY删除
      l_index = l_index + 1.
      DELETE lt_nodes INDEX l_index.
      DO.
        READ TABLE lt_nodes INDEX l_index.
        IF sy-subrc = 0.
          DELETE lt_nodes INDEX l_index.
        ELSE.
          EXIT.
        ENDIF.
      ENDDO.
*---->保存新的当前节点
      APPEND l_cur_node TO lt_nodes.
    ELSE.
      l_index = ls_wbs-stufe - 1.
      READ TABLE lt_nodes INDEX l_index.
      PERFORM add_nodes USING    ls_wbs
                                 lt_nodes
                        CHANGING l_cur_node.
    ENDIF.
    l_former_stufe = ls_wbs-stufe.
  ENDLOOP.

ENDFORM.                               " create_hierarchy
*&---------------------------------------------------------------------*
*&      Form  add_nodes
*&---------------------------------------------------------------------*
FORM add_nodes  USING     ps_wbs TYPE ty_wbs
                          p_cnode_key TYPE lvc_nkey
                CHANGING  p_nnode_key TYPE lvc_nkey.

  DATA: l_node_text TYPE lvc_value.

  CALL FUNCTION ‘CONVERSION_EXIT_ABPSN_OUTPUT‘
    EXPORTING
      input  = ps_wbs-posid
    IMPORTING
      output = l_node_text.

  CALL METHOD g_alv_tree->add_node
    EXPORTING
      i_relat_node_key = p_cnode_key
      i_relationship   = cl_gui_column_tree=>relat_last_child
      i_node_text      = l_node_text
      is_outtab_line   = ps_wbs
    IMPORTING
      e_new_node_key   = p_nnode_key.

ENDFORM.                               " add_month
*&---------------------------------------------------------------------*
*&      Form  build_fieldcategory
*&---------------------------------------------------------------------*
FORM build_fieldcategory .
*  gs_fcat-fieldname      =  ‘POSID‘.
*  gs_fcat-seltext        =  text-f06.    " 字段输出名称
*  gs_fcat-coltext        =  text-f06.    " 字段输出名称
*  gs_fcat-just           =  ‘L‘.
*  gs_fcat-outputlen      =  ‘40‘.        " 输出长度
*  APPEND gs_fcat TO gt_fcat.
*  CLEAR  gs_fcat.
  gs_fcat-fieldname      =  ‘POST1‘.
  gs_fcat-seltext        =  text-f01.    " 字段输出名称
  gs_fcat-coltext        =  text-f01.    " 字段输出名称
  gs_fcat-just           =  ‘L‘.
  gs_fcat-outputlen      =  ‘40‘.        " 输出长度
  APPEND gs_fcat TO gt_fcat.
  CLEAR  gs_fcat.
ENDFORM.                    " build_fieldcategory
*&---------------------------------------------------------------------*
*&      Form  register_events
*&---------------------------------------------------------------------*
FORM register_events .
  DATA: lt_events TYPE cntl_simple_events,
        l_event TYPE cntl_simple_event,
        l_event_receiver TYPE REF TO lcl_tree_event_receiver.

  CALL METHOD g_alv_tree->get_registered_events
    IMPORTING
      events = lt_events.

  l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
  APPEND l_event TO lt_events.
  l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
  APPEND l_event TO lt_events.

  CALL METHOD g_alv_tree->set_registered_events
    EXPORTING
      events                    = lt_events
    EXCEPTIONS
      cntl_error                = 1
      cntl_system_error         = 2
      illegal_event_combination = 3.
  IF sy-subrc <> 0.
    MESSAGE x208(00) WITH ‘ERROR‘.                          "#EC NOTEXT
  ENDIF.

  CREATE OBJECT l_event_receiver.
  SET HANDLER l_event_receiver->handle_node_double_click FOR g_alv_tree.
  SET HANDLER l_event_receiver->handle_item_double_click FOR g_alv_tree.

ENDFORM.                    " register_events
时间: 2024-11-02 20:14:51

ALV Tree demo(WBS元素分层显示)[引用别人的]的相关文章

ALV Tree

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

OO方式下,ALV TREE和ALV GRID的不同之处

ALV TREE和ALV GRID的实现整体上是相似的,但也有一些不同之处,现总结如下 首先定义概念:文中的ALV GRID指的是由OO方式建立的.由类cl_gui_alv_grid实例化后产生的ALV GRID,而ALV TREE指的是由类cl_gui_alv_tree实例化后产生的ALV TREE 1,输出内容的构建方式 ALV GRID的输出数据是通过直接将查询结果内表作为参数传递到ALV GRID对象的 set_table_for_first_display方法而显示的.   在ALV

创建list ALV tree[RS_TREE_LIST_DISPLAY]

ABAP程序中的ALV显示是很常用的一种数据展示手段,除了常规的alv,有时也会用到ALV tree这种有层次结构的展示方式更好的展现数据,下面介绍一个创建list alv tree的方法: 1)用函数RS_TREE_CONSTRUCT构造alv 树的层次结构, alv tree的节点类型(node type)分两种:T和P,区别如下:区别就是个文件夹的图标. 2)调用函数RS_TREE_LIST_DISPLAY显示alv tree 完整代码: 用list alv tree来显示采购订单和采购订

jQuery判断元素是否显示与隐藏

jQuery判断一个元素是显示还是隐藏,jQuery使用is()方法来判断一个元素是否显示,反之则为隐藏 核心代码 if($("#username").is(":hidden")){ } 实例代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>test.html</ti

js实例_当鼠标移动到某个元素上时在元素下面显示一段提示文字

效果: 当鼠标不在自动登录上时,只显示自动登录这个表单,下面的div提示则隐藏. 当鼠标移动到自动登录这个表单时,则显示下面的div提示,当鼠标移出时再将其隐藏 代码实现与原理: HTML代码: <body> <input type="checkbox" />自动登录 <div id="div1">不要再玩游戏啦!!!</div> </body> CSS代码:给id为div1的元素做一下修饰,并且将其最开始

使块元素并排显示和清除浮动的方法

使多个块元素并排显示: ①inline-block:内敛块,不占一行,但可以设置宽高属性,将块元素的display设置为inline-block,可以让多个div块横向显示.但是该用法下多个块之间会出现空格,是由于相邻两个</div>与<div>之间的换行符引起的,空格的清除办法: ①去掉换行符(不推荐):页面不美观 ②注释(不推荐):将换行部分注释掉 ③将上一行的>移到下一行(不推荐):页面不美观 ④将要并排显示的div添加父元素,并且给父元素div添加属性:font-si

CSS如何让浮动导航栏元素居中显示

CSS如何让浮动导航栏元素居中显示:制作导航栏是最为基础的布局技能之一,当然对于稍有经验的人员来说没有任何问题,不过对于初学者可能会有一定的困扰.普通的导航栏一般具有一下几个特点,整个导航栏居中,导航栏目具有,并且能够均匀分布,下面就是一个这样的简单代码实例.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="author"

IE6、IE7、IE8及其他浏览器多个元素并排显示

IE6.IE7.IE8及其他浏览器多个元素并排显示 HTML代码 <div class="line"> <h1>全部input框</h1> <input placeholder="我是输入框..." type="text"><input placeholder="我是输入框..." type="text"><input type="

JavaScript - 元素的显示和隐藏

元素的显示和隐藏 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>元素的显示和隐藏</title> <style type="text/css"> img{ display:block; } </style> <script type="text/