2010 May 14 6:24 AM
hi all,
i had an requirement to do an alv report with tree nodes without using oops concept if any examples are there please let me know i had searched in bcal* but all the reports are using oops concept please help me.
regards,
karthik
2010 May 15 3:35 PM
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
§1a. Define reference variables
data: g_alv_tree type ref to cl_gui_alv_tree,
g_custom_container type ref to cl_gui_custom_container.
data: gt_sflight type sflight occurs 0, u201COutput-Table
ok_code like sy-ucomm,
save_ok like sy-ucomm, u201COK-Code
g_max type i value 255.
end-of-selection.
call screen 100.
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Module PBO OUTPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
process before output
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
module pbo output.
set pf-status u2018MAIN100u2032.
set titlebar u2018MAINTITLEu2019.
if g_alv_tree is initial.
perform init_tree.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc ne 0.
call function u2018POPUP_TO_INFORMu2019
exporting
titel = u2018Automation Queue failureu2019(801)
txt1 = u2018Internal error:u2019(802)
txt2 = u2018A method in the automation queueu2019(803)
txt3 = u2019caused a failure.u2019(804).
endif.
endif.
endmodule. u201C PBO OUTPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Module PAI INPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
process after input
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
module pai input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when u2018EXITu2019 or u2018BACKu2019 or u2018CANCu2019.
perform exit_program.
when others.
§6. Call dispatch to process toolbar functions
call method cl_gui_cfw=>dispatch.
endcase.
call method cl_gui_cfw=>flush.
endmodule. u201C PAI INPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form init_tree
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013> p1 text
<u2013 p2 text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form init_tree.
§1b. Create ALV Tree Control and corresponding Container.
create container for alv-tree
data: l_tree_container_name(30) type c.
l_tree_container_name = u2018CCONTAINER1u2032.
create object g_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 u2018ERRORu2019(100).
endif.
create tree control
create object g_alv_tree
exporting
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = u2018Xu2019
no_html_header = u2018Xu2019
no_toolbar = u201D
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 u2018ERRORu2019. u201C#EC NOTEXT
endif.
§2. Create Hierarchy-header
The simple ALV Tree uses the text of the fields which were used
for sorting to define this header. When you use
the u2019normalu2019 ALV Tree the hierarchy is build up freely
by the programmer this is not possible, so he has to define it
himself.
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
§3. Create empty Tree Control
IMPORTANT: Table u2019gt_sflightu2019 must be empty. Do not change this table
(even after this method call). You can change data of your table
by calling methods of CL_GUI_ALV_TREE.
Furthermore, the output table u2019gt_outtabu2019 must be global and can
only be used for one ALV Tree Control.
call method g_alv_tree->set_table_for_first_display
exporting
i_structure_name = u2018SFLIGHTu2019
is_hierarchy_header = l_hierarchy_header
changing
it_outtab = gt_sflight. u201Ctable must be empty !
§4. Create hierarchy (nodes and leaves)
perform create_hierarchy.
§5. Send data to frontend.
call method g_alv_tree->frontend_update.
wait for automatic flush at end of pbo
endform. u201C init_tree
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form build_hierarchy_header
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
build hierarchy-header-information
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013>P_L_HIERARCHY_HEADER strucxture for hierarchy-header
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = u2018Month/Carrier/Dateu2019(300).
p_hierarchy_header-tooltip = u2018Flights in a monthu2019(400).
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = u2018 u2019.
endform. u201C build_hierarchy_header
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form exit_program
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
free object and leave program
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form exit_program.
call method g_custom_container->free.
leave program.
endform. u201C exit_program
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form create_hierarchy
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013> p1 text
<u2013 p2 text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0,
l_yyyymm(6) type c, u201Cyear and month of sflight-fldate
l_yyyymm_last(6) type c,
l_carrid like sflight-carrid,
l_carrid_last like sflight-carrid.
data: l_month_key type lvc_nkey,
l_carrid_key type lvc_nkey,
l_last_key type lvc_nkey.
§4a. Select data
select * from sflight into table lt_sflight up to g_max rows.
§4b. Sort output table according to your conceived hierarchy
We sort in this order:
year and month (top level nodes, yyyymm of DATS)
carrier id (next level)
day of month (leaves, dd of DATS)
sort lt_sflight by fldate0(6) carrid fldate6(2).
Note: The top level nodes do not correspond to a field of the
output table. Instead we use data of the table to invent another
hierarchy level above the levels that can be build by sorting.
§4c. Add data to tree
loop at lt_sflight into ls_sflight.
Prerequesite: The table is sorted.
You add a node everytime the values of a sorted field changes.
Finally, the complete line is added as a leaf below the last
node.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
Top level nodes:
if l_yyyymm <> l_yyyymm_last. u201Con change of l_yyyymm
l_yyyymm_last = l_yyyymm.
*Providing no key means that the node is added on top level:
perform add_month using l_yyyymm
u201D
changing l_month_key.
The month changed, thus, there is no predecessor carrier
clear l_carrid_last.
endif.
Carrier nodes:
(always inserted as child of the last month
which is identified by u2019l_month_keyu2019)
if l_carrid <> l_carrid_last. u201Con change of l_carrid
l_carrid_last = l_carrid.
perform add_carrid_line using ls_sflight
l_month_key
changing l_carrid_key.
endif.
Leaf:
(always inserted as child of the last carrier
which is identified by u2019l_carrid_keyu2019)
perform add_complete_line using ls_sflight
l_carrid_key
changing l_last_key.
endloop.
endform. u201C create_hierarchy
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form add_month
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form add_month using p_yyyymm type c
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight,
l_month(15) type c. u201Coutput string for month
get month name for node text
perform get_month using p_yyyymm
changing l_month.
l_node_text = l_month.
add node:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form u2019add_carrid_lineu2019
the leaf gets a child and thus ALV converts it to a folder
automatically.
*
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.
endform. u201C add_month
*u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
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.
add node
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form u2019add_carrid_lineu2019
the leaf gets a child and thus ALV converts it to a folder
automatically.
*
l_node_text = ps_sflight-carrid.
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.
endform. u201C add_carrid_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form add_complete_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
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.
write ps_sflight-fldate to l_node_text mm/dd/yyyy.
add leaf:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set.
Since these nodes will never get children they stay leaves
(as intended).
*
call method g_alv_tree->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
importing
e_new_node_key = p_node_key.
endform. u201C add_complete_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form GET_MONTH
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013>P_P_YYYYMM text
<u2013P_L_MONTH text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form get_month using p_yyyymm
changing p_month.
Returns the name of month according to the digits in p_yyyymm
data: l_monthdigits(2) type c.
l_monthdigits = p_yyyymm+4(2).
case l_monthdigits.
when u201801u2032.
p_month = u2018Januaryu2019(701).
when u201802u2032.
p_month = u2018Februaryu2019(702).
when u201803u2032.
p_month = u2018Marchu2019(703).
when u201804u2032.
p_month = u2018Aprilu2019(704).
when u201805u2032.
p_month = u2018Mayu2019(705).
when u201806u2032.
p_month = u2018Juneu2019(706).
when u201807u2032.
p_month = u2018Julyu2019(707).
when u201808u2032.
p_month = u2018Augustu2019(708).
when u201809u2032.
p_month = u2018Septemberu2019(709).
when u201810u2032.
p_month = u2018Octoberu2019(710).
when u201811u2032.
p_month = u2018Novemberu2019(711).
when u201812u2032.
p_month = u2018Decemberu2019(712).
endcase.
concatenate p_yyyymm+0(4) u2018->u2019 p_month into p_month.
endform. u201C GET_MONTH
hi all,
i had an requirement to do an alv report with tree nodes without using oops concept if any examples are there please let me know i had searched in bcal* but all the reports are using oops concept please help me.
regards,
karthik
2010 May 14 10:12 AM
whats the problem in using OO concepts ??
Really strange to hear!!!
2010 May 15 3:35 PM
*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
§1a. Define reference variables
data: g_alv_tree type ref to cl_gui_alv_tree,
g_custom_container type ref to cl_gui_custom_container.
data: gt_sflight type sflight occurs 0, u201COutput-Table
ok_code like sy-ucomm,
save_ok like sy-ucomm, u201COK-Code
g_max type i value 255.
end-of-selection.
call screen 100.
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Module PBO OUTPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
process before output
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
module pbo output.
set pf-status u2018MAIN100u2032.
set titlebar u2018MAINTITLEu2019.
if g_alv_tree is initial.
perform init_tree.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2.
if sy-subrc ne 0.
call function u2018POPUP_TO_INFORMu2019
exporting
titel = u2018Automation Queue failureu2019(801)
txt1 = u2018Internal error:u2019(802)
txt2 = u2018A method in the automation queueu2019(803)
txt3 = u2019caused a failure.u2019(804).
endif.
endif.
endmodule. u201C PBO OUTPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Module PAI INPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
process after input
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
module pai input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when u2018EXITu2019 or u2018BACKu2019 or u2018CANCu2019.
perform exit_program.
when others.
§6. Call dispatch to process toolbar functions
call method cl_gui_cfw=>dispatch.
endcase.
call method cl_gui_cfw=>flush.
endmodule. u201C PAI INPUT
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form init_tree
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013> p1 text
<u2013 p2 text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form init_tree.
§1b. Create ALV Tree Control and corresponding Container.
create container for alv-tree
data: l_tree_container_name(30) type c.
l_tree_container_name = u2018CCONTAINER1u2032.
create object g_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 u2018ERRORu2019(100).
endif.
create tree control
create object g_alv_tree
exporting
parent = g_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = u2018Xu2019
no_html_header = u2018Xu2019
no_toolbar = u201D
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 u2018ERRORu2019. u201C#EC NOTEXT
endif.
§2. Create Hierarchy-header
The simple ALV Tree uses the text of the fields which were used
for sorting to define this header. When you use
the u2019normalu2019 ALV Tree the hierarchy is build up freely
by the programmer this is not possible, so he has to define it
himself.
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
§3. Create empty Tree Control
IMPORTANT: Table u2019gt_sflightu2019 must be empty. Do not change this table
(even after this method call). You can change data of your table
by calling methods of CL_GUI_ALV_TREE.
Furthermore, the output table u2019gt_outtabu2019 must be global and can
only be used for one ALV Tree Control.
call method g_alv_tree->set_table_for_first_display
exporting
i_structure_name = u2018SFLIGHTu2019
is_hierarchy_header = l_hierarchy_header
changing
it_outtab = gt_sflight. u201Ctable must be empty !
§4. Create hierarchy (nodes and leaves)
perform create_hierarchy.
§5. Send data to frontend.
call method g_alv_tree->frontend_update.
wait for automatic flush at end of pbo
endform. u201C init_tree
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form build_hierarchy_header
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
build hierarchy-header-information
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013>P_L_HIERARCHY_HEADER strucxture for hierarchy-header
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = u2018Month/Carrier/Dateu2019(300).
p_hierarchy_header-tooltip = u2018Flights in a monthu2019(400).
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = u2018 u2019.
endform. u201C build_hierarchy_header
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form exit_program
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
free object and leave program
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form exit_program.
call method g_custom_container->free.
leave program.
endform. u201C exit_program
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form create_hierarchy
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013> p1 text
<u2013 p2 text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form create_hierarchy.
data: ls_sflight type sflight,
lt_sflight type sflight occurs 0,
l_yyyymm(6) type c, u201Cyear and month of sflight-fldate
l_yyyymm_last(6) type c,
l_carrid like sflight-carrid,
l_carrid_last like sflight-carrid.
data: l_month_key type lvc_nkey,
l_carrid_key type lvc_nkey,
l_last_key type lvc_nkey.
§4a. Select data
select * from sflight into table lt_sflight up to g_max rows.
§4b. Sort output table according to your conceived hierarchy
We sort in this order:
year and month (top level nodes, yyyymm of DATS)
carrier id (next level)
day of month (leaves, dd of DATS)
sort lt_sflight by fldate0(6) carrid fldate6(2).
Note: The top level nodes do not correspond to a field of the
output table. Instead we use data of the table to invent another
hierarchy level above the levels that can be build by sorting.
§4c. Add data to tree
loop at lt_sflight into ls_sflight.
Prerequesite: The table is sorted.
You add a node everytime the values of a sorted field changes.
Finally, the complete line is added as a leaf below the last
node.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
Top level nodes:
if l_yyyymm <> l_yyyymm_last. u201Con change of l_yyyymm
l_yyyymm_last = l_yyyymm.
*Providing no key means that the node is added on top level:
perform add_month using l_yyyymm
u201D
changing l_month_key.
The month changed, thus, there is no predecessor carrier
clear l_carrid_last.
endif.
Carrier nodes:
(always inserted as child of the last month
which is identified by u2019l_month_keyu2019)
if l_carrid <> l_carrid_last. u201Con change of l_carrid
l_carrid_last = l_carrid.
perform add_carrid_line using ls_sflight
l_month_key
changing l_carrid_key.
endif.
Leaf:
(always inserted as child of the last carrier
which is identified by u2019l_carrid_keyu2019)
perform add_complete_line using ls_sflight
l_carrid_key
changing l_last_key.
endloop.
endform. u201C create_hierarchy
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form add_month
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
form add_month using p_yyyymm type c
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_sflight type sflight,
l_month(15) type c. u201Coutput string for month
get month name for node text
perform get_month using p_yyyymm
changing l_month.
l_node_text = l_month.
add node:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form u2019add_carrid_lineu2019
the leaf gets a child and thus ALV converts it to a folder
automatically.
*
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.
endform. u201C add_month
*u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2013
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.
add node
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set. In form u2019add_carrid_lineu2019
the leaf gets a child and thus ALV converts it to a folder
automatically.
*
l_node_text = ps_sflight-carrid.
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.
endform. u201C add_carrid_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form add_complete_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
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.
write ps_sflight-fldate to l_node_text mm/dd/yyyy.
add leaf:
ALV Tree firstly inserts this node as a leaf if you do not provide
IS_NODE_LAYOUT with field ISFOLDER set.
Since these nodes will never get children they stay leaves
(as intended).
*
call method g_alv_tree->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
importing
e_new_node_key = p_node_key.
endform. u201C add_complete_line
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
*& Form GET_MONTH
&u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014
text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
u2013>P_P_YYYYMM text
<u2013P_L_MONTH text
u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014u2014-
form get_month using p_yyyymm
changing p_month.
Returns the name of month according to the digits in p_yyyymm
data: l_monthdigits(2) type c.
l_monthdigits = p_yyyymm+4(2).
case l_monthdigits.
when u201801u2032.
p_month = u2018Januaryu2019(701).
when u201802u2032.
p_month = u2018Februaryu2019(702).
when u201803u2032.
p_month = u2018Marchu2019(703).
when u201804u2032.
p_month = u2018Aprilu2019(704).
when u201805u2032.
p_month = u2018Mayu2019(705).
when u201806u2032.
p_month = u2018Juneu2019(706).
when u201807u2032.
p_month = u2018Julyu2019(707).
when u201808u2032.
p_month = u2018Augustu2019(708).
when u201809u2032.
p_month = u2018Septemberu2019(709).
when u201810u2032.
p_month = u2018Octoberu2019(710).
when u201811u2032.
p_month = u2018Novemberu2019(711).
when u201812u2032.
p_month = u2018Decemberu2019(712).
endcase.
concatenate p_yyyymm+0(4) u2018->u2019 p_month into p_month.
endform. u201C GET_MONTH
2010 May 17 8:09 AM
hi,
in transaction SE24>Display object "CL_SALV_TREE">Click Button CLASS DOCUMENTATION.
In the documentation, at the end you can find gud example.
Reg,
NJ
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |