Application Development and Automation 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: 
Read only

Node_Double_Click wont Trigger ALV TREE

Former Member
0 Likes
1,273

Hi Sdn Community,

My class has a event that is triggered by (at least was supposed to be) Node_Double_Click. ( I even tried Item_Double_Click event, and mark 'X' in item_selection parameter when creating my instance of CL_GUI_ALV_TREE but that event wont trigger too.)

I already have set the handler (SET HANDLER me->event_name for r_alvtree) just right off the creating of the object (CL_GUI_ALV_TREE).

Then I Sot the Method to be Event Handler, giving the name of the class 'CL_GUI_ALV_TREE' and Node_Double_Click for the event (in detalied vision options).

Obs: As U can notice, I'm using Class Builder...

Still have I missed something?

When tring to use another method, like Header_Click, it work's fine...

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
830

Hello Jose

I assume you have not registered the event with the tree instance.

Have a look at the following sample report. The crucial parts are marked using $ADDED$:

<b>(1) Register event with tree instance:</b>

[code] "Register event for NODE_DOUBLE_CLICK

l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

APPEND l_event TO lt_events.[/code]

<b>(2) Set handler vor event:</b>

[code] SET HANDLER l_event_receiver->handle_node_double_click

FOR tree1.[/code]

(3) Define and implement event handler method:

[code] 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.

MESSAGE node_key TYPE 'I'.

ENDMETHOD. "handle_node_double_click[/code]

The sample report is a modified version of BCALV_TREE_DEMO. For raising the event NODE_DOUBLE_CLICK you have to double-click on the folders in the hierarchy part of the ALV.

[code]&----


*& Report ZUS_SDN_BCALV_TREE_DEMO_4_ROOT *

*& *

&----


*& *

*& *

&----


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

*include bcalv_toolbar_event_receiver.

INCLUDE zus_sdn_tree_event_receiver_4.

*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

PARAMETERS:

p_root AS CHECKBOX. " $ADDED

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.

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 '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. "build_comment

&----


*& 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 . "#EC CI_NOWHERE

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.

DATA: l_root_key TYPE lvc_nkey. " $ADDED

IF ( p_root = 'X' ).

CLEAR: ls_sflight.

PERFORM add_root_node USING ls_sflight

''

CHANGING l_root_key.

ELSE.

l_root_key = ''.

ENDIF. " $ADDED

LOOP AT lt_sflight INTO ls_sflight.

ON CHANGE OF ls_sflight-carrid.

PERFORM add_carrid_line USING ls_sflight

l_root_key " ''

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_root_node

&----


  • add root node

----


  • -->P_LS_SFLIGHT sflight

  • -->P_RELEATKEY relatkey

  • <-->p_node_key new node-key

----


FORM add_root_node 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 = 'Root = All Airlines'.

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_sflight

is_node_layout = ls_node

it_item_layout = lt_item_layout

IMPORTING

e_new_node_key = p_node_key.

ENDFORM. " add_root_node

&----


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

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_sflight

is_node_layout = ls_node

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.

CLEAR ls_item_layout.

ls_item_layout-fieldname = 'PLANETYPE'.

ls_item_layout-alignment = cl_gui_column_tree=>align_right.

APPEND ls_item_layout TO lt_item_layout.

l_node_text = ps_sflight-fldate.

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

is_outtab_line = ps_sflight

i_node_text = l_node_text

is_node_layout = ls_node

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.

"$ADDED$ Register event for NODE_DOUBLE_CLICK

l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

APPEND l_event TO lt_events.

"$ADDED$

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.

"$ADDED$

SET HANDLER l_event_receiver->handle_node_double_click

FOR tree1.

"$ADDED$

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[/code]

Regards

Uwe

2 REPLIES 2
Read only

uwe_schieferstein
Active Contributor
0 Likes
831

Hello Jose

I assume you have not registered the event with the tree instance.

Have a look at the following sample report. The crucial parts are marked using $ADDED$:

<b>(1) Register event with tree instance:</b>

[code] "Register event for NODE_DOUBLE_CLICK

l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

APPEND l_event TO lt_events.[/code]

<b>(2) Set handler vor event:</b>

[code] SET HANDLER l_event_receiver->handle_node_double_click

FOR tree1.[/code]

(3) Define and implement event handler method:

[code] 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.

MESSAGE node_key TYPE 'I'.

ENDMETHOD. "handle_node_double_click[/code]

The sample report is a modified version of BCALV_TREE_DEMO. For raising the event NODE_DOUBLE_CLICK you have to double-click on the folders in the hierarchy part of the ALV.

[code]&----


*& Report ZUS_SDN_BCALV_TREE_DEMO_4_ROOT *

*& *

&----


*& *

*& *

&----


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

*include bcalv_toolbar_event_receiver.

INCLUDE zus_sdn_tree_event_receiver_4.

*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

PARAMETERS:

p_root AS CHECKBOX. " $ADDED

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.

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 '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. "build_comment

&----


*& 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 . "#EC CI_NOWHERE

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.

DATA: l_root_key TYPE lvc_nkey. " $ADDED

IF ( p_root = 'X' ).

CLEAR: ls_sflight.

PERFORM add_root_node USING ls_sflight

''

CHANGING l_root_key.

ELSE.

l_root_key = ''.

ENDIF. " $ADDED

LOOP AT lt_sflight INTO ls_sflight.

ON CHANGE OF ls_sflight-carrid.

PERFORM add_carrid_line USING ls_sflight

l_root_key " ''

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_root_node

&----


  • add root node

----


  • -->P_LS_SFLIGHT sflight

  • -->P_RELEATKEY relatkey

  • <-->p_node_key new node-key

----


FORM add_root_node 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 = 'Root = All Airlines'.

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_sflight

is_node_layout = ls_node

it_item_layout = lt_item_layout

IMPORTING

e_new_node_key = p_node_key.

ENDFORM. " add_root_node

&----


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

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_sflight

is_node_layout = ls_node

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.

CLEAR ls_item_layout.

ls_item_layout-fieldname = 'PLANETYPE'.

ls_item_layout-alignment = cl_gui_column_tree=>align_right.

APPEND ls_item_layout TO lt_item_layout.

l_node_text = ps_sflight-fldate.

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

is_outtab_line = ps_sflight

i_node_text = l_node_text

is_node_layout = ls_node

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.

"$ADDED$ Register event for NODE_DOUBLE_CLICK

l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.

APPEND l_event TO lt_events.

"$ADDED$

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.

"$ADDED$

SET HANDLER l_event_receiver->handle_node_double_click

FOR tree1.

"$ADDED$

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[/code]

Regards

Uwe

Read only

0 Likes
830

> Hello Jose

>

> I assume you have not registered the event with the

> tree instance.

> Have a look at the following sample report. The

> crucial parts are marked using $ADDED$:

>

> <b>(1) Register event with tree instance:</b>

>

>

 "Register event for NODE_DOUBLE_CLICK
> l_event-eventid =
> cl_gui_column_tree=>eventid_node_double_click.
>   APPEND l_event TO lt_events.

Exactly, Uwe.

I Missed the METHOD SET_REGISTERED_EVENT. Inserting those lines up-ahead and this method just befero setting my handler corrects my Abap coding.

Still, strange to Header_Click event works without those thnigs.

But now, Node_Double_Click is working properly.

Thanx, Uwe.