Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Expand & Decompress Alv columns

former_member672218
Participant
0 Kudos
1,281

Hello,

I am to develop a tree alv with expand and compress butons. The expand & compress buttons are to be made

available on the third & fourth columns.I have not seen an example which has the buttons on the other

columns except for the first one.Can some one explain how to achieve the same?

Ex : Something like below screenshot

Regards,

Venkat

8 REPLIES 8

Former Member
0 Kudos
524

Report BCALV_TREE_02 has that option at 1st, 2nd and 3rd level.

Read the code, especially subroutine create_hierarchy.

0 Kudos
524

Hello,

Sorry for the delay in reply. Even in that program, the hiearchy is set for the first column. Do you mean i can copy the subroutine create_hierarchy and enhance it to second and third columns?

0 Kudos
524

Subroutine create_hierarchy loops at internal table of sflight and calls other subroutines like add_month and add_carrid_line.

Observe the way parent is specified while inserting node.

call method g_alv_tree->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
        importing
           e_new_node_key = p_node_key.

If i_relat_node_key is blank, hierarchy of your node would be highest.

If i_relat_node_key is having level 2 node, your new node would automatically be created as level 3 node.

former_member209120
Active Contributor
0 Kudos
524

Hi Venkat Varadan,

See this code

CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.

DATA tree1  TYPE REF TO cl_gui_alv_tree_simple.

INCLUDE <icon>.
INCLUDE bcalv_simple_event_receiver.

DATA: gt_sflight      TYPE sflight OCCURS 0,   " Output-Table
       gt_fieldcatalog TYPE lvc_t_fcat,         " Field Catalog
       gt_sort         TYPE lvc_t_sort,         " Sorting Table
       ok_code         LIKE sy-ucomm.           " OK-Code

END-OF-SELECTION.

   CALL SCREEN 100.

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*  This subroutine is used to build the field catalog for the ALV list
*----------------------------------------------------------------------*
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' OR 'PRICE' OR  'SEATSOCC'.
         ls_fieldcatalog-no_out = 'X'.
         ls_fieldcatalog-key    = ''.
       WHEN  'SEATSMAX' OR 'PAYMENTSUM'.
         ls_fieldcatalog-do_sum = 'X'.
     ENDCASE.
     MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
   ENDLOOP.

ENDFORM.                               " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_OUTTAB
*&---------------------------------------------------------------------*
* Retrieving the data from the table and filling it in the output table
* of the ALV list
*----------------------------------------------------------------------*
FORM build_outtab.

   SELECT * FROM sflight INTO TABLE gt_sflight.

ENDFORM.                               " BUILD_OUTTAB

*&---------------------------------------------------------------------*
*&      Form  BUILD_SORT_TABLE
*&---------------------------------------------------------------------*
* This subroutine is used to build the sort table or the sort criteria
*----------------------------------------------------------------------*

FORM build_sort_table.

   DATA ls_sort_wa TYPE lvc_s_sort.

* create sort-table
   ls_sort_wa-spos = 1.
   ls_sort_wa-fieldname = 'CARRID'.
   ls_sort_wa-up = 'X'.
   ls_sort_wa-subtot = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 2.
   ls_sort_wa-fieldname = 'CONNID'.
   ls_sort_wa-up = 'X'.
   ls_sort_wa-subtot = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 3.
   ls_sort_wa-fieldname = 'FLDATE'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 4.
   ls_sort_wa-fieldname = 'PRICE'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 5.
   ls_sort_wa-fieldname = 'SEATSOCC'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.




ENDFORM.                               " BUILD_SORT_TABLE
*&---------------------------------------------------------------------*
*&      Module  PBO  OUTPUT
*&---------------------------------------------------------------------*
* This subroutine is used to build the ALV Tree
*----------------------------------------------------------------------*
MODULE pbo OUTPUT.
   IF tree1 IS INITIAL.
     PERFORM init_tree.
   ENDIF.
   SET PF-STATUS 'ZSTATUS'.

ENDMODULE.                             " PBO  OUTPUT

*&---------------------------------------------------------------------*
*&      Module  PAI  INPUT
*&---------------------------------------------------------------------*
* This subroutine is used to handle the navigation on the screen
*----------------------------------------------------------------------*
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.
ENDMODULE.                             " PAI  INPUT

*&---------------------------------------------------------------------*
*&      Form  exit_program
*&---------------------------------------------------------------------*
*       free object and leave program
*----------------------------------------------------------------------*
FORM exit_program.

   CALL METHOD tree1->free.
   LEAVE PROGRAM.

ENDFORM.                               " exit_program

*&---------------------------------------------------------------------*
*&      Form  register_events
*&---------------------------------------------------------------------*
*  Handling the events in the ALV Tree control in backend
*----------------------------------------------------------------------*
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_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_context_men_req.
   APPEND l_event TO lt_events.
   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_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.

* set Handler
   DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
   CREATE OBJECT l_event_receiver.
   SET HANDLER l_event_receiver->on_add_hierarchy_node
                                                         FOR tree1.
ENDFORM.                               " register_events

*&---------------------------------------------------------------------*
*&      Form  build_header
*&---------------------------------------------------------------------*
*       build table for header
*----------------------------------------------------------------------*
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 for SCN'.
   APPEND ls_line TO pt_list_commentary.

   p_logo = 'ENJOYSAP'.

ENDFORM.                    "build_comment

*&---------------------------------------------------------------------*
*&      Form  init_tree
*&---------------------------------------------------------------------*
*  Building the ALV-Tree for the first time display
*----------------------------------------------------------------------*

FORM init_tree.
   PERFORM build_fieldcatalog.

   PERFORM build_outtab.

   PERFORM build_sort_table.

* 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'.

   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.

* create tree control
   CREATE OBJECT tree1
     EXPORTING
         i_parent              = l_custom_container
         i_node_selection_mode =
                               cl_gui_column_tree=>node_sel_mode_multiple
         i_item_selection      = 'X'
         i_no_html_header      = ''
         i_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.

* 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.

* register events
   PERFORM register_events.

* create hierarchy
   CALL METHOD tree1->set_table_for_first_display
     EXPORTING
       it_list_commentary = lt_list_commentary
       i_logo             = l_logo
       i_background_id    = 'ALV_BACKGROUND'
       i_save             = 'A'
       is_variant         = ls_variant
     CHANGING
       it_sort            = gt_sort
       it_outtab          = gt_sflight
       it_fieldcatalog    = gt_fieldcatalog.

* expand first level
   CALL METHOD tree1->expand_tree
     EXPORTING
       i_level = 1.

* optimize column-width
   CALL METHOD tree1->column_optimize
     EXPORTING
       i_start_column = tree1->c_hierarchy_column_name
       i_end_column   = tree1->c_hierarchy_column_name.

ENDFORM.                    " init_tree

For Additional Node

Change Like this

* 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' OR 'PRICE' OR  'SEATSOCC' OR
'SEATSMAX'
.
         ls_fieldcatalog-no_out = 'X'.
         ls_fieldcatalog-key    = ''.
       WHEN  'PAYMENTSUM'.
         ls_fieldcatalog-do_sum = 'X'.
     ENDCASE.
     MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
   ENDLOOP.

FORM build_sort_table.

   DATA ls_sort_wa TYPE lvc_s_sort.

* create sort-table
   ls_sort_wa-spos = 1.
   ls_sort_wa-fieldname = 'CARRID'.
   ls_sort_wa-up = 'X'.
   ls_sort_wa-subtot = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 2.
   ls_sort_wa-fieldname = 'CONNID'.
   ls_sort_wa-up = 'X'.
   ls_sort_wa-subtot = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 3.
   ls_sort_wa-fieldname = 'FLDATE'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 4.
   ls_sort_wa-fieldname = 'PRICE'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

   ls_sort_wa-spos = 5.
   ls_sort_wa-fieldname = 'SEATSOCC'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

ls_sort_wa-spos = 6.
   ls_sort_wa-fieldname = '
SEATSMAX'.
   ls_sort_wa-up = 'X'.
   APPEND ls_sort_wa TO gt_sort.

Regards,

Ramesh.T


Former Member
0 Kudos
524

Hi,

I don't think your requirement is possible with the current ALV Tree Classes. By right the trees and nodes are only created on the first column of your class. And since opening the newly created node with drop-down affects the design of your layout this has not been considered.

Thanks

sujeet2918
Active Contributor
0 Kudos
524

Hi Venkat,

You can try to use below code:

CREATE OBJECT l_custom_container

        EXPORTING

              container_name = l_tree_container_name

CREATE OBJECT l_event_receiver.

  CREATE OBJECT tree1

  EXPORTING

      parent              = l_custom_container

      node_selection_mode = cl_gui_column_tree=>node_sel_mode_single

CALL METHOD tree1->set_table_for_first_display

    EXPORTING

      is_hierarchy_header = gd_hierarchy_header

      it_list_commentary = lt_list_commentary

      i_background_id    = 'ALV_BACKGROUND'

      i_save             = 'A'

      is_variant         = ls_variant

    CHANGING

      it_outtab          = i_final2   " Must be Empty

      it_fieldcatalog    = gt_fieldcatalog.

CALL METHOD tree1->add_node

    EXPORTING

          i_relat_node_key = p_relate_key

          i_relationship   = cl_gui_column_tree=>relat_last_child

          is_outtab_line   = p_wa_final

          is_node_layout   = ls_node_layout

          it_item_layout   = lt_item_layout

          i_node_text      = ld_node_text

       IMPORTING

          e_new_node_key = p_node_key.

Refer below Links.

<<Removed >>

Regards,

Sujeet Mishra

Message was edited by: Kesavadas Thekkillath

kesavadas_thekkillath
Active Contributor
0 Kudos
524

Use class CL_SALV_TREE, it easy than the other class. sample code available in BCALV_TREE_DEMO


Have a look at this sample porgram where the columns are created dynamically for hierarchy.

former_member672218
Participant
0 Kudos
524

Thanks to all for your replies. I believe the current requirement is not possible like David said. All the example  programs were helpful but as i said in my case the tree node must occur in third & fourth columns and not in the first column. I did try some standard programs but were not helpful. So i believe it will not work. If anyone has done this kind of requirement pls do share your thoughts.

Thanks.