2007 Aug 17 6:32 PM
hi
I want a simple example of ALV tree, I already browsed in SDN for such programs but all I could find was examples of type BCS_ALV* which use SFLIGHT table
But I need programs which use a custom Internal table... which have fields from several tables... not a standard table structure
Please help find such program.. Points will be awarded for every helpful answer
2007 Aug 17 6:49 PM
Hi, Find the below code for alv tree example.
report zmm_alv_tree .
class cl_gui_cfw definition load.
class cl_gui_column_tree definition load.
data : obj_tree type ref to cl_gui_alv_tree,
obj_cont type ref to cl_gui_custom_container.
*TYPES : BEGIN OF t_mara ,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
END OF t_mara.
*
*DATA : it_mara TYPE TABLE OF t_mara ,
it_mara1 TYPE TABLE OF t_mara,
x_mara TYPE t_mara.
data : it_mara type zmara_mano occurs 0 ,
it_mara1 type zmara_mano occurs 0,
x_mara type zmara_mano.
data : ok_code type sy-ucomm,
fcat type lvc_t_fcat ,
g_new_node_key type lvc_nkey.
start-of-selection.
end-of-selection.
call screen 100.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
module status_0100 output.
set pf-status 'ZPF'.
if obj_tree is initial.
perform init_tree.
endif.
endmodule. " STATUS_0100 OUTPUT
&----
*& Form init_tree
&----
text
----
--> p1 text
<-- p2 text
----
form init_tree .
perform build_fcat.
create object obj_cont
exporting
PARENT =
container_name = 'TCONT'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
create object obj_tree
exporting
LIFETIME =
parent = obj_cont
SHELLSTYLE =
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
"cl_gui_column_tree=>node_sel_mode_sin
HIDE_SELECTION =
item_selection = 'X'
NO_TOOLBAR =
NO_HTML_HEADER =
I_PRINT =
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
others = 8
.
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 obj_tree->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_HIERARCHY_HEADER =
IS_EXCEPTION_FIELD =
IT_SPECIAL_GROUPS =
IT_LIST_COMMENTARY =
I_LOGO =
I_BACKGROUND_ID =
IT_TOOLBAR_EXCLUDING =
IT_EXCEPT_QINFO =
changing
it_outtab = it_mara1
IT_FILTER =
it_fieldcatalog = fcat
.
call method obj_tree->expand_node
exporting
i_node_key = g_new_node_key
I_LEVEL_COUNT = 1
I_EXPAND_SUBTREE =
exceptions
failed = 1
illegal_level_count = 2
cntl_system_error = 3
node_not_found = 4
cannot_expand_leaf = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
perform select_data.
loop at it_mara into x_mara.
perform add_details using x_mara.
endloop.
call method obj_tree->frontend_update
.
endform. " init_tree
&----
*& Form build_fcat
&----
text
----
--> p1 text
<-- p2 text
----
form build_fcat .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
I_BUFFER_ACTIVE =
i_structure_name = 'ZMARA_MANO'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
changing
ct_fieldcat = fcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " build_fcat
&----
*& Form select_data
&----
text
----
--> p1 text
<-- p2 text
----
form select_data .
select matnr
ersda
ernam
mtart
into table it_mara
from mara
where mtart = 'FERT'.
endform. " select_data
&----
*& Form add_details
&----
text
----
-->P_X_MARA text
----
form add_details using p_mara type zmara_mano.
data : lv_matnr type lvc_value,
lv_mara type zmara_mano.
lv_matnr = p_mara-matnr.
call method obj_tree->add_node
exporting
i_relat_node_key = ' '
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = lv_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
importing
e_new_node_key = g_new_node_key
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
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 obj_tree->add_node
exporting
i_relat_node_key = g_new_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = p_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
IMPORTING
E_NEW_NODE_KEY =
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " add_details
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
module user_command_0100 input.
case ok_code.
when 'BACK' or 'EXIT' or 'CANCEL'.
leave to screen 0.
when others.
call method cl_gui_cfw=>dispatch .
endcase.
clear ok_code.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3
.
endmodule. " USER_COMMAND_0100 INPUT
Rewards the points, if it is useful for you.
Regards
Ramesh.
Hi, Find the below code for alv tree example.
report zmm_alv_tree .
class cl_gui_cfw definition load.
class cl_gui_column_tree definition load.
data : obj_tree type ref to cl_gui_alv_tree,
obj_cont type ref to cl_gui_custom_container.
*TYPES : BEGIN OF t_mara ,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
END OF t_mara.
*
*DATA : it_mara TYPE TABLE OF t_mara ,
it_mara1 TYPE TABLE OF t_mara,
x_mara TYPE t_mara.
data : it_mara type zmara_mano occurs 0 ,
it_mara1 type zmara_mano occurs 0,
x_mara type zmara_mano.
data : ok_code type sy-ucomm,
fcat type lvc_t_fcat ,
g_new_node_key type lvc_nkey.
start-of-selection.
end-of-selection.
call screen 100.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
module status_0100 output.
set pf-status 'ZPF'.
if obj_tree is initial.
perform init_tree.
endif.
endmodule. " STATUS_0100 OUTPUT
&----
*& Form init_tree
&----
text
----
--> p1 text
<-- p2 text
----
form init_tree .
perform build_fcat.
create object obj_cont
exporting
PARENT =
container_name = 'TCONT'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
create object obj_tree
exporting
LIFETIME =
parent = obj_cont
SHELLSTYLE =
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
"cl_gui_column_tree=>node_sel_mode_sin
HIDE_SELECTION =
item_selection = 'X'
NO_TOOLBAR =
NO_HTML_HEADER =
I_PRINT =
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
others = 8
.
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 obj_tree->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_HIERARCHY_HEADER =
IS_EXCEPTION_FIELD =
IT_SPECIAL_GROUPS =
IT_LIST_COMMENTARY =
I_LOGO =
I_BACKGROUND_ID =
IT_TOOLBAR_EXCLUDING =
IT_EXCEPT_QINFO =
changing
it_outtab = it_mara1
IT_FILTER =
it_fieldcatalog = fcat
.
call method obj_tree->expand_node
exporting
i_node_key = g_new_node_key
I_LEVEL_COUNT = 1
I_EXPAND_SUBTREE =
exceptions
failed = 1
illegal_level_count = 2
cntl_system_error = 3
node_not_found = 4
cannot_expand_leaf = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
perform select_data.
loop at it_mara into x_mara.
perform add_details using x_mara.
endloop.
call method obj_tree->frontend_update
.
endform. " init_tree
&----
*& Form build_fcat
&----
text
----
--> p1 text
<-- p2 text
----
form build_fcat .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
I_BUFFER_ACTIVE =
i_structure_name = 'ZMARA_MANO'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
changing
ct_fieldcat = fcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " build_fcat
&----
*& Form select_data
&----
text
----
--> p1 text
<-- p2 text
----
form select_data .
select matnr
ersda
ernam
mtart
into table it_mara
from mara
where mtart = 'FERT'.
endform. " select_data
&----
*& Form add_details
&----
text
----
-->P_X_MARA text
----
form add_details using p_mara type zmara_mano.
data : lv_matnr type lvc_value,
lv_mara type zmara_mano.
lv_matnr = p_mara-matnr.
call method obj_tree->add_node
exporting
i_relat_node_key = ' '
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = lv_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
importing
e_new_node_key = g_new_node_key
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
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 obj_tree->add_node
exporting
i_relat_node_key = g_new_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = p_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
IMPORTING
E_NEW_NODE_KEY =
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " add_details
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
module user_command_0100 input.
case ok_code.
when 'BACK' or 'EXIT' or 'CANCEL'.
leave to screen 0.
when others.
call method cl_gui_cfw=>dispatch .
endcase.
clear ok_code.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3
.
endmodule. " USER_COMMAND_0100 INPUT
Rewards the points, if it is useful for you.
Regards
Ramesh.
2007 Aug 17 6:45 PM
Hi,
I suggest better to start with BCALV_TEST_SIMPLE_TREE it is using the class
cl_gui_alv_tree_simple
if gr_container_d0100 is initial.
create object gr_container_d0100
exporting
container_name = 'D0100_CONTAINER'.
create object gr_tree_d0100
exporting
i_parent = gr_container_d0100
i_node_selection_mode
= cl_gui_column_tree=>node_sel_mode_single
i_item_selection = space.
perform d0100_get_outtab.
perform d0100_set_grid_vari changing ls_vari.
perform d0100_set_grid_layo changing ls_layo.
perform d0100_set_grid_fcat changing lt_fcat.
perform d0100_set_grid_sort changing lt_sort.
perform d0100_set_tree_header changing lt_tree_header.
perform d0100_set_tree_hhead changing l_hhead.
call method gr_tree_d0100->set_table_for_first_display
exporting
is_variant = ls_vari
i_save = 'A'
i_default = con_true
is_layout = ls_layo
it_list_commentary = lt_tree_header
i_background_id = 'ALV_BACKGROUND'
changing
it_outtab = gt_outtab
it_fieldcatalog = lt_fcat
it_sort = lt_sort.
call method gr_tree_d0100->frontend_update.
call method cl_gui_cfw=>flush.
call method cl_gui_control=>set_focus
exporting
control = gr_tree_d0100.
endif.
If you check the real piece of code is simple.
a®
2007 Aug 17 6:49 PM
Hi, Find the below code for alv tree example.
report zmm_alv_tree .
class cl_gui_cfw definition load.
class cl_gui_column_tree definition load.
data : obj_tree type ref to cl_gui_alv_tree,
obj_cont type ref to cl_gui_custom_container.
*TYPES : BEGIN OF t_mara ,
matnr TYPE matnr,
ersda TYPE ersda,
ernam TYPE ernam,
mtart TYPE mtart,
END OF t_mara.
*
*DATA : it_mara TYPE TABLE OF t_mara ,
it_mara1 TYPE TABLE OF t_mara,
x_mara TYPE t_mara.
data : it_mara type zmara_mano occurs 0 ,
it_mara1 type zmara_mano occurs 0,
x_mara type zmara_mano.
data : ok_code type sy-ucomm,
fcat type lvc_t_fcat ,
g_new_node_key type lvc_nkey.
start-of-selection.
end-of-selection.
call screen 100.
&----
*& Module STATUS_0100 OUTPUT
&----
text
----
module status_0100 output.
set pf-status 'ZPF'.
if obj_tree is initial.
perform init_tree.
endif.
endmodule. " STATUS_0100 OUTPUT
&----
*& Form init_tree
&----
text
----
--> p1 text
<-- p2 text
----
form init_tree .
perform build_fcat.
create object obj_cont
exporting
PARENT =
container_name = 'TCONT'
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
create object obj_tree
exporting
LIFETIME =
parent = obj_cont
SHELLSTYLE =
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
"cl_gui_column_tree=>node_sel_mode_sin
HIDE_SELECTION =
item_selection = 'X'
NO_TOOLBAR =
NO_HTML_HEADER =
I_PRINT =
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
others = 8
.
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 obj_tree->set_table_for_first_display
EXPORTING
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_HIERARCHY_HEADER =
IS_EXCEPTION_FIELD =
IT_SPECIAL_GROUPS =
IT_LIST_COMMENTARY =
I_LOGO =
I_BACKGROUND_ID =
IT_TOOLBAR_EXCLUDING =
IT_EXCEPT_QINFO =
changing
it_outtab = it_mara1
IT_FILTER =
it_fieldcatalog = fcat
.
call method obj_tree->expand_node
exporting
i_node_key = g_new_node_key
I_LEVEL_COUNT = 1
I_EXPAND_SUBTREE =
exceptions
failed = 1
illegal_level_count = 2
cntl_system_error = 3
node_not_found = 4
cannot_expand_leaf = 5
others = 6
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
perform select_data.
loop at it_mara into x_mara.
perform add_details using x_mara.
endloop.
call method obj_tree->frontend_update
.
endform. " init_tree
&----
*& Form build_fcat
&----
text
----
--> p1 text
<-- p2 text
----
form build_fcat .
call function 'LVC_FIELDCATALOG_MERGE'
exporting
I_BUFFER_ACTIVE =
i_structure_name = 'ZMARA_MANO'
I_CLIENT_NEVER_DISPLAY = 'X'
I_BYPASSING_BUFFER =
I_INTERNAL_TABNAME =
changing
ct_fieldcat = fcat
exceptions
inconsistent_interface = 1
program_error = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " build_fcat
&----
*& Form select_data
&----
text
----
--> p1 text
<-- p2 text
----
form select_data .
select matnr
ersda
ernam
mtart
into table it_mara
from mara
where mtart = 'FERT'.
endform. " select_data
&----
*& Form add_details
&----
text
----
-->P_X_MARA text
----
form add_details using p_mara type zmara_mano.
data : lv_matnr type lvc_value,
lv_mara type zmara_mano.
lv_matnr = p_mara-matnr.
call method obj_tree->add_node
exporting
i_relat_node_key = ' '
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = lv_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
importing
e_new_node_key = g_new_node_key
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
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 obj_tree->add_node
exporting
i_relat_node_key = g_new_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = p_mara
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = lv_matnr
IMPORTING
E_NEW_NODE_KEY =
exceptions
relat_node_not_found = 1
node_not_found = 2
others = 3
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " add_details
&----
*& Module USER_COMMAND_0100 INPUT
&----
text
----
module user_command_0100 input.
case ok_code.
when 'BACK' or 'EXIT' or 'CANCEL'.
leave to screen 0.
when others.
call method cl_gui_cfw=>dispatch .
endcase.
clear ok_code.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3
.
endmodule. " USER_COMMAND_0100 INPUT
Rewards the points, if it is useful for you.
Regards
Ramesh.
2007 Aug 18 4:22 AM
Thank you very much... I just got what I want
I wasnt able to load data into my container earlier with the one I have created, your example helped me solve it
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |