Chinaunix首页 | 论坛 | 博客
  • 博客访问: 402410
  • 博文数量: 120
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 1266
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-16 16:04
文章分类

全部博文(120)

文章存档

2011年(4)

2010年(10)

2009年(38)

2008年(68)

我的朋友

分类:

2008-12-08 15:12:22

REPORT ZTEST_CONTROL.
TYPE-POOLS ICON.
DATA:G_DOCK TYPE REF TO CL_GUI_DOCKING_CONTAINER,
     G_SPLIT TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
     G_BARCON TYPE REF TO CL_GUI_CONTAINER_BAR,
     G_TREE TYPE REF TO CL_GUI_COLUMN_TREE,
     G_CON TYPE REF TO CL_GUI_CONTAINER,
     G_CON1 TYPE REF TO CL_GUI_CONTAINER,
     G_CON2 TYPE REF TO CL_GUI_CONTAINER,
     G_CON3 TYPE REF TO CL_GUI_CONTAINER,
     G_EDIT TYPE REF TO CL_GUI_TEXTEDIT,
     G_GRID TYPE REF TO CL_GUI_ALV_GRID,
     INIT(1).
TYPES: ITEM_TABLE_TYPE LIKE STANDARD TABLE OF MTREEITM WITH DEFAULT KEY.
DATA:NODE_TABLE TYPE TREEV_NTAB,
     ITEM_TABLE TYPE ITEM_TABLE_TYPE,
     EVENT TYPE CNTL_SIMPLE_EVENT,
     EVENTS TYPE CNTL_SIMPLE_EVENTS,
     HIERARCHY_HEADER TYPE TREEV_HHDR,
     LI_NODE TYPE I.
DATA ITAB LIKE MARA OCCURS 0 WITH HEADER LINE.
DATA:BEGIN OF ITAB1 OCCURS 0,
         MATKL    TYPE MARA-MATKL,              "物料组
         WGBEZ,                                 "物料组描述
         NODE     TYPE TREEV_NODE-NODE_KEY,     "节点
         RELATKEY TYPE TREEV_NODE-RELATKEY,
         FOLDER(1),                             "文件夹折叠标记
         LEVEL(1),                              "文件夹所在层级
     END OF ITAB1,
     WA LIKE ITAB1.
DATA:S_CAPTION TYPE SBPTCAPTN,
     T_CAPTION TYPE SBPTCAPTNS.
PARAMETERS P_MATNR TYPE MATNR.
AT SELECTION-SCREEN OUTPUT.
  IF INIT IS INITIAL.
    INIT = 'X'.
***创建docking容器
    CREATE OBJECT G_DOCK
      EXPORTING
        REPID            = SY-REPID
        DYNNR            = SY-DYNNR
        SIDE             = 4
        EXTENSION        = 500 .
***创建splitter容器
    CREATE OBJECT G_SPLIT
      EXPORTING
        PARENT            = G_DOCK
        ROWS              = 1
        COLUMNS           = 2  .
***获得splitter的左子容器
    CALL METHOD G_SPLIT->GET_CONTAINER
      EXPORTING
        ROW       = 1
        COLUMN    = 1
      RECEIVING
        CONTAINER = G_CON.
***创建containerbar的标题,有几个标题,表示内部包含几个子容器
    S_CAPTION-CAPTION = 'TEXTEDIT'.
    S_CAPTION-ICON = .
    APPEND S_CAPTION TO T_CAPTION.
    S_CAPTION-CAPTION = 'ALV_GRID'.
    S_CAPTION-ICON = ICON_TABLE_SETTINGS.
    APPEND S_CAPTION TO T_CAPTION.
    S_CAPTION-CAPTION = 'COLUMN_TREE'.
    S_CAPTION-ICON = ICON_TREE.
    APPEND S_CAPTION TO T_CAPTION.
***在splitter的子容器里创建containerbar
    CREATE OBJECT G_BARCON
      EXPORTING
        CAPTIONS        = T_CAPTION
        PARENT          = G_CON.
***获得containerbar里的第一个子容器
    CALL METHOD G_BARCON->GET_CONTAINER
      EXPORTING
        ID        = 1
      RECEIVING
        CONTAINER = G_CON1.
***在第一个子容器创建textedit
    CREATE OBJECT G_EDIT
      EXPORTING
        PARENT                 = G_CON1.
***获得containerbar里的第二个子容器
    CALL METHOD G_BARCON->GET_CONTAINER
      EXPORTING
        ID        = 2
      RECEIVING
        CONTAINER = G_CON2.
***在第2个子容器里创建alv_grid
    CREATE OBJECT G_GRID
      EXPORTING
        I_PARENT                 = G_CON2.
    SELECT * FROM MARA INTO TABLE ITAB UP TO 10 ROWS.
    CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
        I_STRUCTURE_NAME = 'MARA'
      CHANGING
        IT_OUTTAB        = ITAB[].
***获得containerbar里的第三个子容器
    CALL METHOD G_BARCON->GET_CONTAINER
      EXPORTING
        ID        = 3
      RECEIVING
        CONTAINER = G_CON3.
***在第3个子容器中创建column tree
* 设置层次的描述(第一列)
    HIERARCHY_HEADER-HEADING = '物料组'.
    HIERARCHY_HEADER-WIDTH = 40.
**建立树对象, 初始化树
    CREATE OBJECT G_TREE
      EXPORTING
        PARENT              = G_CON3
        NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE
        ITEM_SELECTION = 'X'
        HIERARCHY_COLUMN_NAME = 'Column1'                     "列1(物料组)
        HIERARCHY_HEADER = HIERARCHY_HEADER
      EXCEPTIONS
        CNTL_SYSTEM_ERROR           = 1
        CREATE_ERROR                = 2
        FAILED                      = 3
        ILLEGAL_NODE_SELECTION_MODE = 4
        ILLEGAL_COLUMN_NAME         = 5
        LIFETIME_ERROR              = 6.
**构建树内容
    PERFORM BUILD_NODE_AND_ITEM_TABLE USING NODE_TABLE ITEM_TABLE.
    CALL METHOD G_TREE->ADD_NODES_AND_ITEMS
      EXPORTING
        NODE_TABLE                     = NODE_TABLE
        ITEM_TABLE                     = ITEM_TABLE
        ITEM_TABLE_STRUCTURE_NAME      = 'MTREEITM'
      EXCEPTIONS
        FAILED                         = 1
        CNTL_SYSTEM_ERROR              = 3
        ERROR_IN_TABLES                = 4
        DP_ERROR                       = 5
        TABLE_STRUCTURE_NAME_NOT_FOUND = 6.
* 展开根节点
    CALL METHOD G_TREE->EXPAND_NODE
      EXPORTING
        NODE_KEY            = 'Root'
      EXCEPTIONS
        FAILED              = 1
        ILLEGAL_LEVEL_COUNT = 2
        CNTL_SYSTEM_ERROR   = 3
        NODE_NOT_FOUND      = 4
        CANNOT_EXPAND_LEAF  = 5.
  ENDIF.
*&--------------------------------------------------------------------*
*&      Form  BUILD_NODE_AND_ITEM_TABLE
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->NODE_TABLE text
*      -->ITEM_TABLE text
*---------------------------------------------------------------------*
FORM BUILD_NODE_AND_ITEM_TABLE
  USING
    NODE_TABLE TYPE TREEV_NTAB
    ITEM_TABLE TYPE ITEM_TABLE_TYPE.
  DATA: NODE TYPE TREEV_NODE,
        ITEM TYPE MTREEITM,
        L_NODE(12),
        L_NODE1(12),
        L_NODE2(12),
        L_LEN TYPE I.
  CLEAR NODE.
  NODE-NODE_KEY = 'Root'.
  NODE-ISFOLDER = 'X'.
  APPEND NODE TO NODE_TABLE.
  CLEAR ITEM.
  ITEM-NODE_KEY = 'Root'.
  ITEM-ITEM_NAME = 'Column1'.
  ITEM-TEXT = '物料组显示'.
  APPEND ITEM TO ITEM_TABLE.
  APPEND 'ABC' TO ITAB1.
  APPEND 'ABE' TO ITAB1.
  APPEND 'ABF' TO ITAB1.
  APPEND 'ABG' TO ITAB1.
  APPEND 'BBC' TO ITAB1.
  LOOP AT ITAB1 INTO WA.
    WA-LEVEL = '3'.                      "第三层
    MODIFY ITAB1 FROM WA.
    READ TABLE ITAB1 WITH KEY MATKL = WA-MATKL+0(1).
    IF SY-SUBRC <> 0.
      ITAB1-LEVEL = '1'.                       "第一层
      ITAB1-MATKL = WA-MATKL+0(1).
      APPEND ITAB1 TO ITAB1.
    ENDIF.
    READ TABLE ITAB1 WITH KEY MATKL = WA-MATKL+0(2).
    IF SY-SUBRC <> 0.
      ITAB1-LEVEL = '2'.                       "第二层
      ITAB1-MATKL = WA-MATKL+0(2).
      APPEND ITAB1 TO ITAB1.
    ENDIF.
  ENDLOOP.
  SORT ITAB1 BY MATKL .
  LI_NODE = 1.
  LOOP AT ITAB1.
    CLEAR: NODE.
    NODE-NODE_KEY = LI_NODE.
    LI_NODE = LI_NODE + 1.
    ITAB1-NODE = NODE-NODE_KEY.
    CLEAR L_LEN.
    L_LEN = STRLEN( ITAB1-MATKL ).
    CASE L_LEN.
      WHEN 1.
        L_NODE1 = NODE-NODE_KEY.
        ITAB1-RELATKEY = 'Root'.
        NODE-RELATKEY = 'Root'.
        NODE-ISFOLDER = 'X'.
        NODE-EXPANDER = 'X'.
      WHEN 2.
        L_NODE2 = NODE-NODE_KEY.
        ITAB1-RELATKEY = L_NODE1.
        NODE-RELATKEY = L_NODE1.
        NODE-ISFOLDER = 'X'.
        NODE-EXPANDER = 'X'.
      WHEN OTHERS.
        ITAB1-RELATKEY = L_NODE2.
        NODE-RELATKEY = L_NODE2.
        NODE-ISFOLDER = ''.
        NODE-EXPANDER = ''.
    ENDCASE.
    MODIFY ITAB1.
    NODE-RELATSHIP = CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD.
    APPEND NODE TO NODE_TABLE.
    CLEAR ITEM.
    ITEM-NODE_KEY = NODE-NODE_KEY.
    ITEM-ITEM_NAME = 'Column1'.
    ITEM-TEXT = ITAB1-MATKL.
    APPEND ITEM TO ITEM_TABLE.
  ENDLOOP.
ENDFORM.                    " BUILD_NODE_AND_ITEM_TABLE
阅读(1565) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~