ALV Tree Report--clicking on a row....

Hello Experts,
i have a alv tree report.my requirement is,
"Selecting a row means clicking on record  and then click on a another button called YES ,For other functionality i need to capture the row '.
How can i solve this  problem.
Thanks,
Sridhar.

hi check this..
REPORT  z_simpletree.
type pool declarations for tree
TYPE-POOLS : fibs,stree.
*Data declaration for additional node information
DATA : t_node TYPE snodetext.
*Internal table and wa decl for nodes
DATA : it_node LIKE TABLE OF t_node INITIAL SIZE 0,
       wa_node LIKE t_node.
*Internal table and wa decl for Education table PA0022
DATA : it_0022 TYPE STANDARD TABLE OF pa0022 INITIAL SIZE 0,
       wa_0022 TYPE pa0022.
*Internal table and wa decl for text table t517x
DATA : it_517x TYPE STANDARD TABLE OF t517x INITIAL SIZE 0,
       wa_517x TYPE t517x.
*Internal table and wa decl for text table t517T
DATA : it_517t TYPE STANDARD TABLE OF t517t INITIAL SIZE 0,
       wa_517t TYPE t517t.
*Internal table and wa decl for text table t519T
DATA : it_519t TYPE STANDARD TABLE OF t519t INITIAL SIZE 0,
       wa_519t TYPE t519t.
*initialization event
INITIALIZATION.
*Start of selection  event
START-OF-SELECTION.
*Select the data for tree
  PERFORM fetch_data.
*Build the hierarchy for tree
  PERFORM build_hierarchy.
*Build Tree for display
  PERFORM build_tree.
*&      Form  fetch_data
      text
-->  p1        text
<--  p2        text
FORM fetch_data .
*select data from PA0022
  SELECT * FROM pa0022 INTO CORRESPONDING FIELDS OF TABLE it_0022
   UP TO 50 ROWS.
*select data from T517x
  SELECT * FROM t517x INTO CORRESPONDING FIELDS OF TABLE it_517x
   WHERE langu = 'E'.
*select data from T517T
  SELECT * FROM t517t INTO CORRESPONDING FIELDS OF TABLE it_517t
   WHERE sprsl = 'E'.
*select data from T519t
  SELECT * FROM t519t INTO CORRESPONDING FIELDS OF TABLE it_519t
   WHERE sprsl = 'E'.
  ENDFORM.                    " fetch_data
*&      Form  build_hierarchy
      text
-->  p1        text
<--  p2        text
FORM build_hierarchy .
*Building the nodes and hierarchy for tree
  CLEAR : it_node[],
  wa_node.
  wa_node-type = 'T'.
  wa_node-name = 'Education'.
  wa_node-tlevel = '01'.
  wa_node-nlength = '15'.
  wa_node-color = '4'.
  wa_node-text = 'Infotype 0022'.
  wa_node-tlength ='20'.
  wa_node-tcolor = 3.
  APPEND wa_node TO it_node.
  CLEAR wa_node.
*Filling the values of internal table into tree
  LOOP AT it_0022 INTO wa_0022.
    wa_node-type = 'P'.
    wa_node-name = 'PERNR'.
    wa_node-tlevel = '02'.
    wa_node-nlength = '8'.
    wa_node-color = '1'.
    wa_node-text = wa_0022-pernr.
    wa_node-tlength ='20'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
*Filling the text of T517t
    READ TABLE it_517t INTO wa_517t WITH KEY slart = wa_0022-slart.
    wa_node-type = 'P'.
    wa_node-name = wa_0022-slart.
    wa_node-tlevel = '03'.
    wa_node-nlength = '8'.
    wa_node-color = '1'.
    wa_node-text = wa_517t-stext.
    wa_node-tlength ='40'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
*Filling the text of T519t
    READ TABLE it_519t INTO wa_519t WITH KEY slabs = wa_0022-slabs.
    wa_node-type = 'P'.
    wa_node-name = wa_0022-slabs.
    wa_node-tlevel = '04'.
    wa_node-nlength = '8'.
    wa_node-color = '2'.
    wa_node-text = wa_519t-stext.
    wa_node-tlength ='40'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
*Filling the text of T517x
    READ TABLE it_517x INTO wa_517x WITH KEY faart = wa_0022-sltp1.
    wa_node-type = 'P'.
    wa_node-name = wa_0022-sltp1.
    wa_node-tlevel = '05'.
    wa_node-nlength = '8'.
    wa_node-color = '1'.
    wa_node-text = wa_517x-ftext.
    wa_node-tlength ='40'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
    wa_node-type = 'P'.
    wa_node-tlevel = '06'.
    wa_node-nlength = '8'.
    wa_node-color = '1'.
    wa_node-text = '% Completed'.
    wa_node-tlength ='15'.
    wa_node-tcolor = 4.
    APPEND wa_node TO it_node.
    CLEAR wa_node.
    ENDLOOP.
    ENDFORM.                    " build_hierarchy
*&      Form  build_tree
      text
-->  p1        text
<--  p2        text
FORM build_tree .
*Fm for constructing the tree
  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
     nodetab = it_node.
  IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*FM for displaying the tree
  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
      callback_program     = sy-repid
      check_duplicate_name = '1'
      color_of_node        = '3'
      color_of_mark        = '3'
      color_of_link        = '1'
      color_of_match       = '5'
      node_length          = 30
      text_length          = 75
      use_control          = 'L'.ENDFORM.                    " build_tree
regards,
venkat

Similar Messages

  • Development of alv tree report using classes from basics

    Hi,
    Need a simple ALV tree report by showing the reason for why we are using the classse so that i can build a ALV report in the same manner.
    i have the data from MARA for given materials and their descriptions.Now in the basiv out put MARA information should come and tree out put for the material description when the user selects the maerial.
    A hot spot should come on the material and if he opts click the material then MM03 out put should come.
    Help me out in this regard
    Regards
    Naren

    Ok, but the importance of ABAP OO, should not be taken from an example ALV tree, but more in general. There are several good  articles on this on SCN. But for example in this particular case (ALV Tree), you should already see the importance as far as object instances and inheritance is concerned. Without much work, you can create an instance of an ALV tree, and all the attributes, methods etc. are there for use. Some of the methods / attributes are inherited from other superclasses.
    There are propably even more things to be mentioned here which emphasizes the importance of ABAP OO in ALV tree, but as far as I'm concerned, this is about it for me.

  • ALV Tree Report without using ABAP Objects

    Hi all,
    I want to know the name of a function module to create ALV Tree in SE38 as a report. I am required to create this ALV Tree Report without using ABAP OBJECTS. Can u pls help me as early as possible.

    Hi
    see this link
    http://www.sapdev.co.uk/reporting/alv/alvtree.htm
    *& Report  ZBCALV_TREE
    REPORT  ZBCALV_TREE.
    class cl_gui_column_tree definition load.
    class cl_gui_cfw definition load.
    data tree1  type ref to cl_gui_alv_tree.
    data mr_toolbar type ref to cl_gui_toolbar.
    include <icon>.
    include bcalv_toolbar_event_receiver.
    include bcalv_tree_event_receiver.
    data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.
    data: gt_VBAK  type VBAK occurs 0,      "Output-Table
          gt_fieldcatalog type lvc_t_fcat, "Fieldcatalog
          ok_code like sy-ucomm.           "OK-Code
    start-of-selection.
    end-of-selection.
      call screen 100.
    *&      Module  STATUS_0100  OUTPUT
          text
    module STATUS_0100 output.
      SET PF-STATUS 'MAIN'.
    if tree1 is initial.
        perform Zinit_tree.
      endif.
      call method cl_gui_cfw=>flush.
    endmodule.                 " STATUS_0100  OUTPUT
    *&      Form  Zinit_tree
          text
    -->  p1        text
    <--  p2        text
    form Zinit_tree .
    perform Zbuild_fieldcatalog.
    create container for alv-tree
    data: l_tree_container_name(30) type c,
            l_custom_container type ref to cl_gui_custom_container.
      l_tree_container_name = 'TREE1'.
    if sy-batch is initial.
        create object l_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'.                        "#EC NOTEXT
        endif.
      endif.
    create tree control
      create object tree1
        exporting
            parent              = l_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = ''
            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.
    create Hierarchy-header
      data l_hierarchy_header type treev_hhdr.
      perform zbuild_hierarchy_header changing l_hierarchy_header.
    create info-table for html-header
      data: lt_list_commentary type slis_t_listheader,
            l_logo             type sdydo_value.
      perform Zbuild_comment using
                     lt_list_commentary
                     l_logo.
    repid for saving variants
      data: ls_variant type disvariant.
      ls_variant-report = sy-repid.
    create emty tree-control
      call method tree1->set_table_for_first_display
        exporting
          is_hierarchy_header = l_hierarchy_header
          it_list_commentary  = lt_list_commentary
          i_logo              = l_logo
          i_background_id     = 'ALV_BACKGROUND'
          i_save              = 'A'
          is_variant          = ls_variant
        changing
          it_outtab           = gt_VBAK "table must be emty !!
          it_fieldcatalog     = gt_fieldcatalog.
    create hierarchy
      perform Zcreate_hierarchy.
    add own functioncodes to the toolbar
      perform zchange_toolbar.
    register events
      perform zregister_events.
    endform.                    " Zinit_tree
    *&      Form  Zbuild_fieldcatalog
          text
    -->  p1        text
    <--  p2        text
    form Zbuild_fieldcatalog .
    get fieldcatalog
      call function 'LVC_FIELDCATALOG_MERGE'
        exporting
          i_structure_name = 'VBAK'
        changing
          ct_fieldcat      = gt_fieldcatalog.
      sort gt_fieldcatalog by scrtext_l.
    change fieldcatalog
      data: ls_fieldcatalog type lvc_s_fcat.
      loop at gt_fieldcatalog into ls_fieldcatalog.
        case ls_fieldcatalog-fieldname.
          when 'AUART' .
            ls_fieldcatalog-no_out = 'X'.
            ls_fieldcatalog-key    = ''.
        endcase.
        modify gt_fieldcatalog from ls_fieldcatalog.
      endloop.
    endform.                    " Zbuild_fieldcatalog
    *&      Form  zbuild_hierarchy_header
          text
         <--P_L_HIERARCHY_HEADER  text
    form zbuild_hierarchy_header changing
                                   p_hierarchy_header type treev_hhdr.
      p_hierarchy_header-heading = 'Hierarchy Header'.          "#EC NOTEXT
      p_hierarchy_header-tooltip =
                             'This is the Hierarchy Header !'.  "#EC NOTEXT
      p_hierarchy_header-width = 30.
      p_hierarchy_header-width_pix = ''.
    endform.                    " zbuild_hierarchy_header
    *&      Form  Zbuild_comment
          text
         -->P_LT_LIST_COMMENTARY  text
         -->P_L_LOGO  text
    form Zbuild_comment   using
                           pt_list_commentary type slis_t_listheader
                           p_logo             type sdydo_value.
    data: ls_line type slis_listheader.
    LIST HEADING LINE: TYPE H
      clear ls_line.
      ls_line-typ  = 'H'.
    LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'ALV-tree-demo: flight-overview'.          "#EC NOTEXT
      append ls_line to pt_list_commentary.
    STATUS LINE: TYPE S
      clear ls_line.
      ls_line-typ  = 'S'.
      ls_line-key  = 'valid until'.                             "#EC NOTEXT
      ls_line-info = 'January 29 1999'.                         "#EC NOTEXT
      append ls_line to pt_list_commentary.
      ls_line-key  = 'time'.
      ls_line-info = '2.00 pm'.                                 "#EC NOTEXT
      append ls_line to pt_list_commentary.
    ACTION LINE: TYPE A
      clear ls_line.
      ls_line-typ  = 'A'.
    LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'actual data'.                             "#EC NOTEXT
      append ls_line to pt_list_commentary.
      p_logo = 'ENJOYSAP_LOGO'.
    endform.                    " Zbuild_comment
    *&      Form  Zcreate_hierarchy
          text
    -->  p1        text
    <--  p2        text
    form Zcreate_hierarchy .
    data: ls_vbak type vbak,
          lt_vbak  type vbak occurs 0.
    get data
      select * from vbak into table lt_vbak
                            up to 200 rows .                "#EC CI_NOWHERE
      sort lt_vbak by AUART.
    add data to tree
      data: l_AUART_key type lvc_nkey.
    loop at lt_vbak into ls_vbak.
        on change of ls_vbak-AUART.
          perform Zadd_AUART_line using   ls_vbak
                                  changing l_AUART_key.
        endon.
      endloop.
    calculate totals
      call method tree1->update_calculations.
    this method must be called to send the data to the frontend
      call method tree1->frontend_update.
    endform.                    " Zcreate_hierarchy
    *&      Form  Zadd_AUART_line
          text
         -->P_LS_vbak  text
         -->P_0379   text
         <--P_L_AUART_KEY  text
    form Zadd_AUART_line  using    p_ls_vbak type vbak
                                   p_relat_key type lvc_nkey
                         changing  p_node_key type lvc_nkey.
      data: l_node_text type lvc_value,
            ls_vbak type vbak.
    set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image = '@3P@'.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      ls_item_layout-style   =
                            cl_gui_column_tree=>style_intensifd_critical.
      append ls_item_layout to lt_item_layout.
    add node
      l_node_text =  p_ls_vbak-AUART.
      data: ls_node type lvc_s_layn.
      ls_node-n_image   = space.
      ls_node-exp_image = space.
      call method tree1->add_node
        exporting
          i_relat_node_key = p_relat_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = l_node_text
          is_outtab_line   = ls_vbak
          is_node_layout   = ls_node
          it_item_layout   = lt_item_layout
        importing
          e_new_node_key   = p_node_key .
    endform.                    " Zadd_AUART_line
    *&      Form  zchange_toolbar
          text
    -->  p1        text
    <--  p2        text
    form zchange_toolbar .
    get toolbar control
      call method tree1->get_toolbar_object
        importing
          er_toolbar = mr_toolbar.
      check not mr_toolbar is initial.
    add seperator to toolbar
      call method mr_toolbar->add_button
        exporting
          fcode     = ''
          icon      = ''
          butn_type = cntb_btype_sep
          text      = ''
          quickinfo = 'This is a Seperator'.                    "#EC NOTEXT
    add Standard Button to toolbar (for Delete Subtree)
      call method mr_toolbar->add_button
        exporting
          fcode     = 'DELETE'
          icon      = '@18@'
          butn_type = cntb_btype_button
          text      = ''
          quickinfo = 'Delete subtree'.                         "#EC NOTEXT
    add Dropdown Button to toolbar (for Insert Line)
      call method mr_toolbar->add_button
        exporting
          fcode     = 'INSERT_LC'
          icon      = '@17@'
          butn_type = cntb_btype_dropdown
          text      = ''
          quickinfo = 'Insert Line'.                            "#EC NOTEXT
    set event-handler for toolbar-control
      create object toolbar_event_receiver.
      set handler toolbar_event_receiver->on_function_selected
                                                          for mr_toolbar.
      set handler toolbar_event_receiver->on_toolbar_dropdown
                                                          for mr_toolbar.
    endform.                    " zchange_toolbar
    *&      Form  zregister_events
          text
    -->  p1        text
    <--  p2        text
    form zregister_events .
    define the events which will be passed to the backend
      data: lt_events type cntl_simple_events,
              l_event type cntl_simple_event.
    define the events which will be passed to the backend
      l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_click.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
      append l_event to lt_events.
      call method tree1->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.
    set Handler
      data: l_event_receiver type ref to lcl_tree_event_receiver.
      create object l_event_receiver.
      set handler l_event_receiver->handle_node_ctmenu_request
                                                            for tree1.
      set handler l_event_receiver->handle_node_ctmenu_selected
                                                            for tree1.
      set handler l_event_receiver->handle_item_ctmenu_request
                                                            for tree1.
      set handler l_event_receiver->handle_item_ctmenu_selected
                                                            for tree1.
    endform.                    " zregister_events
    *&      Module  USER_COMMAND_0100  INPUT
          text
    module USER_COMMAND_0100 input.
    ok_code  = sy-ucomm.
    clear sy-ucomm.
    case ok_code.
        when 'EXIT' or 'BACK' or 'CANC'.
          perform Zexit_program.
        when others.
          call method cl_gui_cfw=>dispatch.
      endcase.
      clear ok_code.
      call method cl_gui_cfw=>flush.
    endmodule.                 " USER_COMMAND_0100  INPUT
    *&      Form  Zexit_program
          text
    -->  p1        text
    <--  p2        text
    form Zexit_program .
      call method tree1->free.
      leave program.
    endform.                    " Zexit_program
    <b>Reward if usefull</b>

  • Hierarchial ALV  Tree Report.

    Hi!
    iam designing a module pool to get all the info of the idoc like status record control record etc.the 3 rd screen would be a hierarchial tree structure.All the data would be retrieved from Z tables.
    My requirement is on the left side of the pane the tree would contain 6 tables as nodes and these would be constant for all the idoc numbers.On the right side of the screen i would have to populate the complete data from these tables.
    When user clicks on the first table only that table data needs to appear.This would be only a display report.
    Plz tell me if this logic would work
    I will create the tree structure on the left side of the pane with all the 6 tables as default.I would also define a subscren on the right side and would call a table control for the respective tables along with the data populated in them.
    Now can i link the double click event of the tree ie the table name to populate the table control in the subscreen.
    Please provide suggestions.
    thanks
    kedar

    HI Kedar,
    What u r trying to do is going to work.
    Evn I tried to do the same, but since I ahve less knowledge in ALV class I couldnt do it.
    U can refer to DWDM, it is for demo programs...it has ALV tree method

  • ALV-Tree Node click not working

    Hi All,
    I am displaying the data in ALV tree. When the user click on the node i want to capture some event and method in which i have to do some coding. Can you tell me which method and  event i should use to achieve this functionality. its bit urgent.
    Immediate response will be apprecited.
    Regards,
    Ranjan

    Hi ,
    I have gone through the link. I have done the below part in my coding even though when i double click on the node, the event node_double_click is not getting triggered. Kindly suggest me what i have missed.
    1) Register event with tree instance:
    Register event for NODE_DOUBLE_CLICK
    l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
    APPEND l_event TO lt_events.
    (2) Set handler for event:
    SET HANDLER l_event_receiver->handle_node_double_click FOR tree1
    (3) Define and implement event handler method:
    METHODS handle_node_double_click
    FOR EVENT node_double_click OF cl_gui_alv_tree
    IMPORTING node_key.
    ENDCLASS. "lcl_tree_event_receiver DEFINITION
    CLASS lcl_tree_event_receiver IMPLEMENTATION
    CLASS lcl_tree_event_receiver IMPLEMENTATION.
    METHOD handle_node_double_click.
    break-point.
    ENDMETHOD. "handle_node_double_click
    Regards,
    Ranjan

  • Problem when printing Alv Tree Report in back ground

    Hi,
    I am using SUBMIT ...TO SAP-SPOOL WITHOUT SPOOL DYNPRO with GET_PRINT_PARAMETERS FM.Its working fine.
    My problem is that my SUBMIT report have TREE STRUCTURE as output so when i am running my program one blank screen is coming with heading DISPLAY LOG TREE because of TREE STRUCTURE.when i click on back button then only further processing happens.
    How to avoid this TREE STRUCTURE SCREEN ???
    Is there any other way to pass your list o/p to SPOOL other than .....TO SAP-SPOOL..?
    Thanks in advance.

    in foreground when u run ALV report it holds maximum fields and displays in 1 single row, but the case is not in back ground...When any report is run in background, the default size for a line is 255 chars...So, if it more it gets splitted into 2 line item....This is how back ground job works for a report  though it is a normal report or alv report.

  • ALV TREE Report

    Dear all,
    I am currently working on a tree alv report. Here i have 3 levels of heirearchy each heirearchy level has different fields to be displayed. Can anyone please help me out how to build the fieldcatalog when the field changes for each heirearchy level? If anyone can help me with sample report will be rewarded with points.
    Example:
    1st level - Netwrok Activity -- Display Fields from AFVC table
    2nd level - Components of Activity - Display fields from RESB Table
    3rd Level - Items of Component - Display fields from STPO table
    We dont have such example in BCLAVTREE if so pls help me with some sample code of program how to build fieldcatolog.
    Thanks & Regards
    Sathish

    Hi,
    If it's going three level drill down list then you can use can see following piece of code. declaration should be like this.
    top_of_page type slis_formname value 'TOP_OF_PAGE',
    end_of_page type slis_formname value 'END_OF_PAGE',
    user_command type slis_formname value 'USER_COMMAND',
    pf_status_set type slis_formname value 'PF_STATUS_SET',
    user_command1 type slis_formname value 'USER_COMMAND1',
    pf_status_set1 type slis_formname value 'PF_STATUS_SET1',
    and displaying the first list will be.
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    * I_INTERFACE_CHECK = ' '
    * I_BYPASSING_BUFFER =
    * I_BUFFER_ACTIVE = ' '
    i_callback_program = name
    i_callback_pf_status_set = pf_status_set
    i_callback_user_command = user_command
    * I_STRUCTURE_NAME =
    i_callback_top_of_page = 'TOP-OF-PAGE'
    i_grid_title = 'CUSTOMER GROUP WISE REPORT'
    is_layout = layout
    it_fieldcat = fieldcat_t
    * IT_EXCLUDING =
    * IT_SPECIAL_GROUPS =
    * it_sort = SORT_T
    * IT_FILTER =
    * IS_SEL_HIDE =
    i_default = 'X'
    i_save = 'A'
    * IS_VARIANT =
    * it_events = events_t
    * IT_EVENT_EXIT =
    * IS_PRINT =
    * IS_REPREP_ID =
    * IT_ADD_FIELDCAT = FIELDCAT_T1
    * I_SCREEN_START_COLUMN = 0
    * I_SCREEN_START_LINE = 0
    * I_SCREEN_END_COLUMN = 0
    * I_SCREEN_END_LINE = 0
    * IMPORTING
    * E_EXIT_CAUSED_BY_CALLER =
    * ES_EXIT_CAUSED_BY_USER =
    tables
    t_outtab = it_basic.
    and capturing user command will be like this.
    form user_command using ucomm like sy-ucomm
    selfield type slis_selfield.
    case ucomm.
    when '&IC1'.
    read table it_basic index selfield-tabindex.
    perform get_data_first_list using it_basic-kdgrp.
    when '&PLEVEL'.
    when '&CUST'.
    when '&F15'.
    leave to screen 0.
    endcase.
    endform. "user_command
    you may be able to display the similar when the double click a line or clicking on a button.
    if you want have mulitple header lines on the top of page you can this.
    form top-of-page.
    *ALV Header declarations
    data: t_header type slis_t_listheader,
    wa_header type slis_listheader.
    wa_header-typ = 'H'.
    wa_header-info = xhead.
    append wa_header to t_header.
    clear wa_header.
    concatenate sy-datum+6(2) sy-datum+4(2) sy-datum+0(4) into xhead1
    separated by '.'.
    wa_header-typ = 'H'.
    wa_header-info = xhead1.
    append wa_header to t_header.
    clear wa_header.
    * append t_header.
    *append t_header.
    call function 'REUSE_ALV_COMMENTARY_WRITE'
    exporting
    it_list_commentary = t_header.
    * i_logo = 'Z_LOGO'.
    endform. "top-of-page
    May it helps you.
    Regards.
    DS

  • Alv tree report with non oop

    Hi All,
    I have requirement to create tree structure report where:-
    The Folders structure should appear on left side.
    Once clicking on the particular folder in left pane , it should display a report in right pane.
    The folder can be nested withing particular folder.
    regards,
    karthik

    Hi,
    Check out sample program BCALV_TREE_DEMO. I don't think it is possible without OOP. Why you don't want OOP? I feel, It is simpler than normal programming.
    Thanks,
    Vinod.

  • ALV TREE - Double click on an item

    Hi all,
    I need to handle the double click action on an Item of ad ALV_TREE defined cl_gui_alv_tree_simple
    What I did at now is:
    u2026
    DATA tree1  TYPE REF TO cl_gui_alv_tree_simple.
    u2026     
      CREATE OBJECT event_receiver.
      SET HANDLER event_receiver->item_double_click FOR tree1.
      SET HANDLER event_receiver->node_double_click FOR tree1.
    u2026
    CLASS lcl_event_receiver DEFINITION.
      PUBLIC SECTION.
        METHODS:
    *Double-click control
        item_double_click FOR EVENT item_double_click OF cl_gui_alv_tree_simple
                          IMPORTING index_outtab
                                    fieldname
                                    grouplevel,
    *Double-click control
        node_double_click FOR EVENT node_double_click OF cl_gui_alv_tree_simple
                          IMPORTING index_outtab
                                    grouplevel.
      PRIVATE SECTION.
    ENDCLASS.                    "lcl_event_receiver DEFINITION
    CLASS lcl_event_receiver IMPLEMENTATION.
      METHOD item_double_click.
        break <my_user_id>.
      ENDMETHOD.                    "handle_double_click
      METHOD node_double_click.
        break <my_user_id>.
      ENDMETHOD.                    "handle_double_click
    ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION
    When I double click on item the program do nothing and I donu2019t understand the why.
    Note: I think I could try to define the events passed, using the method et_registered_events, but I donu2019t know how to obtain the id of method item_double_click defined in class cl_gui_alv_tree_simple.
    Any Idea?
    Thank you in advance.

    Register the events with the below code...
      data: lt_events type cntl_simple_events,
            l_event type cntl_simple_event.
      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 tree1->set_registered_events
        exporting
          events = lt_events
        exceptions
          cntl_error                = 1
          cntl_system_error         = 2
          illegal_event_combination = 3.

  • Double Click in ALV TREE doesn't get triggered

    Hello All,
    Double click event on item in a alv tree report doesn't get triggered. I thought I was doing everything right. Please help me out.
    Look at the code below and tell me what else I need to do.
    <b>FORM register_events .
    Event registration: tell ALV Tree which events shall be passed
    from frontend to backend.
      DATA: lt_events TYPE cntl_simple_events,
            l_event TYPE cntl_simple_event,
            l_event_receiver TYPE REF TO lcl_tree_event_receiver.
    Frontend registration:  get already registered tree events
      CALL METHOD g_alv_tree->get_registered_events
        IMPORTING
          events = lt_events.
    Frontend registration: add additional event ids
      l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
      APPEND l_event TO lt_events.
    Frontend registration: provide new event table to alv tree
      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.
    Register events on backend (ABAP Objects event handling)
      CREATE OBJECT l_event_receiver.
      SET HANDLER l_event_receiver->node_double_click FOR g_alv_tree.
      SET HANDLER l_event_receiver->item_double_click FOR g_alv_tree.
      SET HANDLER l_event_receiver->on_function_selected FOR g_toolbar.
    ENDFORM.                    " register_events</b>
    When I double click on item on the report double click event doesnt trigger. what could be the problem? Any sample programs?
    Thanks,
    Chandni

    Hi,
    Here is a sample code for you.
    report ztree.
    TABLES : vbak.
    DATA: BEGIN OF mylist OCCURS 50. " Internal table hierarchy
    INCLUDE STRUCTURE snodetext.
    DATA: END OF mylist.
    DATA: f15 TYPE c.
    DATA :
    BEGIN OF gt_sales OCCURS 0,
    vbeln LIKE vbak-vbeln,
    kunnr LIKE vbak-kunnr,
    matnr LIKE vbap-matnr,
    arktx LIKE vbap-arktx,
    END OF gt_sales.
    SELECT-OPTIONS : s_vbeln FOR vbak-vbeln.
    START-OF-SELECTION.
    SET PF-STATUS 'ZTREE1'.
    SET TITLEBAR 'T1'.
    Fill internal table with pseudo-data
    PERFORM fill_itab.
    Hierarchy output
    PERFORM main.
    *& Form FILL_ITAB
    text
    --> p1 text
    <-- p2 text
    FORM fill_itab .
    *Fill the gt_sales table
    SELECT vkvbeln vkkunnr vpmatnr vparktx INTO CORRESPONDING FIELDS OF
    TABLE gt_sales
    FROM ( vbak AS vk INNER JOIN vbap AS vp ON vkvbeln = vpvbeln )
    WHERE vk~vbeln IN s_vbeln.
    SORT gt_sales BY vbeln kunnr.
    *Fill the root
    mylist-name = 'Report Tree List'.
    mylist-color = 1.
    mylist-intensiv = '1'.
    mylist-text = 'Report Tree List'.
    mylist-tlength = 16.
    mylist-tlevel = 1.
    mylist-tcolor = 1.
    mylist-tintensiv = '1'.
    mylist-text1 = 'using "RS_TREE_CONSTRUCT" function'.
    mylist-tlength1 = 50.
    mylist-tcolor1 = 2.
    mylist-tintensiv1 = '0'.
    APPEND mylist.
    LOOP AT gt_sales.
    ON CHANGE OF gt_sales-vbeln.
    mylist-name = 'level1'.
    mylist-color = 0.
    mylist-intensiv = '0'.
    mylist-text = 'Sales Document no:'.
    mylist-tlength = 20.
    mylist-tlevel = 2.
    mylist-tcolor = 7.
    mylist-tintensiv = '1'.
    mylist-text1 = gt_sales-vbeln.
    mylist-tlength1 = 30.
    mylist-tcolor1 = 2.
    mylist-tintensiv1 = '0'.
    APPEND mylist.
    ENDON.
    ON CHANGE OF gt_sales-kunnr.
    mylist-name = 'level2'.
    mylist-color = 0.
    mylist-intensiv = '0'.
    mylist-text = 'Customer no:'.
    mylist-tlength = 20.
    mylist-tlevel = 3.
    mylist-tcolor = 5.
    mylist-tintensiv = '1'.
    mylist-text1 = gt_sales-kunnr.
    mylist-tlength1 = 30.
    mylist-tcolor1 = 3.
    mylist-tintensiv1 = '0'.
    APPEND mylist.
    ENDON.
    mylist-name = 'level3'.
    mylist-color = 0.
    mylist-intensiv = '0'.
    mylist-text = gt_sales-matnr.
    mylist-tlength = 15.
    mylist-tlevel = 4.
    mylist-tcolor = 4.
    mylist-tintensiv = '0'.
    mylist-text1 = gt_sales-arktx.
    mylist-tlength1 = 30.
    mylist-tcolor1 = 2.
    mylist-tintensiv1 = '0'.
    APPEND mylist.
    ENDLOOP.
    ENDFORM. " FILL_ITAB
    *& Form MAIN
    text
    --> p1 text
    <-- p2 text
    FORM main .
    PERFORM hierarchy. " construct & draw the tree
    ENDFORM. " MAIN
    *& Form HIERARCHY
    text
    --> p1 text
    <-- p2 text
    FORM hierarchy .
    PERFORM build_tree.
    PERFORM draw_tree.
    ENDFORM. " HIERARCHY
    FORM BUILD_TREE *
    Builds the tree from internal table *
    Uses the Function module RS_TREE_CONSTRUCT *
    FORM build_tree.
    CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
    nodetab = mylist
    EXCEPTIONS
    tree_failure = 1.
    ENDFORM. "build_tree
    FORM DRAW_TREE *
    Builds the tree from internal table *
    Uses the Function module RS_TREE_DISPLAY *
    FORM draw_tree.
    sy-lsind = 0.
    CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
    callback_program = 'ZREPORT_TREE'
    callback_user_command = 'NODE_SELECT'
    IMPORTING
    f15 = f15.
    ENDFORM. "draw_tree
    FORM NODE_SELECT *
    Handles selection of nodes *
    FORM node_select TABLES knoten STRUCTURE seucomm
    USING command
    CHANGING exit
    list_refresh.
    Processing of commands for hierarchy list
    CASE command.
    WHEN 'DISP'.
    CASE knoten-id.
    WHEN '000002'.
    *Display Sales Order
    SET PARAMETER ID 'AUN' FIELD knoten-text1.
    CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
    WHEN '000003'.
    *Display Customer
    SET PARAMETER ID 'KUN' FIELD knoten-text1.
    CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
    ENDCASE.
    ENDCASE.
    list_refresh = 'X'.
    ENDFORM. "node_select

  • Required Sample Programs on Tree Reports using ALV and Reports

    Hi Pals,
       I require sample progrms on Tree Reports using Function Modules for both ALV and Classical Reports. Send the list of sample programs and function modules used for tree reports.
    Regards,
    Pradeep.g
    <removed by moderator>

    Check these threads..U can find sample programs.
    tree type report
    ALVtree reports - Example code and information on creating ALV tree reports
    http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htmhttps://alv tree
    ALso check this DEMO Program
    SAPCOLUMN_TREE_CONTROL_DEMO
    CL_GUI_ALV_COLUMN_TREE
    Sample code:
    http://www.geocities.com/victorav15/sapr3/utilities/zvvooa3.txt

  • Get cursor field in ALV Tree

    Hello all,
    How do I get a cursor field on ALV Tree report? I have output with po number, vendor no etc. When I double click PO, i shuold display ME23N and on vendor no 'XK03' etc. Double click event is triggered, but how do I check which field is clicked? Anybody pls suggest me.
    Thanks,
    Chandni

    Hi,
    you can use method to get the select lines:
      CALL METHOD TREE->GET_SELECTED_NODES
       CHANGING
         CT_INDEX_OUTTAB   = SELECTED_NODES
        EXCEPTIONS
          CNTL_SYSTEM_ERROR = 1
          DP_ERROR          = 2
          FAILED            = 3
          OTHERS            = 4.
    or in double click:
        METHODS HANDLE_DOUBLE_CLICK
          FOR EVENT ITEM_DOUBLE_CLICK OF CL_GUI_ALV_TREE_SIMPLE
          IMPORTING FIELDNAME INDEX_OUTTAB GROUPLEVEL.
    just read tables with index_outttab
    READ TABLE GT_TAB INTO IGT_TAB INDEX INDEX_OUTTAB.
    to check which  field is clicked use the FIELDNAME field.
    regards

  • How to refresh the ALV Tree

    Hi,
    I have an ALV Tree report developed using the OOPS. In my ALV Tree output, I have some buttons which will update the database after clicking. The data is correctly updating in the database. But, it is not getting updated in the ALV Tree display. That means, it is not REFRESHing the ALV Tree display. We have to again execute the program in order to see the updated output.
    Could anyone please suggest me how to Refresh the ALV Tree display..?
    We can't use the method 'REFRESH_TABLE_DISPLAY' as it is a PRIVATE method is the class CL_GUI_ALV_TREE.
    Please share your valuable thoughts.
    Thanks & Regards,
    Paddu.

    Hi paddu.
    please check out the link mentioned below,this will help u.
    How to Refresh data on ALV tree
    Regards
    Theres

  • ALV Tree

    Hi,
    I have created ALV Tree, every thing is fine. But in ALV there is no EXPORT button on alv toolbar. My requirement is to download the data to excel. How to add/activate export button with functionality.
    I am using Object oriented mechanism, and using set_table_for_first_Dipslay method to display the output.
    Thanks
    Edited by: Salahuddin Lughmani on Feb 24, 2008 4:55 AM

    Hi,
    Following report is the sample report for ALV Tree Report.
    REPORT  yms_alvtreefooter.
    TABLES vbak.
    TYPE-POOLS slis.
    Data Declaration
    TYPES: BEGIN OF t_vbak,
    vbeln TYPE vbak-vbeln,
    erdat TYPE vbak-erdat,
    ernam TYPE vbak-ernam,
    audat TYPE vbak-audat,
    vbtyp TYPE vbak-vbtyp,
    netwr TYPE vbak-netwr,
    vkorg TYPE vbak-vkorg,
    vkgrp TYPE vbak-vkgrp,
    line_color(4) TYPE c,
    END OF t_vbak.
    DATA: it_vbak TYPE STANDARD TABLE OF t_vbak INITIAL SIZE 0,
    wa_vbak TYPE t_vbak.
    ALV Data Declaration
    DATA: fldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
    gd_layout TYPE slis_layout_alv,
    gd_repid TYPE sy-repid,
    i_events TYPE slis_t_event,
    w_events LIKE LINE OF i_events.
    DATA: i_comment TYPE slis_t_listheader,
    wa_comment TYPE slis_listheader.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM bld_fldcat.
      PERFORM bld_layout.
      PERFORM call_events.
      PERFORM display_alv_report.
    Build Field Catalog for ALV Report
    FORM bld_fldcat.
      fldcat-fieldname = 'VBELN'.
      fldcat-seltext_m = 'Sales Document'.
      fldcat-col_pos = 0.
    *FLDCAT-EMPHASIZE = 'C411'.
      fldcat-outputlen = 20.
      fldcat-key = 'X'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'ERDAT'.
      fldcat-seltext_l = 'Record Date created'.
      fldcat-col_pos = 1.
      fldcat-key = 'X'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'ERNAM'.
      fldcat-seltext_l = 'Cteated Object Person Name'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'AUDAT'.
      fldcat-seltext_m = 'Document Date'.
      fldcat-col_pos = 3.
      fldcat-emphasize = 'C110'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'VBTYP'.
      fldcat-seltext_l = 'SD Document category'.
      fldcat-col_pos = 4.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'NETWR'.
      fldcat-seltext_l = 'Net Value of the SO in Document Currency'.
      fldcat-col_pos = 5.
      fldcat-outputlen = 60.
      fldcat-do_sum = 'X'.
      fldcat-datatype = 'CURR'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'VKORG'.
      fldcat-seltext_l = 'Sales Organization'.
      fldcat-col_pos = 6.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
      fldcat-fieldname = 'VKGRP'.
      fldcat-seltext_m = 'Sales Group'.
      fldcat-col_pos = 7.
      fldcat-emphasize = 'C801'.
      APPEND fldcat TO fldcat.
      CLEAR fldcat.
    ENDFORM.                    "BLD_FLDCAT
    Build Layout for ALV Grid Report
    FORM bld_layout.
      gd_layout-no_input = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-info_fieldname = 'LINE_COLOR'.
    ENDFORM.                    "BLD_LAYOUT
    Display report using ALV grid
    FORM display_alv_report.
      DATA t_event TYPE slis_t_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type = 0
        IMPORTING
          et_events   = t_event.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      gd_repid = sy-repid.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
      i_callback_program = gd_repid
      is_layout = gd_layout
    I_CALLBACK_HTML_TOP_OF_PAGE = 'TOP_OF_PAGE_SPLIT'
    I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'
    I_CALLBACK_HTML_END_OF_LIST = 'END_OF_LIST_HTML'
      it_events = i_events
      it_fieldcat = fldcat[]
      i_save = 'X'
      TABLES
      t_outtab = it_vbak
      EXCEPTIONS
      program_error = 1
      OTHERS = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "DISPLAY_ALV_REPORT
    Retrieve data from VBAK table and populate itab IT_VBAK
    FORM data_retrieval.
      DATA ld_color(1) TYPE c.
      SELECT vbeln erdat ernam audat vbtyp netwr vkorg
      UP TO 100 ROWS
      FROM vbak
      INTO TABLE it_vbak.
      LOOP AT it_vbak INTO wa_vbak.
        ld_color = ld_color + 1.
        IF ld_color = 8.
          ld_color = 1.
        ENDIF.
        CONCATENATE 'C' ld_color '10' INTO wa_vbak-line_color.
        MODIFY it_vbak FROM wa_vbak.
      ENDLOOP.
    ENDFORM.                    "DATA_RETRIEVAL
    *&      Form  CALL_EVENTS
          text
    FORM call_events.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
      EXPORTING
      i_list_type = 0
      IMPORTING
      et_events = i_events
    EXCEPTIONS
    LIST_TYPE_WRONG = 1
    OTHERS = 2
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      IF NOT i_events[] IS INITIAL.
        READ TABLE i_events INTO w_events WITH KEY name = 'END_OF_LIST'.
        w_events-form = 'GENERATE_USERCOMMAND_FOOTER'.
        MODIFY i_events FROM w_events INDEX sy-tabix.
      ENDIF.
    ENDFORM.                    "CALL_EVENTS
    *&      Form  GENERATE_USERCOMMAND_FOOTER
          text
    FORM generate_usercommand_footer.
      CLEAR i_comment[].
      wa_comment-typ = 'S'.
      wa_comment-info = sy-pagno.
      APPEND wa_comment TO i_comment.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
      EXPORTING
      it_list_commentary = i_comment
    I_LOGO = ''
      i_end_of_list_grid = 'X'.
    ENDFORM.                    "GENERATE_USERCOMMAND_FOOTER
    Thanks,
    Sankar M

  • ALV Tree using Function Modules

    Hi,
    I want a simple example of ALV Tree using Function Modules which can display multiple Columns in the Hierarchically arranged fashion along with nodes & icons.
    Also should be able to handle the events.
    Thanks in Advance..

    Hi Ramesh,
    Here is a example of alv tree
    *& Report  BCALV_TREE_DEMO                                             *
    report  bcalv_tree_demo.
    class cl_gui_column_tree definition load.
    class cl_gui_cfw definition load.
    data tree1  type ref to cl_gui_alv_tree.
    data mr_toolbar type ref to cl_gui_toolbar.
    include <icon>.
    include bcalv_toolbar_event_receiver.
    include bcalv_tree_event_receiver.
    data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.
    data: gt_sflight      type sflight occurs 0,      "Output-Table
          gt_fieldcatalog type lvc_t_fcat, "Fieldcatalog
          ok_code like sy-ucomm.           "OK-Code
    start-of-selection.
    end-of-selection.
      call screen 100.
    *&      Module  PBO  OUTPUT
    *       process before output
    module pbo output.
      set pf-status 'MAIN100'.
      if tree1 is initial.
        perform init_tree.
      endif.
      call method cl_gui_cfw=>flush.
    endmodule.                             " PBO  OUTPUT
    *&      Module  PAI  INPUT
    *       process after input
    module pai input.
      case ok_code.
        when 'EXIT' or 'BACK' or 'CANC'.
          perform exit_program.
        when others.
          call method cl_gui_cfw=>dispatch.
      endcase.
      clear ok_code.
      call method cl_gui_cfw=>flush.
    endmodule.                             " PAI  INPUT
    *&      Form  build_fieldcatalog
    *       build fieldcatalog for structure sflight
    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.                               " build_fieldcatalog
    *&      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 = 'Hierarchy Header'.         "#EC NOTEXT
      p_hierarchy_header-tooltip =
                             'This is the Hierarchy Header !'. "#EC NOTEXT
      p_hierarchy_header-width = 30.
      p_hierarchy_header-width_pix = ''.
    endform.                               " build_hierarchy_header
    *&      Form  exit_program
    *       free object and leave program
    form exit_program.
      call method tree1->free.
      leave program.
    endform.                               " exit_program
    *&      Form  build_header
    *       build table for html_header
    *  -->  p1        text
    *  <--  p2        text
    form build_comment using
          pt_list_commentary type slis_t_listheader
          p_logo             type sdydo_value.
      data: ls_line type slis_listheader.
    * LIST HEADING LINE: TYPE H
      clear ls_line.
      ls_line-typ  = 'H'.
    * LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'ALV-tree-demo: flight-overview'.       "#EC NOTEXT
      append ls_line to pt_list_commentary.
    * STATUS LINE: TYPE S
      clear ls_line.
      ls_line-typ  = 'S'.
      ls_line-key  = 'valid until'.                          "#EC NOTEXT
      ls_line-info = 'January 29 1999'.                      "#EC NOTEXT
      append ls_line to pt_list_commentary.
      ls_line-key  = 'time'.
      ls_line-info = '2.00 pm'.                              "#EC NOTEXT
      append ls_line to pt_list_commentary.
    * ACTION LINE: TYPE A
      clear ls_line.
      ls_line-typ  = 'A'.
    * LS_LINE-KEY:  NOT USED FOR THIS TYPE
      ls_line-info = 'actual data'.                          "#EC NOTEXT
      append ls_line to pt_list_commentary.
      p_logo = 'ENJOYSAP_LOGO'.
    endform.
    *&      Form  create_hierarchy
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form create_hierarchy.
      data: ls_sflight type sflight,
            lt_sflight type sflight occurs 0.
    * get data
      select * from sflight into table lt_sflight
                            UP TO 200 ROWS .
      sort lt_sflight by carrid connid fldate.
    * add data to tree
      data: l_carrid_key type lvc_nkey,
            l_connid_key type lvc_nkey,
            l_last_key type lvc_nkey.
      loop at lt_sflight into ls_sflight.
        on change of ls_sflight-carrid.
          perform add_carrid_line using    ls_sflight
                                  changing l_carrid_key.
        endon.
        on change of ls_sflight-connid.
          perform add_connid_line using    ls_sflight
                                           l_carrid_key
                                  changing l_connid_key.
        endon.
        perform add_complete_line using  ls_sflight
                                         l_connid_key
                                changing l_last_key.
      endloop.
    * calculate totals
      call method tree1->update_calculations.
    * this method must be called to send the data to the frontend
      call method tree1->frontend_update.
    endform.                               " create_hierarchy
    *&      Form  add_carrid_line
    *       add hierarchy-level 1 to tree
    *      -->P_LS_SFLIGHT  sflight
    *      -->P_RELEATKEY   relatkey
    *     <-->p_node_key    new node-key
    form add_carrid_line using     ps_sflight type sflight
                                   p_relat_key type lvc_nkey
                         changing  p_node_key type lvc_nkey.
      data: l_node_text type lvc_value,
            ls_sflight type sflight.
    * set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image = '@3P@'.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      ls_item_layout-style   =
                            cl_gui_column_tree=>style_intensifd_critical.
      append ls_item_layout to lt_item_layout.
    * add node
      l_node_text =  ps_sflight-carrid.
      call method tree1->add_node
        exporting
              i_relat_node_key = p_relat_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = l_node_text
              is_outtab_line   = ls_sflight
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                               " add_carrid_line
    *&      Form  add_connid_line
    *       add hierarchy-level 2 to tree
    *      -->P_LS_SFLIGHT  sflight
    *      -->P_RELEATKEY   relatkey
    *     <-->p_node_key    new node-key
    form add_connid_line using     ps_sflight type sflight
                                   p_relat_key type lvc_nkey
                         changing  p_node_key type lvc_nkey.
      data: l_node_text type lvc_value,
            ls_sflight type sflight.
    * set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-t_image = '@3Y@'.
      ls_item_layout-style   =
                            cl_gui_column_tree=>style_intensified.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      append ls_item_layout to lt_item_layout.
    * add node
      l_node_text =  ps_sflight-connid.
      call method tree1->add_node
        exporting
              i_relat_node_key = p_relat_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              i_node_text      = l_node_text
              is_outtab_line   = ls_sflight
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                               " add_connid_line
    *&      Form  add_cmplete_line
    *       add hierarchy-level 3 to tree
    *      -->P_LS_SFLIGHT  sflight
    *      -->P_RELEATKEY   relatkey
    *     <-->p_node_key    new node-key
    form add_complete_line using   ps_sflight type sflight
                                   p_relat_key type lvc_nkey
                         changing  p_node_key type lvc_nkey.
      data: l_node_text type lvc_value.
    * set item-layout
      data: lt_item_layout type lvc_t_layi,
            ls_item_layout type lvc_s_layi.
      ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
      ls_item_layout-class   = cl_gui_column_tree=>item_class_checkbox.
      ls_item_layout-editable = 'X'.
      append ls_item_layout to lt_item_layout.
      l_node_text =  ps_sflight-fldate.
      call method tree1->add_node
        exporting
              i_relat_node_key = p_relat_key
              i_relationship   = cl_gui_column_tree=>relat_last_child
              is_outtab_line   = ps_sflight
              i_node_text      = l_node_text
              it_item_layout   = lt_item_layout
           importing
              e_new_node_key = p_node_key.
    endform.                               " add_complete_line
    *&      Form  register_events
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form register_events.
    * define the events which will be passed to the backend
      data: lt_events type cntl_simple_events,
            l_event type cntl_simple_event.
    * define the events which will be passed to the backend
      l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
      append l_event to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_header_click.
      append L_EVENT to lt_events.
      l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
      append L_EVENT to lt_events.
      call method tree1->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.
    * set Handler
      data: l_event_receiver type ref to lcl_tree_event_receiver.
      create object l_event_receiver.
      set handler l_event_receiver->handle_node_ctmenu_request
                                                            for tree1.
      set handler l_event_receiver->handle_node_ctmenu_selected
                                                            for tree1.
      set handler l_event_receiver->handle_item_ctmenu_request
                                                            for tree1.
      set handler l_event_receiver->handle_item_ctmenu_selected
                                                            for tree1.
    endform.                               " register_events
    *&      Form  change_toolbar
    *       text
    *  -->  p1        text
    *  <--  p2        text
    form change_toolbar.
    * get toolbar control
      call method tree1->get_toolbar_object
              importing
                  er_toolbar = mr_toolbar.
      check not mr_toolbar is initial.
    * add seperator to toolbar
      call method mr_toolbar->add_button
              exporting
                  fcode     = ''
                  icon      = ''
                  butn_type = cntb_btype_sep
                  text      = ''
                  quickinfo = 'This is a Seperator'.         "#EC NOTEXT
    * add Standard Button to toolbar (for Delete Subtree)
      call method mr_toolbar->add_button
              exporting
                  fcode     = 'DELETE'
                  icon      = '@18@'
                  butn_type = cntb_btype_button
                  text      = ''
                  quickinfo = 'Delete subtree'.              "#EC NOTEXT
    * add Dropdown Button to toolbar (for Insert Line)
      call method mr_toolbar->add_button
              exporting
                  fcode     = 'INSERT_LC'
                  icon      = '@17@'
                  butn_type = cntb_btype_dropdown
                  text      = ''
                  quickinfo = 'Insert Line'.           "#EC NOTEXT
    * set event-handler for toolbar-control
      create object toolbar_event_receiver.
      set handler toolbar_event_receiver->on_function_selected
                                                          for mr_toolbar.
      set handler toolbar_event_receiver->on_toolbar_dropdown
                                                          for mr_toolbar.
    endform.                               " change_toolbar
    *&      Form  init_tree
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM init_tree.
    * create fieldcatalog for structure sflight
      perform build_fieldcatalog.
    * create container for alv-tree
      data: l_tree_container_name(30) type c,
            l_custom_container type ref to cl_gui_custom_container.
      l_tree_container_name = 'TREE1'.
      if sy-batch is initial.
        create object l_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'.                       "#EC NOTEXT
        endif.
      endif.
    * create tree control
      create object tree1
        exporting
            parent              = l_custom_container
            node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
            item_selection      = 'X'
            no_html_header      = ''
            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.
    * create Hierarchy-header
      data l_hierarchy_header type treev_hhdr.
      perform build_hierarchy_header changing l_hierarchy_header.
    * create info-table for html-header
      data: lt_list_commentary type slis_t_listheader,
            l_logo             type sdydo_value.
      perform build_comment using
                     lt_list_commentary
                     l_logo.
    * repid for saving variants
      data: ls_variant type disvariant.
      ls_variant-report = sy-repid.
    * create emty tree-control
      call method tree1->set_table_for_first_display
         exporting
                   is_hierarchy_header  = l_hierarchy_header
                   it_list_commentary   = lt_list_commentary
                   i_logo               = l_logo
                   i_background_id      = 'ALV_BACKGROUND'
                   i_save               = 'A'
                   is_variant            = ls_variant
         changing
                   it_outtab            = gt_sflight "table must be emty !!
                   it_fieldcatalog      = gt_fieldcatalog.
    * create hierarchy
      perform create_hierarchy.
    * add own functioncodes to the toolbar
      perform change_toolbar.
    * register events
      perform register_events.
    * adjust column_width
      call method tree1->COLUMN_OPTIMIZE.
    ENDFORM.                    " init_tree
    regards,
    venu.

Maybe you are looking for