ALV Tree 구현

1. Data, Tree Event Receiver Class 선언 및 생성

2. 객체 선언 및 Container 할당

3. Tree Root, Node, Item 구성

4. Tree Refresh 방법.

1. Data, Tree Event Receiver Class 선언 및 생성

[#M_더보기|접기|

  CLASS LCL_TREE_EVENT_RECEIVER DEFINITION DEFERRED.

  DATA: GO_COLUMN_TREE TYPE REF TO CL_GUI_COLUMN_TREE,

            GO_TREE                TYPE REF TO LCL_TREE_EVENT_RECEIVER.





2. Tree Event Receiver Class 생성

*———————————————————————-*

*       CLASS LCL_TREE_EVENT_RECEIVER DEFINITION

*———————————————————————-*

*

*———————————————————————-*

CLASS LCL_TREE_EVENT_RECEIVER DEFINITION.

  PUBLIC SECTION.

    METHODS:

      HANDLE_BUTTON_CLICK

        FOR EVENT BUTTON_CLICK

        OF CL_GUI_COLUMN_TREE

        IMPORTING NODE_KEY ITEM_NAME.

ENDCLASS.                    “LCL_TREE_EVENT_RECEIVER DEFINITION

*———————————————————————-*

*       CLASS LCL_TREE_EVENT_RECEIVER IMPLEMENTATION

*———————————————————————-*

*

*———————————————————————-*

CLASS LCL_TREE_EVENT_RECEIVER IMPLEMENTATION.

  METHOD  HANDLE_BUTTON_CLICK.

    PERFORM HANDLE_BUTTON_CLICK USING NODE_KEY ITEM_NAME.

  ENDMETHOD.                    “HANDLE_BUTTON_CLICK

ENDCLASS.                    “LCL_TREE_EVENT_RECEIVER IMPLEMENTATION

_M#]

2. 객체 선언 및 Container 할당

 – 예제는 1행1열이 Tree, 1행2열이 ALV Grid.


[#M_더보기|접기|

*   create a container for the tree control

    CREATE OBJECT GO_DOCKING_CONTAINER1

      EXPORTING

        SIDE      = GO_DOCKING_CONTAINER1->DOCK_AT_LEFT

        EXTENSION = 2000.

    IF SY-SUBRC <> 0.

      MESSAGE A000.

    ENDIF.

*   화면 분할.

    CREATE OBJECT GO_SPLITTER1

      EXPORTING

        PARENT  = GO_DOCKING_CONTAINER1

        ROWS    = 1

        WIDTH   = 2000

        COLUMNS = 2.

*   1행 1열(Tree용).

    CALL METHOD GO_SPLITTER1->GET_CONTAINER

      EXPORTING

        ROW       = 1

        COLUMN    = 1

      RECEIVING

        CONTAINER = GO_CONTAINER1.

*   1행 2열(ALV Grid용).

    CALL METHOD GO_SPLITTER1->GET_CONTAINER

      EXPORTING

        ROW       = 1

        COLUMN    = 2

      RECEIVING

        CONTAINER = GO_CONTAINER2.

    CALL METHOD GO_SPLITTER1->SET_COLUMN_WIDTH

      EXPORTING

        ID    = 1

        WIDTH = 15.

*   ALV Grid.

    CREATE OBJECT GO_GRID1

      EXPORTING

        I_PARENT = GO_CONTAINER2.

_M#]

3. Tree Root, Node, Item 구성


[#M_더보기|접기|

    IF GO_TREE IS NOT BOUND.

      CREATE OBJECT GO_TREE.

      PERFORM CREATE_AND_INIT_TREE.

    ENDIF.

*  &———————————————————————*

*  &      Form  CREATE_AND_INIT_TREE

*  &———————————————————————*

*         text

*  ———————————————————————-*

  FORM CREATE_AND_INIT_TREE.

    DATA: PT_NODE_TABLE       TYPE TREEV_NTAB,

          PT_ITEM_TABLE       TYPE ITEM_TABLE_TYPE,

          LS_EVENT            TYPE CNTL_SIMPLE_EVENT,

          LT_EVENTS           TYPE CNTL_SIMPLE_EVENTS,

          LS_HIERARCHY_HEADER TYPE TREEV_HHDR.


*   setup the hierarchy header

    LS_HIERARCHY_HEADER-HEADING = ‘수익성분석 작업’.

    ” heading

    LS_HIERARCHY_HEADER-WIDTH = 30.         ” width: 30 characters


*   create a tree control


*   After construction, the control contains one column in the

*   hierarchy area. The name of this column

*   is defined via the constructor parameter HIERACHY_COLUMN_NAME.

    CREATE OBJECT GO_COLUMN_TREE

      EXPORTING

        PARENT                      = GO_CONTAINER1

        NODE_SELECTION_MODE         = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_SINGLE

        ITEM_SELECTION              = ‘X’

        HIERARCHY_COLUMN_NAME       = C_COLUMN-COLUMN1

        HIERARCHY_HEADER            = LS_HIERARCHY_HEADER

      EXCEPTIONS

        CNTL_SYSTEM_ERROR           = 1

        CREATE_ERROR                = 2

        FAILED                      = 3

        ILLEGAL_NODE_SELECTION_MODE = 4

        ILLEGAL_COLUMN_NAME         = 5

        LIFETIME_ERROR              = 6.

    IF SY-SUBRC <> 0.

      MESSAGE A000.

    ENDIF.


*   define the Lt_EVENTS which will be passed to the backend

*    ” node double click

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_NODE_DOUBLE_CLICK.

*    LS_EVENT-APPL_EVENT = ‘X’. ” process PAI if ls_EVENT occurs

*    APPEND LS_EVENT TO LT_EVENTS.


*    ” item double click

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_ITEM_DOUBLE_CLICK.

*    LS_EVENT-APPL_EVENT = ‘X’.

*    APPEND LS_EVENT TO LT_EVENTS.


*    ” expand no children

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_EXPAND_NO_CHILDREN.

*    LS_EVENT-APPL_EVENT = ‘X’.

*    APPEND LS_EVENT TO LT_EVENTS.


*    ” link click

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_LINK_CLICK.

*    LS_EVENT-APPL_EVENT = ‘X’.

*    APPEND LS_EVENT TO LT_EVENTS.


    ” button click

    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_BUTTON_CLICK.

    LS_EVENT-APPL_EVENT = ‘X’.

    APPEND LS_EVENT TO LT_EVENTS.


*    ” checkbox change

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_CHECKBOX_CHANGE.

*    LS_EVENT-APPL_EVENT = ‘X’.

*    APPEND LS_EVENT TO LT_EVENTS.


*    ” header click

*    LS_EVENT-EVENTID = CL_GUI_COLUMN_TREE=>EVENTID_HEADER_CLICK.

*    LS_EVENT-APPL_EVENT = ‘X’.

*    APPEND LS_EVENT TO LT_EVENTS.


    CALL METHOD GO_COLUMN_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 A000.

    ENDIF.


*   assign ls_EVENT handlers in the application class to each desired ls_EVENT

*    SET HANDLER GO_tree->HANDLE_NODE_DOUBLE_CLICK  FOR GO_COLUMN_TREE.

*    SET HANDLER GO_tree->HANDLE_ITEM_DOUBLE_CLICK  FOR GO_COLUMN_TREE.

*    SET HANDLER GO_tree->HANDLE_EXPAND_NO_CHILDREN FOR GO_COLUMN_TREE.

*    SET HANDLER GO_tree->HANDLE_LINK_CLICK         FOR GO_COLUMN_TREE.

    SET HANDLER GO_TREE->HANDLE_BUTTON_CLICK       FOR GO_COLUMN_TREE.

*    SET HANDLER GO_tree->HANDLE_CHECKBOX_CHANGE    FOR GO_COLUMN_TREE.

*    SET HANDLER GO_tree->HANDLE_HEADER_CLICK       FOR GO_COLUMN_TREE.


*   Node, Child 설정.

    CLEAR: PT_NODE_TABLE, PT_ITEM_TABLE.

    PERFORM BUILD_NODE_AND_PT_ITEM_TABLE TABLES PT_NODE_TABLE PT_ITEM_TABLE.


    CALL METHOD GO_COLUMN_TREE->ADD_NODES_AND_ITEMS

      EXPORTING

        NODE_TABLE                     = PT_NODE_TABLE

        ITEM_TABLE                     = PT_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.

    IF SY-SUBRC <> 0.

      MESSAGE A000.

    ENDIF.


*   expand the node with key ‘Root’

    CALL METHOD GO_COLUMN_TREE->EXPAND_NODE

      EXPORTING

        NODE_KEY            = C_NODEKEY-ROOT

      EXCEPTIONS

        FAILED              = 1

        ILLEGAL_LEVEL_COUNT = 2

        CNTL_SYSTEM_ERROR   = 3

        NODE_NOT_FOUND      = 4

        CANNOT_EXPAND_LEAF  = 5.

    IF SY-SUBRC <> 0.

      MESSAGE A000.

    ENDIF.


  ENDFORM.                    ” CREATE_AND_INIT_TREE

*  &———————————————————————*

*  &      Form  BUILD_NODE_AND_PT_ITEM_TABLE

*  &———————————————————————*

*         text

*  ———————————————————————-*

  FORM BUILD_NODE_AND_PT_ITEM_TABLE TABLES PT_NODE_TABLE TYPE TREEV_NTAB

                                           PT_ITEM_TABLE TYPE ITEM_TABLE_TYPE.

    DATA: LS_NODE TYPE TREEV_NODE,

          LS_ITEM TYPE MTREEITM.

    FIELD-SYMBOLS: <FS_CHILD>.

    FIELD-SYMBOLS: <FS_ICON>.

    DATA: LV_CHILD(30).

    DATA: LV_TEXT(30).

    DATA: LV_ICON(30).


*   Root Node.

    PERFORM BUILD_NODE_TABLE TABLES PT_NODE_TABLE

                              USING C_NODEKEY-ROOT ‘X’ ” ”.


    READ TABLE GT_DISPLAY INTO GS_DISPLAY INDEX 1.


    LOOP AT GT_5499 INTO GS_5499.

*   Node.

      CLEAR: LV_CHILD, LV_TEXT.

      CONCATENATE ‘C_NODEKEY-CHILD’ GS_5499-SFLAG INTO LV_CHILD.

      CONCATENATE GS_5499-SFLAG GS_5499-TEXT INTO LV_TEXT SEPARATED BY ‘.’.


      ASSIGN (LV_CHILD) TO <FS_CHILD>.


      PERFORM BUILD_NODE_TABLE TABLES PT_NODE_TABLE

                                USING <FS_CHILD> ‘X’ C_NODEKEY-ROOT

                                      CL_GUI_COLUMN_TREE=>RELAT_LAST_CHILD.

*   Item.

*   출력 데이터를 검색하여 작업 단계 확인.

      CLEAR: LV_ICON.

      CONCATENATE ‘GV_ICON’ GS_5499-SFLAG INTO LV_ICON.

      ASSIGN (LV_ICON) TO <FS_ICON>.


      IF GS_DISPLAY-SFLAG GE GS_5499-SFLAG.

*      IF ZCOT5400-SFLAG GE GS_5499-SFLAG.

        <FS_ICON> = GC_ICON_CHECKED.    ” @01@, ICON_CHECKED.


      ELSE.

        <FS_ICON> = GC_ICON_INCOMPLETE. ” @02@, ICON_INCOMPLETE.

      ENDIF.


      PERFORM BUILD_ITEM_TABLE TABLES PT_ITEM_TABLE

                                USING <FS_CHILD> C_COLUMN-COLUMN1

                                      CL_GUI_COLUMN_TREE=>ITEM_CLASS_BUTTON

                                      LV_TEXT

                                      <FS_ICON>.

    ENDLOOP.  ” LOOP AT GT_5499 INTO GS_5499.


  ENDFORM.                    ” BUILD_NODE_AND_PT_ITEM_TABLE

*  &———————————————————————*

*  &      Form  BUILD_NODE_TABLE

*  &———————————————————————*

*         text

*  ———————————————————————-*

  FORM BUILD_NODE_TABLE TABLES PT_TABLE TYPE TREEV_NTAB

                         USING PV_NODEKEY PV_ISFOLDER PV_RELAKEY PV_RELATSHIP.

    DATA: LS_NODE TYPE TREEV_NODE.


    LS_NODE-NODE_KEY = PV_NODEKEY.

    LS_NODE-HIDDEN = ‘ ‘.        ” The node is visible,

    LS_NODE-DISABLED = ‘ ‘.      ” selectable,

    CLEAR LS_NODE-N_IMAGE.       ” Folder-/ Leaf-Symbol in state “closed”:


    IF PV_NODEKEY = C_NODEKEY-ROOT.

      CLEAR LS_NODE-RELATKEY.      ” Special case: A root node has no parent

      CLEAR LS_NODE-RELATSHIP.     ” node.

      LS_NODE-ISFOLDER = PV_ISFOLDER.      ” a folder.


    ELSE.

      LS_NODE-RELATKEY = PV_RELAKEY.      ” Special case: A root node has no parent

      LS_NODE-RELATSHIP = PV_RELATSHIP.     ” node.

      CLEAR: LS_NODE-ISFOLDER.

    ENDIF.


    CLEAR LS_NODE-EXP_IMAGE.     ” Folder-/ Leaf-Symbol in state “open”:

    CLEAR LS_NODE-EXPANDER.      ” see below.


    APPEND LS_NODE TO PT_TABLE.


  ENDFORM.                    ” BUILD_NODE_TABLE

*  &———————————————————————*

*  &      Form  BUILD_ITEM_TABLE

*  &———————————————————————*

*         text

*  ———————————————————————-*

  FORM BUILD_ITEM_TABLE TABLES PT_TABLE TYPE ITEM_TABLE_TYPE

                         USING PV_NODEKEY_CHILD1

                               PV_COLUMN_COLUMN1

                               PV_ITEM_CLASS

                               PV_TEXT

                               PV_ICON.

    DATA: LS_ITEM TYPE MTREEITM.


    CLEAR LS_ITEM.

    LS_ITEM-NODE_KEY = PV_NODEKEY_CHILD1.

    LS_ITEM-ITEM_NAME = PV_COLUMN_COLUMN1.

    LS_ITEM-CLASS = PV_ITEM_CLASS.

    LS_ITEM-EDITABLE = ‘ ‘.

    LS_ITEM-TEXT = PV_TEXT.


*   ICON.

    LS_ITEM-T_IMAGE = PV_ICON.


*   Data 추출시 버튼 비활성화.

    IF R_R2 = ‘X’.

      LS_ITEM-DISABLED = ‘X’.

    ENDIF.


    APPEND LS_ITEM TO PT_TABLE.


  ENDFORM.                    ” BUILD_ITEM_TABLE

_M#]

4. Tree Refresh 방법

*   Tree 재구성.

        IF GO_COLUMN_TREE IS BOUND.

          GO_COLUMN_TREE->FREE( ).

        ENDIF.

        PERFORM CREATE_AND_INIT_TREE. ” Reuse.


Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
개발자
개발자
9 years ago

REFRESH 기능에서 이건 재생성이지 REFRESH 가 아니지 않습니까!!

Thinkmaniac
9 years ago
Reply to  개발자

네, 단어 선택이 별로 안좋았네요. ^^