abap tree control demo

原创 2016年08月29日 15:14:35

最终效果图


代码:

REPORT ZTEST_HSS3.

INCLUDE ZTEST_HSS3_DATA.

INCLUDE ZTEST_HSS3_FRM.

INCLUDE ZTEST_HSS3_PBO.

INCLUDE ZTEST_HSS3_PAI.

INITIALIZATION.

*START-OF-SELECTION.


  CREATE OBJECT G_APPLICATION.

  CALL SCREEN 100.


ZTEST_HSS3_DATA的代码:

*&---------------------------------------------------------------------*
*&  包含                ZTEST_HSS3_DATA
*&---------------------------------------------------------------------*
TABLES:T001.
DATA: BEGIN OF GT_MARA OCCURS 0,
        ICON          LIKE ICON-ID, "状态指示灯
****超链接字段
        LINK_NAME(20).
        INCLUDE STRUCTURE MARA.
DATA: END OF GT_MARA.

DATA IT_T137 TYPE TABLE OF T137 WITH HEADER LINE.

DATA DYNNR TYPE SY-DYNNR VALUE '0200'.
DATA ALV_CONT TYPE REF TO CL_GUI_CUSTOM_CONTAINER.

*FIELD-SYMBOLS <FS_MARA> TYPE GT_MARA.
*DATA : GT_MARA LIKE TABLE OF MARA WITH HEADER LINE.
DATA: IT_MARA LIKE LINE OF GT_MARA.

DATA: G_DOCKING    TYPE REF TO CL_GUI_DOCKING_CONTAINER,
      G_SPLITTER   TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
      G_CONTAINER  TYPE REF TO CL_GUI_CONTAINER,
      G_CONTAINER1 TYPE REF TO CL_GUI_CONTAINER,
      G_GRID       TYPE REF TO CL_GUI_ALV_GRID.

DATA: GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE,
      GS_LAYOUT   TYPE LVC_S_LAYO.

DATA:TAB1 TYPE TABLE OF SVAL,
     TAB  LIKE LINE OF TAB1.
DATA: CODE  TYPE C.


DATA LT_DDVAL TYPE LVC_T_DRAL WITH HEADER LINE.


DATA TT_FIELDCAT TYPE LVC_T_FCAT.
DATA WA_FIELDCAT LIKE LINE OF TT_FIELDCAT.
DATA L_POS TYPE I.

DATA: GT_SFLIGHT      TYPE SFLIGHT OCCURS 0,      "Output-Table
      GT_FIELDCATALOG TYPE LVC_T_FCAT, "Fieldcatalog
      GT_SORT         TYPE LVC_T_SORT, "Sortiertabelle
      OK_CODE         LIKE SY-UCOMM.   "OK-Code

CLASS CL_GUI_COLUMN_TREE DEFINITION LOAD.
CLASS CL_GUI_CFW DEFINITION LOAD.

DATA: LS_VARIANT TYPE DISVARIANT.
DATA TREE1  TYPE REF TO CL_GUI_ALV_TREE_SIMPLE.
DATA: LT_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER,
      L_LOGO             TYPE SDYDO_VALUE.

INCLUDE <ICON>.
INCLUDE BCALV_SIMPLE_EVENT_RECEIVER.


"==========HTTP超链接
DATA: LS_HYPE TYPE LVC_S_HYPE,
      LT_HYPE TYPE LVC_T_HYPE . "网址映射关系表,在具体链接到哪个网址就是根据 handle 中设定的值来获取的

CLASS EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
****热点
      HANDLE_HOTSPOT FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID IMPORTING E_ROW_ID
                                                                            E_COLUMN_ID
                                                                            ES_ROW_NO,

****双击
      HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID IMPORTING SENDER
                                                                                E_ROW
                                                                                E_COLUMN
                                                                                ES_ROW_NO,

******工具栏
      HANDLE_TOOLBAR FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID IMPORTING E_OBJECT
                                                                      E_INTERACTIVE,

****用户自定义命令
      HANDLE_USER_COMMAND FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID IMPORTING E_UCOMM,

*****f4功能
      ON_F4 FOR EVENT ONF4 OF CL_GUI_ALV_GRID IMPORTING E_FIELDNAME
                                                          E_FIELDVALUE
                                                          ES_ROW_NO
                                                          ER_EVENT_DATA
                                                          ET_BAD_CELLS
                                                          E_DISPLAY,
*****数据改变
      HANDLE_DATA_CHANGED FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID IMPORTING ER_DATA_CHANGED
                                                                                E_ONF4
                                                                                E_ONF4_BEFORE
                                                                                E_ONF4_AFTER
                                                                                E_UCOMM,
****菜单按钮
      HANDLE_MENU_BUTTON FOR EVENT MENU_BUTTON OF CL_GUI_ALV_GRID IMPORTING E_OBJECT
                                                                              E_UCOMM.

ENDCLASS.

CLASS EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_HOTSPOT.
*    MESSAGE S001(00) WITH '热点连接' DISPLAY LIKE 'S'.
****跳转到 物料详细信息
    PERFORM FRM_MATNRINFO USING E_ROW_ID.
  ENDMETHOD.


  METHOD HANDLE_DOUBLE_CLICK.
    IF E_COLUMN = 'BSTME'.
      DATA VAL(30).
      CALL METHOD SENDER->GET_CURRENT_CELL
        IMPORTING
          E_VALUE = VAL.

      MESSAGE I001(00) WITH VAL.
    ENDIF.

  ENDMETHOD.

  METHOD HANDLE_TOOLBAR.
    PERFORM FRM_GETTOOLBAR USING E_OBJECT  E_INTERACTIVE.
  ENDMETHOD.

  METHOD HANDLE_USER_COMMAND.
  ENDMETHOD.

  METHOD ON_F4.
*    MESSAGE S001(00) WITH 'F4' DISPLAY LIKE 'S'.

    SELECT  MBRSH
            BRARE
            BBREF
            FLREF
      INTO CORRESPONDING FIELDS OF TABLE IT_T137
      FROM T137.

    CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
      EXPORTING
*       DDIC_STRUCTURE         = ' '
        RETFIELD    = 'MBRSH'
*       PVALKEY     = ' '
        DYNPPROG    = SY-REPID        "返回才程序
        DYNPNR      = SY-DYNNR        "屏幕
        DYNPROFIELD = 'MBRSH'        "往页面回填值的地方
*       STEPL       = 0
*       WINDOW_TITLE           =
*       VALUE       = ' '
        VALUE_ORG   = 'S'
*       MULTIPLE_CHOICE        = ' '
*       DISPLAY     = ' '
*       CALLBACK_PROGRAM       = ' '
*       CALLBACK_FORM          = ' '
*       CALLBACK_METHOD        =
*       MARK_TAB    =
* IMPORTING
*       USER_RESET  =
      TABLES
        VALUE_TAB   = IT_T137[]
*       FIELD_TAB   =
*       RETURN_TAB  =
*       DYNPFLD_MAPPING        =
* EXCEPTIONS
*       PARAMETER_ERROR        = 1
*       NO_VALUES_FOUND        = 2
*       OTHERS      = 3
      .
    IF SY-SUBRC <> 0.
* Implement suitable error handling here
    ENDIF.


  ENDMETHOD.

  METHOD HANDLE_DATA_CHANGED.
  ENDMETHOD.

  METHOD HANDLE_MENU_BUTTON.
  ENDMETHOD.

ENDCLASS.


DATA G_RECEIVER TYPE REF TO EVENT_RECEIVER.






DATA: WA_CONTAINER           TYPE SCRFNAME VALUE 'TREE',
      WA_CONTAINERALV        TYPE SCRFNAME VALUE 'ALV',
      WA_CUSTOM_CONTAINER    TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      WA_CUSTOM_CONTAINERALV TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      WA_TREE                TYPE REF TO CL_GUI_SIMPLE_TREE,
      WA_ALV                 TYPE REF TO CL_GUI_ALV_GRID.

DATA: NODE_TABLE  LIKE TABLE OF MTREESNODE,
      NODE_TABLE1 LIKE TABLE OF MTREESNODE,
      NODE1       TYPE MTREESNODE,
      NODE2       LIKE TABLE OF MTREESNODE WITH HEADER LINE,
      NODE3       LIKE TABLE OF MTREESNODE WITH HEADER LINE.

*DATA WA_SPFLI TYPE TABLE OF SPFLI WITH HEADER LINE.
*DATA WA_SFLIGHT TYPE TABLE OF SFLIGHT.

DATA: WA_ZTREE TYPE TABLE OF ZTREE WITH HEADER LINE,
      IT_ZTREE TYPE TABLE OF ZTREE,
      TY_ZTREE TYPE ZTREE.

DATA: NODEKEY(200)  VALUE 'NODE',
      NODETEXT(200) VALUE 'NODE'.

CLASS LCL_APPLICATION DEFINITION DEFERRED.
DATA EVENT_RECEIVER TYPE REF TO LCL_APPLICATION.

CLASS LCL_APPLICATION DEFINITION.
  PUBLIC SECTION.

    METHODS:
      HANDLE_NODE_DOUBLE_CLICK
      FOR EVENT NODE_DOUBLE_CLICK OF CL_GUI_SIMPLE_TREE IMPORTING NODE_KEY,

      HANDLE_NODE_CONTEXT_MENU_REQ
      FOR EVENT NODE_CONTEXT_MENU_REQUEST OF CL_GUI_SIMPLE_TREE IMPORTING NODE_KEY MENU,

***右键菜单选择之后的功能
      HANDLE_NODE_CONTEXT_MENU_SEL
      FOR EVENT NODE_CONTEXT_MENU_SELECT OF CL_GUI_SIMPLE_TREE IMPORTING NODE_KEY FCODE.

*      HANDLE_EXPAND_NO_CHILDREN
*      FOR EVENT EXPAND_NO_CHILDREN OF CL_GUI_SIMPLE_TREE.
ENDCLASS.

CLASS LCL_APPLICATION IMPLEMENTATION.

  METHOD HANDLE_NODE_DOUBLE_CLICK.
    CASE  NODE_KEY.
      WHEN  '1000'.
        DYNNR = '200'.
      WHEN OTHERS.
        DYNNR = '300'.
    ENDCASE.

  ENDMETHOD.

  METHOD HANDLE_NODE_CONTEXT_MENU_REQ.
    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '增加本级节点'
        FCODE = 'CODE1'.

    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '增加子节点'
        FCODE = 'CODE2'.

    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '修改当前节点'
        FCODE = 'CODE3'.
    CALL METHOD MENU->ADD_FUNCTION
      EXPORTING
        TEXT  = '删除当前节点'
        FCODE = 'CODE4'.
  ENDMETHOD.

  METHOD HANDLE_NODE_CONTEXT_MENU_SEL.

    CLEAR: TAB,TAB1[],NODE2[],TY_ZTREE.
    READ TABLE  NODE_TABLE INTO NODE2 WITH KEY NODE_KEY = NODE_KEY.

    IF SY-SUBRC EQ 0.
      IF FCODE NE 'CODE4'.
        IF FCODE NE 'CODE3'.
          TAB-TABNAME = 'ZTREE'.
          TAB-FIELDNAME = 'TREEID'.
          APPEND TAB TO TAB1 .

          TAB-TABNAME = 'ZTREE'.
          TAB-FIELDNAME = 'TREENAME'.
          APPEND TAB TO TAB1 .

          "弹出填写数据的框
          CALL FUNCTION 'POPUP_GET_VALUES_USER_HELP'
            EXPORTING
              POPUP_TITLE = '增加节点'
              PROGRAMNAME = 'ZTEST_HSS3'
              FORMNAME    = 'ADDFORM'
            IMPORTING
              RETURNCODE  = CODE
            TABLES
              FIELDS      = TAB1.

          IF SY-SUBRC = 0 AND CODE NE 'A'.
            READ TABLE NODE3 INDEX 1 TRANSPORTING NO FIELDS.

            IF FCODE EQ 'CODE1'.
              NODE1-RELATKEY = NODE2-RELATKEY.
            ELSEIF FCODE EQ 'CODE2'.
              NODE1-RELATKEY = NODE_KEY.
            ENDIF.
            NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
            NODE1-HIDDEN = ''.
            NODE1-DISABLED = ''.
            NODE1-ISFOLDER = 'X'.
*        NODE1-N_IMAGE = '@5B@'.
*        NODE1-EXP_IMAGE = '@5B@'.
            CLEAR NODE1-EXPANDER.
            NODE1-NODE_KEY = NODE3-NODE_KEY.
            NODE1-TEXT = NODE3-TEXT.
            APPEND NODE1 TO NODE_TABLE.
            APPEND NODE1 TO NODE_TABLE1.

            CALL METHOD WA_TREE->ADD_NODES
              EXPORTING
                TABLE_STRUCTURE_NAME = 'MTREESNODE'
                NODE_TABLE           = NODE_TABLE1.
            IF SY-SUBRC <> 0.
            ENDIF.

            CLEAR: TY_ZTREE,IT_ZTREE[].
            TY_ZTREE-TREEID = NODE1-NODE_KEY.
            TY_ZTREE-TREENAME = NODE1-TEXT.
            TY_ZTREE-PARENTID = NODE1-RELATKEY.
            APPEND TY_ZTREE TO IT_ZTREE.

            INSERT ZTREE FROM TABLE IT_ZTREE.

            CLEAR: NODE1,NODE3.
          ENDIF.

        ELSE.
          TAB-TABNAME = 'ZTREE'.
          TAB-FIELDNAME = 'TREENAME'.
          TAB-VALUE = NODE2-TEXT.
          APPEND TAB TO TAB1 .

          "弹出填写数据的框
          CALL FUNCTION 'POPUP_GET_VALUES_USER_HELP'
            EXPORTING
              POPUP_TITLE = '修改节点'
              PROGRAMNAME = 'ZTEST_HSS3'
              FORMNAME    = 'UPDATEFORM'
            IMPORTING
              RETURNCODE  = CODE
            TABLES
              FIELDS      = TAB1.

          IF SY-SUBRC = 0 AND CODE NE 'A'.
            READ TABLE NODE3 INDEX 1 TRANSPORTING NO FIELDS.

*            NODE1-TEXT = NODE3-TEXT.
*            NODE1-NODE_KEY = NODE_KEY.

            CALL METHOD WA_TREE->NODE_SET_TEXT
              EXPORTING
                NODE_KEY = NODE_KEY
                TEXT     = NODE3-TEXT.
            IF SY-SUBRC <> 0.
            ENDIF.

            CLEAR: TY_ZTREE,IT_ZTREE[].
            TY_ZTREE-TREEID = NODE_KEY.
            TY_ZTREE-TREENAME = NODE3-TEXT.
            TY_ZTREE-PARENTID = NODE2-RELATKEY.
            APPEND TY_ZTREE TO IT_ZTREE.

            UPDATE ZTREE FROM TABLE IT_ZTREE.

            CLEAR: NODE3.
          ENDIF.

        ENDIF.
      ELSE.
        CALL METHOD WA_TREE->DELETE_NODE
          EXPORTING
            NODE_KEY = NODE_KEY.

        DELETE NODE_TABLE WHERE NODE_KEY = NODE_KEY.

        TY_ZTREE-TREEID = NODE_KEY.
*      APPEND TY_ZTREE TO IT_ZTREE.
        DELETE ZTREE FROM TY_ZTREE.
      ENDIF.
    ENDIF.

  ENDMETHOD.

ENDCLASS.

DATA G_APPLICATION TYPE REF TO LCL_APPLICATION.



     ZTEST_HSS3_FRM的代码:

*&---------------------------------------------------------------------*
*&  包含                ZTEST_HSS3_FRM
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_FCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_FCAT .

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'ICON'.
  GT_FIELDCAT-COLTEXT = '指示灯'.
  GT_FIELDCAT-ICON = 'X'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'MATNR'.
  GT_FIELDCAT-COLTEXT = '物料号'.
  GT_FIELDCAT-HOTSPOT = 'X'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'MTART'.
  GT_FIELDCAT-COLTEXT = '物料类型'.
  GT_FIELDCAT-REF_FIELD = 'MTART'.
  GT_FIELDCAT-REF_TABLE = 'MARA'.
  GT_FIELDCAT-EDIT = 'X'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'MBRSH'.
  GT_FIELDCAT-COLTEXT = '行业类型'.
  GT_FIELDCAT-F4AVAILABL = 'X'.
  GT_FIELDCAT-EDIT = 'X'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'MATKL'.
  GT_FIELDCAT-COLTEXT = '物料组'.
  GT_FIELDCAT-WEB_FIELD = 'LINK_NAME'.
  APPEND GT_FIELDCAT.


  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'MEINS'.
  GT_FIELDCAT-COLTEXT = '基本计量单位'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'BSTME'.
  GT_FIELDCAT-COLTEXT = '订单单位'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'WRKST'.
  GT_FIELDCAT-COLTEXT = '基本物料'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'SPART'.
  GT_FIELDCAT-COLTEXT = '产品组'.
  GT_FIELDCAT-DRDN_HNDL = '1'.          "下拉栏设置
*  GT_FIELDCAT-DRDN_FIELD = 'DROP_DOWN' .
  GT_FIELDCAT-DRDN_ALIAS = 'X'.
  APPEND GT_FIELDCAT.

  CLEAR GT_FIELDCAT.
  GT_FIELDCAT-FIELDNAME = 'LABOR'.
  GT_FIELDCAT-COLTEXT = '实验室/设计室 '.
  APPEND GT_FIELDCAT.


*  CLEAR GT_FIELDCAT.
*  GT_FIELDCAT-FIELDNAME = 'LVORM'.
*  GT_FIELDCAT-COLTEXT = '删除标记'.
*  APPEND GT_FIELDCAT.

  PERFORM FRM_DRDN_HNDL.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DIAPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DIAPLAY_ALV .

  GS_LAYOUT-ZEBRA = 'X'.
  GS_LAYOUT-CWIDTH_OPT = 'X'.
  GS_LAYOUT-SEL_MODE = 'D'.

  CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
*     I_BUFFER_ACTIVE =
*     I_BYPASSING_BUFFER            =
*     I_CONSISTENCY_CHECK           =
*     I_STRUCTURE_NAME              =
*     IS_VARIANT      =
*     I_SAVE          =
*     I_DEFAULT       = 'X'
      IS_LAYOUT       = GS_LAYOUT
*     IS_PRINT        =
*     IT_SPECIAL_GROUPS             =
*     IT_TOOLBAR_EXCLUDING          =
      IT_HYPERLINK    = LT_HYPE
*     IT_ALV_GRAPHICS =
*     IT_EXCEPT_QINFO =
*     IR_SALV_ADAPTER =
    CHANGING
      IT_OUTTAB       = GT_MARA[]
      IT_FIELDCATALOG = GT_FIELDCAT[]
*     IT_SORT         =
*     IT_FILTER       =
*    EXCEPTIONS
*     INVALID_PARAMETER_COMBINATION = 1
*     PROGRAM_ERROR   = 2
*     TOO_MANY_LINES  = 3
*     OTHERS          = 4
    .
  IF SY-SUBRC <> 0.
*   Implement suitable error handling here
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GETDATA .
  SELECT MATNR MTART MATKL BSTME WRKST SPART LVORM MBRSH MEINS LABOR
    UP TO 20 ROWS
    INTO CORRESPONDING FIELDS OF TABLE GT_MARA
    FROM MARA
  ORDER BY LVORM DESCENDING.


  GT_MARA-MATNR = '111111111'.
  GT_MARA-MTART = 'ZB05'.
  GT_MARA-MATKL = '20201'.
  GT_MARA-BSTME = ''.
  GT_MARA-WRKST = ''.
  GT_MARA-SPART = '01'.
  GT_MARA-LVORM = 'X'.
  GT_MARA-LINK_NAME = '1'.
  APPEND GT_MARA.
  CLEAR GT_MARA.


  LS_HYPE-HANDLE = 1 ."相当于HashMap中的Key
  LS_HYPE-HREF = 'http://www.baidu.com' ."相当于HashMap中的Value
  APPEND LS_HYPE TO LT_HYPE .
*  ICON
  LOOP AT GT_MARA.
    IF GT_MARA-LVORM EQ 'X'.
      GT_MARA-ICON = '@0A@'.
    ELSE.
      GT_MARA-ICON = '@08@'.
    ENDIF.
    MODIFY GT_MARA.
    CLEAR GT_MARA.
  ENDLOOP.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_MATNRINFO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_E_ROW_ID  text
*----------------------------------------------------------------------*
FORM FRM_MATNRINFO  USING    P_E_ROW_ID TYPE LVC_S_ROW.
  READ TABLE GT_MARA INDEX P_E_ROW_ID INTO IT_MARA.
  IF SY-SUBRC = 0.
    SET PARAMETER ID 'MAT' FIELD IT_MARA-MATNR.
    CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
    CLEAR IT_MARA.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DRDN_HNDL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DRDN_HNDL .

  CLEAR LT_DDVAL.
  LT_DDVAL-HANDLE = '1'.
  LT_DDVAL-INT_VALUE = '01'.
  LT_DDVAL-VALUE = '产品组'.
  APPEND LT_DDVAL.

  CLEAR LT_DDVAL.
  LT_DDVAL-HANDLE = '1'.
  LT_DDVAL-INT_VALUE = 'Z1'.
  LT_DDVAL-VALUE = '铸钢泵'.
  APPEND LT_DDVAL.

  CLEAR LT_DDVAL.
  LT_DDVAL-HANDLE = '1'.
  LT_DDVAL-INT_VALUE = 'Z2'.
  LT_DDVAL-VALUE = '增压泵'.
  APPEND LT_DDVAL.

  CALL METHOD G_GRID->SET_DROP_DOWN_TABLE
    EXPORTING
      IT_DROP_DOWN_ALIAS = LT_DDVAL[].
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_GETTOOLBAR
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_E_OBJECT  text
*      -->P_E_INTERACTIVE  text
*----------------------------------------------------------------------*
FORM FRM_GETTOOLBAR  USING    P_E_OBJECT TYPE REF TO CL_ALV_EVENT_TOOLBAR_SET
                              P_E_INTERACTIVE TYPE CHAR01.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_REGISTERF4
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_REGISTERF4 .
  DATA: LT_F4 TYPE LVC_T_F4,
        LS_F4 TYPE LVC_S_F4.

  LS_F4-FIELDNAME = 'MBRSH'.
  LS_F4-REGISTER = 'X'.
  APPEND LS_F4 TO LT_F4.

  CALL METHOD G_GRID->REGISTER_F4_FOR_FIELDS
    EXPORTING
      IT_F4 = LT_F4.

ENDFORM.


FORM BUILD_FIELDCATALOG.
* get fieldcatalog
  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME = 'SFLIGHT'
    CHANGING
      CT_FIELDCAT      = GT_FIELDCATALOG.
* change fieldcatalog
  DATA: LS_FIELDCATALOG TYPE LVC_S_FCAT.
  LOOP AT GT_FIELDCATALOG INTO LS_FIELDCATALOG.
    CASE LS_FIELDCATALOG-FIELDNAME.
      WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'.
        LS_FIELDCATALOG-NO_OUT = 'X'.
        LS_FIELDCATALOG-KEY    = ''.
      WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'.
        LS_FIELDCATALOG-DO_SUM = 'X'.
    ENDCASE.
    MODIFY GT_FIELDCATALOG FROM LS_FIELDCATALOG.
  ENDLOOP.
ENDFORM.

FORM BUILD_OUTTAB.
  SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT.
ENDFORM.

FORM BUILD_SORT_TABLE.
  DATA LS_SORT_WA TYPE LVC_S_SORT.
* create sort-table
  LS_SORT_WA-SPOS = 1.
  LS_SORT_WA-FIELDNAME = 'CARRID'.
  LS_SORT_WA-UP = 'X'.
  LS_SORT_WA-SUBTOT = 'X'.
  APPEND LS_SORT_WA TO GT_SORT.

  LS_SORT_WA-SPOS = 2.
  LS_SORT_WA-FIELDNAME = 'CONNID'.
  LS_SORT_WA-UP = 'X'.
  LS_SORT_WA-SUBTOT = 'X'.
  APPEND LS_SORT_WA TO GT_SORT.

  LS_SORT_WA-SPOS = 3.
  LS_SORT_WA-FIELDNAME = 'FLDATE'.
  LS_SORT_WA-UP = 'X'.
  APPEND LS_SORT_WA TO GT_SORT.
ENDFORM.                               " BUILD_SORT_TABLE
*&---------------------------------------------------------------------*
*&      Form  FRM_INITIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_INITIAL .

  DATA: EVENTS TYPE CNTL_SIMPLE_EVENTS,
        EVENT1 TYPE CNTL_SIMPLE_EVENT.

  SELECT * INTO TABLE WA_ZTREE FROM ZTREE
    ORDER BY TREEID  PARENTID ASCENDING.

*****第一步创建最大的显示屏幕容器
  IF G_DOCKING IS INITIAL.
    CREATE OBJECT G_DOCKING
      EXPORTING
*       PARENT                      =
        REPID                       = SY-REPID
        DYNNR                       = '0100'
        SIDE                        = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT
        EXTENSION                   = 300    "全屏设置
*       STYLE                       =
*       LIFETIME                    = lifetime_default
*       CAPTION                     =
*       METRIC                      = 0
*       RATIO                       =
*       NO_AUTODEF_PROGID_DYNNR     =
*       NAME                        =
      EXCEPTIONS
        CNTL_ERROR                  = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        LIFETIME_ERROR              = 4
        LIFETIME_DYNPRO_DYNPRO_LINK = 5
*       OTHERS                      = 6
      .
    IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.


*建立树对象
    CREATE OBJECT WA_TREE
      EXPORTING
        PARENT                      = G_DOCKING
        NODE_SELECTION_MODE         = CL_GUI_SIMPLE_TREE=>NODE_SEL_MODE_SINGLE
      EXCEPTIONS
        LIFETIME_ERROR              = 1
        CNTL_SYSTEM_ERROR           = 2
        CREATE_ERROR                = 3
        FAILED                      = 4
        ILLEGAL_NODE_SELECTION_MODE = 5.

    IF SY-SUBRC <> 0.
    ENDIF.


    DATA: PARENTID LIKE ZTREE-PARENTID.

    DATA:STR1(255).

*定义双击事件
    EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK.
    EVENT1-APPL_EVENT = 'X'.
    APPEND EVENT1 TO EVENTS.

***右键菜单功能
    EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_CONTEXT_MENU_REQ.
    EVENT1-APPL_EVENT = ''.
    APPEND EVENT1 TO EVENTS.

    EVENT1-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_EXPAND_NO_CHILDREN.
    EVENT1-APPL_EVENT = ''.
    APPEND EVENT1 TO EVENTS.

    CALL METHOD WA_TREE->SET_CTX_MENU_SELECT_EVENT_APPL
      EXPORTING
        APPL_EVENT = 'X'.

    CALL METHOD WA_TREE->SET_REGISTERED_EVENTS
      EXPORTING
        EVENTS = EVENTS.

    IF SY-SUBRC <> 0.
    ENDIF.
*
*将已定义的双击事件分配至树对象
    SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR WA_TREE.
    SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_REQ FOR WA_TREE.
    SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_SEL FOR WA_TREE.


    LOOP AT WA_ZTREE.

      CLEAR NODE1.
      IF  WA_ZTREE-PARENTID IS INITIAL.
        NODE1-NODE_KEY = WA_ZTREE-TREEID.
*第一层
        CLEAR NODE1-RELATKEY.
        CLEAR NODE1-RELATSHIP.
*是文件夹
        NODE1-HIDDEN = ''.
        NODE1-DISABLED = ''.
        NODE1-ISFOLDER = 'X'.
*不带ICON
        CLEAR NODE1-N_IMAGE.
        CLEAR NODE1-EXP_IMAGE.
        CLEAR NODE1-EXPANDER.

        NODE1-TEXT = WA_ZTREE-TREENAME.
        APPEND NODE1 TO NODE_TABLE.
      ELSE.
        NODE1-RELATKEY = WA_ZTREE-PARENTID.
        NODE1-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
        NODE1-HIDDEN = ''.
        NODE1-DISABLED = ''.
        NODE1-ISFOLDER = 'X'.
*        NODE1-N_IMAGE = '@5B@'.
*        NODE1-EXP_IMAGE = '@5B@'.
        CLEAR NODE1-EXPANDER.
        NODE1-NODE_KEY = WA_ZTREE-TREEID.
        NODE1-TEXT = WA_ZTREE-TREENAME.
        APPEND NODE1 TO NODE_TABLE.
      ENDIF.
    ENDLOOP.

*按照节点内容添加节点
    CALL METHOD WA_TREE->ADD_NODES
      EXPORTING
        TABLE_STRUCTURE_NAME           = 'MTREESNODE'
        NODE_TABLE                     = NODE_TABLE
      EXCEPTIONS
        FAILED                         = 1
        ERROR_IN_NODE_TABLE            = 2
        DP_ERROR                       = 3
        TABLE_STRUCTURE_NAME_NOT_FOUND = 4
        OTHERS                         = 5.

    IF SY-SUBRC <> 0.
    ENDIF.

  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Module  STATUS_0300  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0300 OUTPUT.
  IF ALV_CONT IS INITIAL.
    CREATE OBJECT ALV_CONT
      EXPORTING
        CONTAINER_NAME = 'ALV'.

    CREATE OBJECT G_GRID
      EXPORTING
*       I_SHELLSTYLE      = 0
*       I_LIFETIME        =
        I_PARENT = ALV_CONT
*       I_APPL_EVENTS     = space
*       I_PARENTDBG       =
*       I_APPLOGPARENT    =
*       I_GRAPHICSPARENT  =
*       I_NAME   =
*       I_FCAT_COMPLETE   = SPACE
*    EXCEPTIONS
*       ERROR_CNTL_CREATE = 1
*       ERROR_CNTL_INIT   = 2
*       ERROR_CNTL_LINK   = 3
*       ERROR_DP_CREATE   = 4
*       OTHERS   = 5
      .
    IF SY-SUBRC <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CREATE OBJECT G_RECEIVER.
    SET HANDLER: G_RECEIVER->HANDLE_HOTSPOT FOR ALL INSTANCES,
                 G_RECEIVER->HANDLE_DOUBLE_CLICK FOR ALL INSTANCES,
                 G_RECEIVER->ON_F4 FOR ALL INSTANCES.

    PERFORM FRM_REGISTERF4.
    PERFORM FRM_GETDATA.
    PERFORM FRM_ALV_FCAT.

    PERFORM FRM_DIAPLAY_ALV.
  ENDIF.
ENDMODULE.


FORM ADDFORM  TABLES   FIELDS STRUCTURE SVAL
                     CHANGING ERROR  STRUCTURE SVALE.
  CLEAR: NODE3,NODE3[].
  LOOP AT FIELDS WHERE FIELDNAME = 'TREEID'.
    READ TABLE NODE_TABLE WITH KEY NODE_KEY = FIELDS-VALUE INTO NODE3.
    IF SY-SUBRC EQ 0.
      MESSAGE E208(00) WITH '键值重复!'.
      LEAVE PROGRAM.
    ELSE.
      CLEAR: NODE3,NODE3[],FIELDS.
      LOOP AT FIELDS.
        IF FIELDS-FIELDNAME = 'TREEID'.
          NODE3-NODE_KEY = FIELDS-VALUE.
        ELSEIF FIELDS-FIELDNAME = 'TREENAME'.
          NODE3-TEXT = FIELDS-VALUE.
        ENDIF.
      ENDLOOP.

      APPEND NODE3.

    ENDIF.
    CLEAR FIELDS.
  ENDLOOP.

ENDFORM.

FORM UPDATEFORM  TABLES   FIELDS STRUCTURE SVAL
                     CHANGING ERROR  STRUCTURE SVALE.
  CLEAR: NODE3,NODE3[].

  READ TABLE FIELDS INDEX 1.
  READ TABLE NODE_TABLE WITH KEY NODE_KEY = FIELDS-VALUE INTO NODE3.
  NODE3-TEXT = FIELDS-VALUE.
  APPEND NODE3.

  CLEAR FIELDS.

ENDFORM.



ZTEST_HSS3_PBO的代码:

*&---------------------------------------------------------------------*
*&  包含                ZTEST_HSS3_PBO
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS '100'.
*  SET TITLEBAR 'xxx'.
  PERFORM FRM_INITIAL.

ENDMODULE.

ZTEST_HSS3_PAI的代码:

*&---------------------------------------------------------------------*
*&  包含                ZTEST_HSS3_PAI
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  CASE SY-UCOMM.
    WHEN 'BACK' OR 'CANCEL' OR 'EXIT'.
      LEAVE TO SCREEN 0.
  ENDCASE.
ENDMODULE.



屏幕100的代码:

PROCESS BEFORE OUTPUT.
 MODULE STATUS_0100.

call SUBSCREEN: sub1 INCLUDING sy-REPID DYNNR.
PROCESS AFTER INPUT.
  MODULE USER_COMMAND_0100.


100屏幕元素:


屏幕200元素:


屏幕300元素:



PROCESS BEFORE OUTPUT.
 MODULE STATUS_0300.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_0300.








相关文章推荐

ABAP Tree Control的使用

Tree Control是最常用的Windows控件之一,在其他语言中,称为“Tree View”等,ABAP的Tree Control能完成相似的功能,本章主要介绍以下实例: (1)实现一个简单的T...

TREE demo

*&---------------------------------------------------------------------* *& Report BCALV_TREE_DEMO ...

Abap/4 控制ALV树(2)

*&---------------------------------------------------------------------* *& Report  Z_CPT10_1      ...

ALV_TREE(二:cl_gui_simple_tree…

树形展示 首先创建屏幕, 画个容器,命名TREE DATA:       wa_container_tree         TYPE        scrfname VALUE 'TREE',...

Reporting Tree in ABAP

* An ABAP reporting tree program that allows the user to press enter or double click on * any line. ...

Delphi7高级应用开发随书源码

  • 2003年04月30日 00:00
  • 676KB
  • 下载

SAP ABAP/4学习--BCALV_TREE_01分析

BCALV_TREE_01分析                                SSOLE   REPORT  BCALV_TREE_01.*&&&&&&&&&&&&&&&&&&&&&&...
  • opparts
  • opparts
  • 2005年02月02日 16:51
  • 5747

ABAP总结之八,ALV,TABLE TREE等一些控件

   今天来总结一下ABAP中一些常用的控件,除去之前写过的一些,还有ALV_GRID, ALV_TREE, TABLE_TREE等。    现在用的控件很多都是用类写的,而它们的使用,说白一点,就和...

[abap] 'REUSE_ALV_GRID_DISPLAY_LVC' 的用法

说明:REUSE_ALV_GRID_DISPLAY_LVC 的用法

ABAP表控制Table Control设计

表控制(Table Control)是SAP应用中最重要的对象之一,业务单据的输入、基础数据的表格输入等都是使用Table Control控件,本章主要介绍: (1)在屏幕设计中通过向导来制作表控件对...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:abap tree control demo
举报原因:
原因补充:

(最多只允许输入30个字)