Skip to Content
0
Former Member
Mar 12, 2007 at 12:02 PM

correct hierarchy in a tree

34 Views

Hi!

This below shown example has a wrong hierarchy.

The right hierarchy is:

Customer-Nr

-> Period

-> Information.

These both upper hierarchies "Customer-Nr" and "Period" should have a

Folder-Icon as usually which indicates being the upper hierarchy.

Reagrds

Ilhan

TABLES:     ZQMCOMP.
TYPE-POOLS: slis.                                 "ALV Declarations


DATA: it_ekko     TYPE STANDARD TABLE OF ZQMCOMP INITIAL SIZE 0,
      it_ekpo     TYPE STANDARD TABLE OF ZQMCOMP INITIAL SIZE 0,
      it_emptytab TYPE STANDARD TABLE OF ZQMCOMP INITIAL SIZE 0,
      wa_ekko     TYPE ZQMCOMP,
      wa_ekpo     TYPE ZQMCOMP.

DATA: ok_code like sy-ucomm,           "OK-Code
      save_ok like sy-ucomm.

*ALV data declarations
DATA: fieldcatalog  TYPE lvc_t_fcat WITH HEADER LINE.

DATA: gd_fieldcat   TYPE lvc_t_fcat,
      gd_tab_group  TYPE slis_t_sp_group_alv,
      gd_layout     TYPE slis_layout_alv.

*ALVtree data declarations
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.

DATA: gd_tree             TYPE REF TO cl_gui_alv_tree,
      gd_hierarchy_header TYPE treev_hhdr,
      gd_report_title     TYPE slis_t_listheader,
      gd_logo             TYPE sdydo_value,
      gd_variant          TYPE disvariant.



DATA: l_tree_container_name(30) TYPE c,
      l_custom_container        TYPE REF TO cl_gui_custom_container,
*
     gd_tree_container_name    TYPE REF TO cl_gui_custom_container,
     gd_custom_container TYPE REF TO cl_gui_custom_container.


* Add following code to 'Z......F01' INCLUDE
*-------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CREATE_ALVTREE_CONTAINER
*&---------------------------------------------------------------------*
*       Create container for alv-tree
*----------------------------------------------------------------------*
FORM create_alvtree_container.
  create object gd_custom_container
      exporting
            container_name = 'SCREEN_CONTAINER'
      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'.
  endif.
ENDFORM.




START-OF-SELECTION.


  PERFORM data_retrieval.
  PERFORM build_fieldcatalog.
  PERFORM build_layout.
  PERFORM build_hierarchy_header CHANGING gd_hierarchy_header.
  PERFORM build_report_title USING gd_report_title gd_logo.
  PERFORM build_variant.

  call screen 100.


*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIEVAL
*&---------------------------------------------------------------------*
*       Retrieve data into Internal tables
*----------------------------------------------------------------------*
FORM data_retrieval.

  select * from ZQMCOMP into TABLE it_ekko.
  select * from ZQMCOMP into TABLE it_ekpo.


ENDFORM.                    " DATA_RETRIEVAL


*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
FORM build_fieldcatalog.

  fieldcatalog-fieldname   = 'EBELN'.           "Field name in itab
  fieldcatalog-scrtext_s   = 'Kunden-Nr'.  "Column text
  fieldcatalog-col_pos     = 0.                 "Column position
  fieldcatalog-outputlen   = 15.                "Column width
  fieldcatalog-emphasize   = 'X'.               "Emphasize  (X or SPACE)
  fieldcatalog-key         = 'X'.               "Key Field? (X or SPACE)
  APPEND fieldcatalog TO gd_fieldcat.
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'EBELP'.
  fieldcatalog-scrtext_s   = 'PO Iten'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 1.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'STATU'.
  fieldcatalog-scrtext_s   = 'Status'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 2.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'AEDAT'.
  fieldcatalog-scrtext_s   = 'Item change date'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 3.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MATNR'.
  fieldcatalog-scrtext_s   = 'Material Number'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 4.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MENGE'.
  fieldcatalog-scrtext_s   = 'PO quantity'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 5.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'MEINS'.
  fieldcatalog-scrtext_s   = 'Order Unit'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 6.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'NETPR'.
  fieldcatalog-scrtext_s   = 'Net Price'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 7.
  fieldcatalog-datatype     = 'CURR'.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.

  fieldcatalog-fieldname   = 'PEINH'.
  fieldcatalog-scrtext_s   = 'Price Unit'.
  fieldcatalog-outputlen   = 15.
  fieldcatalog-col_pos     = 8.
  APPEND fieldcatalog TO gd_fieldcat..
  CLEAR  fieldcatalog.
ENDFORM.                    " BUILD_FIELDCATALOG



*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
FORM build_layout.
  gd_layout-no_input          = 'X'.
  gd_layout-colwidth_optimize = 'X'.
  gd_layout-totals_text       = 'Totals'(230).
*  gd_layout-totals_only        = 'X'.
*  gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
  gd_layout-zebra             = 'X'.
*  gd_layout-group_change_edit = 'X'.
*  gd_layout-header_text       = 'helllllo'.
ENDFORM.                    " BUILD_LAYOUT


*&---------------------------------------------------------------------*
*&      Form  build_hierarchy_header
*&---------------------------------------------------------------------*
*       build hierarchy-header-information
*----------------------------------------------------------------------*
*      -->P_L_HIERARCHY_HEADER  structure for hierarchy-header
*----------------------------------------------------------------------*
FORM build_hierarchy_header CHANGING
                               p_hierarchy_header TYPE treev_hhdr.

  p_hierarchy_header-heading = 'Kunden-Nr.'(013).
  p_hierarchy_header-tooltip = 'Kundenummer'(014).
  p_hierarchy_header-width = 30.
  p_hierarchy_header-width_pix = ''.
ENDFORM.                               " build_hierarchy_header

*&---------------------------------------------------------------------*
*&      Form  BUILD_REPORT_TITLE
*&---------------------------------------------------------------------*
*       Build table for ALVtree header
*----------------------------------------------------------------------*
*  <->  p1        Header details
*  <->  p2        Logo value
*----------------------------------------------------------------------*
FORM build_report_title CHANGING
      pt_report_title  TYPE slis_t_listheader
      pa_logo             TYPE sdydo_value.

  DATA: ls_line TYPE slis_listheader,
        ld_date(10) TYPE c.

* List Heading Line(TYPE H)
  CLEAR ls_line.
  ls_line-typ  = 'H'.
* ls_line-key     "Not Used For This Type(H)
  ls_line-info = 'INFO'.
  APPEND ls_line TO pt_report_title.

* Status Line(TYPE S)
  ld_date(2) = sy-datum+6(2).
  ld_date+2(1) = '/'.
  ld_date+3(2) = sy-datum+4(2).
  ld_date+5(1) = '/'.
  ld_date+6(4) = sy-datum(4).

  ls_line-typ  = 'S'.
  ls_line-key  = 'Date'.
  ls_line-info = ld_date.
  APPEND ls_line TO pt_report_title.

* Action Line(TYPE A)
  CLEAR ls_line.
  ls_line-typ  = 'A'.
  ls_line-info = 'Liste pro Kunde'.
  APPEND ls_line TO pt_report_title.
ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  BUILD_VARIANT
*&---------------------------------------------------------------------*
*       Build variant
*----------------------------------------------------------------------*
form build_variant.
* Set repid for storing variants
  gd_variant-report = sy-repid.
endform.                    " BUILD_VARIANT



*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'STATUS1'.
  SET TITLEBAR 'STATUS1'.

  IF gd_tree IS INITIAL.

    PERFORM create_alvtree_container.
    PERFORM create_object_in_container.
    PERFORM create_empty_alvtree_control.
    PERFORM create_alvtree_hierarchy.


  ENDIF.
  CALL METHOD cl_gui_cfw=>flush.




ENDMODULE.                 " STATUS_0100  OUTPUT


*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.


  DATA return TYPE REF TO cl_gui_event.

  save_ok = ok_code.
  case ok_code.
    when 'BACK' or '%EX' or 'RW'.
*     Exit program
      leave to screen 0.
*   Process ALVtree user actions
    when others.
      call method cl_gui_cfw=>get_current_event_object
              receiving
                 event_object = return.
      call method cl_gui_cfw=>dispatch.

  endcase.


ENDMODULE.                 " USER_COMMAND_0100  INPUT





* Add following code to 'Z......F01' INCLUDE
*-------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CREATE_OBJECT_IN_CONTAINER
*&---------------------------------------------------------------------*
*       Create ALVtree control
*----------------------------------------------------------------------*
FORM create_object_in_container.
  create object gd_tree
    exporting
        parent              = gd_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'.
  endif.
ENDFORM.



* Add following code to 'Z......F01' INCLUDE
*-------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CREATE_EMPTY_ALVTREE_CONTROL
*&---------------------------------------------------------------------*
*       Create empty tree control
*----------------------------------------------------------------------*
FORM create_empty_alvtree_control.
* Create emty tree-control
  CLEAR: it_emptytab.
  REFRESH: it_emptytab.
  CALL METHOD gd_tree->set_table_for_first_display
     EXPORTING
               I_STRUCTURE_NAME     = 'ZQMCOMP'
               is_hierarchy_header  = gd_hierarchy_header
               it_list_commentary   = gd_report_title
               i_logo               = gd_logo
               i_background_id      = 'ALV_BACKGROUND'
               i_save               = 'A'
               is_variant            = gd_variant
     CHANGING
               it_outtab            =  it_emptytab  .    "Must be empty
*               it_fieldcatalog      =  gd_fieldcat.

ENDFORM.                    " CREATE_EMPTY_ALVTREE_CONTROL



* Add following code to 'Z......F01' INCLUDE
*--------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  CREATE_ALVTREE_HIERARCHY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*       Builds ALV tree display, (inserts nodes, subnodes etc)
*----------------------------------------------------------------------*
form create_alvtree_hierarchy.

  data: ld_ebeln_key type lvc_nkey,
        ld_ebelp_key type lvc_nkey.

  loop at it_ekko into wa_ekko.

    perform add_ekko_node using      wa_ekko
                                         ''
                                changing ld_ebeln_key.

    perform add_node_date using      wa_ekko
                                        ''
                               changing ld_ebeln_key.


    perform add_ekpo_line using      wa_ekko
                                          ld_ebeln_key
                                 changing ld_ebelp_key.
  endloop.

* calculate totals
  call method gd_tree->update_calculations.

* this method must be called to send the data to the frontend
  call method gd_tree->frontend_update.
endform.                    " CREATE_ALVTREE_HIERARCHY

*&---------------------------------------------------------------------*
*&      Form  add_node_date
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_0553   text
*      <--P_EBELN_KEY  text
*----------------------------------------------------------------------*
form add_node_date using    ps_ekko like wa_ekko
                            value(p_relate_key)
                   changing p_node_key.

  data: ld_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   = '@1U@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = 'Period'.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekko-KUNDE
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKKO_NODE


*---------------------------------------------------------------------*
*       FORM add_ekko_node                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  PS_EKKO                                                       *
*  -->  VALUE(P_RELATE_KEY)                                           *
*  -->  P_NODE_KEY                                                    *
*---------------------------------------------------------------------*
form add_ekko_node using    ps_ekko like wa_ekko
                            value(p_relate_key)
                   changing p_node_key.

  data: ld_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   = '@A0@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = 'Customer-Nr..'.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekko-KUNDE
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKKO_NODE




*&---------------------------------------------------------------------*
*&      Form  ADD_EKPO_LINE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_WA_EKPO  text
*      -->P_LD_EBELN_KEY  text
*      <--P_LD_EBELP_KEY  text
*----------------------------------------------------------------------*
form add_ekpo_line using    ps_ekpo like wa_ekpo
                            value(p_relate_key)
                   changing p_node_key.

  data: ld_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   = '@90@'.
  ls_item_layout-fieldname = gd_tree->c_hierarchy_column_name.
  ls_item_layout-style     = cl_gui_column_tree=>style_default.
  ld_node_text             = ps_ekpo-KUNDE.
  append ls_item_layout to lt_item_layout.

* Add node
  call method gd_tree->add_node
    exporting
          i_relat_node_key = p_relate_key
          i_relationship   = cl_gui_column_tree=>relat_last_child
          i_node_text      = ld_node_text
          is_outtab_line   = ps_ekpo
          it_item_layout   = lt_item_layout
       importing
          e_new_node_key = p_node_key.
endform.                    " ADD_EKPO_LINE