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

ALV TREE

Former Member
0 Likes
996

Hello friends, I've a little problem with the refresh of my ALVTREE. I've readed the threads about it but I don't find the answer.

Due to this I'm writing this lines.

Well my problem is this one:

I've a selection screen with two fields sflight-carrid and sflight-connid.

I've my alvtree in the same page, depending of my selection the alvtree show the result but in this moment is when I've the problem.

The first time that I do the selection all goes right, but at the second time that I do the selection the alvtree don't show the right result.

I know that the problem is the refresh but I don't know how to do it, I tryied different kinds of do it, but nothing.

PLEASE HELP ME!

Sample of code for a first sight:

&----


*& Form init_tree

&----


FORM init_tree.

DATA: l_tree_container_name(30) TYPE c,

l_custom_container TYPE REF TO cl_gui_custom_container.

  • create info-table for html-header

DATA: lt_list_commentary TYPE slis_t_listheader,

l_logo TYPE sdydo_value.

  • repid for saving variants

DATA: ls_variant TYPE disvariant.

ls_variant-report = sy-repid.

PERFORM build_fieldcatalog.

<b>PERFORM build_outtab.</b>

PERFORM build_sort_table.

PERFORM build_comment USING

lt_list_commentary

l_logo.

  • create container for alv-tree

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.

  • 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

&----


*& Form BUILD_OUTTAB

&----


<b>FORM build_outtab.</b>

IF tree1 IS INITIAL.

CLEAR gt_sflight.

SELECT *

FROM sflight

INTO TABLE gt_sflight.

ELSE.

CLEAR gt_sflight.

CALL METHOD tree1->delete_all_nodes.

CALL METHOD tree1->refresh_table_display.

SELECT *

FROM sflight

INTO TABLE gt_sflight

WHERE carrid = sflight-carrid

AND connid = sflight-connid.

PERFORM refresh_alv.

ENDIF.

ENDFORM. " BUILD_OUTTAB

Thank You very much for your help in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
952

Hi,

Look at these links, this links having the ALV tree reports

<b>Refresh ALVtree:</b>

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_refresh.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm

Regards

Sudheer

Hi,

Look at these links, this links having the ALV tree reports

<b>Refresh ALVtree:</b>

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_refresh.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm

Regards

Sudheer

3 REPLIES 3
Read only

uwe_schieferstein
Active Contributor
0 Likes
952

Hello Jose

Please have a look at my sample report (copied from BCALC_TREE_DEMO). To find my changes search for <b>'$Comment'</b>.

When the tree is created (in routine CREATE_HIERARCHY) the report stores the node key for carrid = 'AA'.

When you now enter DELETE directly into the command field (top left corner of GUI) then the subtree (with node key = gd_delete_neky) will be deleted. The changes are sent to the frontend by calling method <b>tree1->update_calculations</b>.

[code]&----


*& Report ZUS_SDN_BCALV_TREE_DEMO *

*& *

&----


*& Based on: BCALV_TREE_DEMO *

*& *

&----


REPORT zus_sdn_bcalv_tree_demo.

*$Comment: begin

DATA:

gd_delete_nkey TYPE lvc_nkey.

*$Comment: end

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

*include bcalv_toolbar_event_receiver.

INCLUDE zus_sdn_bcalv_tree_event_rcvr.

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

translate ok_code to upper case.

CASE ok_code.

WHEN 'EXIT' OR 'BACK' OR 'CANC'.

PERFORM exit_program.

*$Comment: begin

WHEN 'DELETE'.

CALL METHOD tree1->delete_subtree

EXPORTING

i_node_key = gd_delete_nkey " = folder 'AA'

  • I_UPDATE_PARENTS_EXPANDER = SPACE

  • I_UPDATE_PARENTS_FOLDER = SPACE

EXCEPTIONS

node_key_not_in_model = 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.

CALL METHOD tree1->update_calculations

EXPORTING

no_frontend_update = ' '. " do frontend update

*$Comment: end

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.

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.

*$Comment: begin

IF ( ls_sflight-carrid = 'AA' ).

gd_delete_nkey = l_carrid_key.

ENDIF.

*$Comment: end

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.

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.

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

Regards

Uwe

Read only

Former Member
0 Likes
953

Hi,

Look at these links, this links having the ALV tree reports

<b>Refresh ALVtree:</b>

http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_refresh.htm

http://www.sapdevelopment.co.uk/reporting/alv/alvtree.htm

Regards

Sudheer

Read only

Former Member
0 Likes
952

Thanks