SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Simple Tree Template



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Mar 04, 2009 5:14 pm    Post subject: Simple Tree Template Reply with quote

Version 1.0
Author WATTO
Source from: http: /www.watto.org/program/abap/download/Z_TREE_TEMPLATE.abap

Description: A template program for building a report that has a simple tree in it. A simple tree can not have columns, it is only a tree.

Code:
REPORT z_tree_template.

************************************************************************
***
*** VARIABLES
***
************************************************************************



*** CLASSES ***
CLASS:
  cl_tree_events DEFINITION DEFERRED,
  cl_gui_cfw     DEFINITION LOAD.


*** INTERNAL TABLES ***
DATA:
  v_nodes TYPE mtreesnode,
  i_nodes TYPE STANDARD TABLE OF mtreesnode.


*** OBJECTS ***
DATA:
  o_tree_listener TYPE REF TO cl_tree_events,
  o_tree          TYPE REF TO cl_gui_simple_tree.



************************************************************************
***
*** CLASSES
***
************************************************************************



*----------------------------------------------------------------------
*       CLASS CL_TREE_EVENTS DEFINITION
*----------------------------------------------------------------------
* [+] Class for handling events on o_tree
*----------------------------------------------------------------------
CLASS cl_tree_events DEFINITION.

  PUBLIC SECTION.
    METHODS:
      handle_node_double_click
        FOR EVENT node_double_click
        OF cl_gui_simple_tree
        IMPORTING node_key.

ENDCLASS.                    "cl_tree_events DEFINITION


*----------------------------------------------------------------------
*       CLASS CL_TREE_EVENTS IMPLEMENTATION
*----------------------------------------------------------------------
* [+] Class for handling events on o_tree
*----------------------------------------------------------------------
CLASS cl_tree_events IMPLEMENTATION.


*---------------------------------------------------------------------*
*       METHOD HANDLE_NODE_DOUBLE_CLICK
*---------------------------------------------------------------------*
* [+] Processes a double-click on a node
*---------------------------------------------------------------------*
  METHOD  handle_node_double_click.
    WRITE: / node_key.
  ENDMETHOD.                    "handle_node_double_click


ENDCLASS.                    "cl_tree_events IMPLEMENTATION



************************************************************************
***
*** MAIN PROCESSING
***
************************************************************************



*----------------------------------------------------------------------
*       START-OF-SELECTION
*----------------------------------------------------------------------
START-OF-SELECTION.
* Create the event listener object
  CREATE OBJECT o_tree_listener.

  SET SCREEN 100.



************************************************************************
***
*** DOCKING AND TREE OBJECT METHODS
***
************************************************************************



*----------------------------------------------------------------------
*       FORM BUILD_WINDOW
*----------------------------------------------------------------------
* [+] Constructs and loads the data into the window...
*     [+] Builds the tree
*     [+] Loads the tree nodes
*----------------------------------------------------------------------
FORM build_window.

* Local variables
  DATA: li_events TYPE cntl_simple_events, "events
        lv_events TYPE cntl_simple_event,  "events
        lv_repid  TYPE syrepid. "report ID

* Setting variables
  lv_repid = sy-repid.

* Create the tree object
  CREATE OBJECT o_tree
    EXPORTING
      parent              = parent_container
      node_selection_mode = cl_gui_simple_tree=>node_sel_mode_single.

* Define the events to listen for
  lv_events-eventid = cl_gui_simple_tree=>eventid_node_double_click.
  lv_events-appl_event = 'X'. " process PAI if event occurs
  APPEND lv_events TO li_events.

  CALL METHOD o_tree->set_registered_events
    EXPORTING
      events = li_events.

* Set the event listeners
  SET HANDLER o_tree_listener->handle_node_double_click FOR o_tree.

* Build the tree
  PERFORM build_tree.

ENDFORM.                    "build_window



*----------------------------------------------------------------------
*       FORM BUILD_TREE
*----------------------------------------------------------------------
* [+] Loads the tree nodes
*----------------------------------------------------------------------
FORM build_tree.

* NODES ARE INSERTED IN THE ORDER SHOWN.
* DO NOT DEFINE A CHILD BEFORE ITS PARENT NODE!

* Root Node
  CLEAR v_nodes.
  v_nodes-node_key = 'Root'.
  v_nodes-isfolder = 'X'.
  v_nodes-text = 'Root Node'.
  APPEND v_nodes TO i_nodes.

* First Branch
*                      folder  code   parent   image      name
  PERFORM add_node USING 'X' 'Child1' 'Root'   ''     'Child Node 1'.
  PERFORM add_node USING ' ' 'Leaf1'  'Child1' ''     'Leaf Node 1'.
  PERFORM add_node USING ' ' 'Leaf2'  'Child1' '@10@' 'Leaf Node 2'.

* Second Branch
*                      folder  code   parent  image   name
  PERFORM add_node USING 'X' 'Child2' 'Root'   '' 'Child Node 2'.
  PERFORM add_node USING ' ' 'Leaf3'  'Child2' '' 'Leaf Node 3'.

* Adds the nodes to the tree.
  CALL METHOD o_tree->add_nodes
    EXPORTING
      table_structure_name = 'MTREESNODE'
      node_table           = i_nodes.

ENDFORM.                    "build_tree



*----------------------------------------------------------------------
*       FORM ADD_NODE
*----------------------------------------------------------------------
* [+] Adds a node to the tree
*----------------------------------------------------------------------
FORM add_node
  USING
    p_folder TYPE c
    p_code   TYPE c
    p_parent TYPE c
    p_image  TYPE c
    p_name   TYPE c.

  CLEAR:
    v_nodes.

  v_nodes-node_key  = p_code.
  v_nodes-relatkey  = p_parent.
  v_nodes-relatship = cl_gui_simple_tree=>relat_last_child.
  v_nodes-isfolder  = p_folder.
  v_nodes-text      = p_name.
  v_nodes-n_image   = p_image.

  APPEND v_nodes TO i_nodes.

ENDFORM.                    "add_node



************************************************************************
***
*** MODULES
***
************************************************************************



*----------------------------------------------------------------------
*       MODULE LOAD_TREE
*----------------------------------------------------------------------
* [+] Loads the tree
*----------------------------------------------------------------------
MODULE load_tree OUTPUT.
  SET PF-STATUS 'MAIN'.

  IF o_tree IS INITIAL.
*   build the tree
    PERFORM build_window.
  ENDIF.

ENDMODULE.                    "load_tree OUTPUT



*----------------------------------------------------------------------
*       MODULE PROCESS_EVENTS_0100
*----------------------------------------------------------------------
* [+] Processes the events from the dock/tree
*----------------------------------------------------------------------
MODULE process_events_0100 INPUT.

  DATA: lv_tree_return_code TYPE i.

* If the tree made an event that affects PAI,
* then dont process the event here.
  CALL METHOD cl_gui_cfw=>dispatch
    IMPORTING
      return_code = lv_tree_return_code.

  IF lv_tree_return_code <> cl_gui_cfw=>rc_noevent.
    CLEAR v_ok_code.
    EXIT.
  ENDIF.

  CASE v_ok_code.
    WHEN 'BACK'.
      CLEAR o_tree.
      LEAVE TO SCREEN 0.
  ENDCASE.

  CLEAR v_ok_code.
ENDMODULE.                    "process_events_0100 INPUT
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.