01-31-2008 9:24 AM
hi all,
What is ALV Tree and give me some example code for ALV Tree.
thnks
durga
01-31-2008 9:26 AM
Hi Durga,
Example for ALV Tree:
program z.
----
Constants *
----
constants: c_me like trdir-cnam value 'VNDOVV',
c_myurl type scarr-url value
'http://www.brainbench.com/transcript.jsp?pid=147699',
c_width type i value 260,
c_height type i value 130.
----
Types *
----
types: begin of t_pgm,
year(4) type c,
name like trdir-name,
end of t_pgm,
begin of t_pgmkey,
id type i,
name like trdir-name,
end of t_pgmkey.
----
Data *
----
data: it_pgmkey type table of t_pgmkey.
----
Classes *
----
----
Definitions *
----
class screen_init definition create private.
public section.
class-methods init_screen returning value(this)
type ref to screen_init.
methods constructor.
private section.
class-data a_id type i.
data: splitter_h type ref to cl_gui_splitter_container,
splitter_v type ref to cl_gui_splitter_container,
picture type ref to cl_gui_picture,
tree type ref to cl_gui_simple_tree.
methods: fill_tree,
fill_picture.
endclass.
----
class screen_handler definition.
public section.
methods: constructor importing container
type ref to cl_gui_container,
handle_node_double_click
for event node_double_click
of cl_gui_simple_tree
importing node_key,
handle_picture_double_click
for event picture_dblclick
of cl_gui_picture.
private section.
data: html_viewer type ref to cl_gui_html_viewer,
editor type ref to cl_gui_textedit.
methods: fill_html,
fill_src importing programid type trdir-name.
endclass.
----
Implementations *
----
class screen_init implementation.
----
method init_screen.
data screen type ref to screen_init.
create object screen.
this = screen.
endmethod.
----
method constructor.
data: events type cntl_simple_events,
event like line of events,
event_handler type ref to screen_handler,
container_left type ref to cl_gui_container,
container_right type ref to cl_gui_container,
container_top type ref to cl_gui_container,
container_bottom type ref to cl_gui_container.
create object splitter_h
exporting
parent = cl_gui_container=>screen0
rows = 1
columns = 2.
call method splitter_h->set_border
exporting border = cl_gui_cfw=>false.
call method splitter_h->set_column_mode
exporting mode = splitter_h->mode_absolute.
call method splitter_h->set_column_width
exporting id = 1
width = c_width.
container_left = splitter_h->get_container( row = 1 column = 1 ).
container_right = splitter_h->get_container( row = 1 column = 2 ).
create object splitter_v
exporting
parent = container_left
rows = 2
columns = 1.
call method splitter_v->set_border
exporting border = cl_gui_cfw=>false.
call method splitter_v->set_row_mode
exporting mode = splitter_v->mode_absolute.
call method splitter_v->set_row_height
exporting id = 1
height = c_height.
container_top = splitter_v->get_container( row = 1 column = 1 ).
container_bottom = splitter_v->get_container( row = 2 column = 1 ).
create object picture
exporting parent = container_top.
create object tree
exporting parent = container_bottom
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_single.
create object event_handler
exporting container = container_right.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = ' '. "system event, does not trigger PAI
append event to events.
call method tree->set_registered_events
exporting events = events.
clear: event, events[].
event-eventid = cl_gui_picture=>eventid_picture_dblclick.
event-appl_event = ' '. "system event, does not trigger PAI
append event to events.
call method picture->set_registered_events
exporting events = events.
set handler: event_handler->handle_node_double_click for tree,
event_handler->handle_picture_double_click for picture.
call method: me->fill_picture,
me->fill_tree.
endmethod.
----
method fill_picture.
call method:
picture->load_picture_from_sap_icons exporting icon = '@J4@',
picture->set_display_mode
exporting display_mode = picture->display_mode_fit_center.
endmethod.
----
method fill_tree.
data: node_table type table of abdemonode,
node type abdemonode,
w_pgm type t_pgm,
w_cdat type rdir_cdate,
it_pgm type table of t_pgm,
w_pgmkey type t_pgmkey.
clear: a_id, it_pgmkey[].
select distinct name cdat from trdir into (w_pgm-name, w_cdat)
where cnam = c_me.
w_pgm-year = w_cdat(4).
append w_pgm to it_pgm.
clear w_pgm.
endselect.
sort it_pgm.
node-hidden = ' '. " All nodes are visible,
node-disabled = ' '. " selectable,
node-isfolder = 'X'. " a folder,
node-expander = ' '. " have no '+' sign for expansion.
loop at it_pgm into w_pgm.
at new year.
node-node_key = w_pgm-year.
clear node-relatkey.
clear node-relatship.
node-text = w_pgm-year.
node-n_image = ' '.
node-exp_image = ' '.
append node to node_table.
endat.
at new name.
add 1 to a_id.
node-node_key = w_pgmkey-id = a_id.
w_pgmkey-name = w_pgm-name.
node-relatkey = w_pgm-year.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = w_pgm-name.
node-n_image = '@0P@'.
node-exp_image = '@0P@'.
append w_pgmkey to it_pgmkey.
endat.
append node to node_table.
endloop.
call method tree->add_nodes
exporting table_structure_name = 'ABDEMONODE'
node_table = node_table.
endmethod.
endclass.
----
class screen_handler implementation.
----
method constructor.
create object: html_viewer exporting parent = container,
editor exporting parent = container
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = 72.
call method: fill_html,
editor->set_readonly_mode exporting readonly_mode = 1.
endmethod.
----
method handle_node_double_click.
data: w_name type programm,
w_id type i,
w_year(4) type c,
w_pgmkey type t_pgmkey.
w_name = node_key+4.
w_id = w_name.
clear w_name.
read table it_pgmkey into w_pgmkey with key id = w_id
binary search.
if sy-subrc = 0.
w_name = w_pgmkey-name.
endif.
w_year = node_key(4).
if w_name is initial.
call method: fill_html,
html_viewer->set_visible exporting visible = 'X',
editor->set_visible exporting visible = ' '.
else.
call method: fill_src exporting programid = w_name,
editor->set_visible exporting visible = 'X',
html_viewer->set_visible exporting visible = ' '.
endif.
call method cl_gui_cfw=>flush.
endmethod.
----
method handle_picture_double_click.
call method: fill_html,
html_viewer->set_visible exporting visible = 'X',
editor->set_visible exporting visible = ' '.
call method cl_gui_cfw=>flush.
endmethod.
----
method fill_html.
call method html_viewer->show_url exporting url = c_myurl.
endmethod.
----
method fill_src.
types t_line(72) type c.
data src type table of t_line.
read report programid into src.
call method: editor->delete_text,
editor->set_text_as_r3table exporting table = src[].
endmethod.
endclass.
----
Data *
----
data this_screen type ref to screen_init.
----
Program execution *
----
load-of-program.
call screen 100.
----
Dialog Modules PBO *
----
module status_0100 output.
set pf-status 'SCREEN_100'.
set titlebar 'TIT_100'.
this_screen = screen_init=>init_screen( ).
endmodule.
----
Dialog Modules PAI *
----
module cancel input.
leave program.
endmodule.
----
See this link for any help on ALV it is very clear in the link:
http://www.geocities.com/victorav15/sapr3/abap_ood.html
Plzz reward if it is useful,
Mahi.
01-31-2008 9:26 AM
Hi Durga,
Example for ALV Tree:
program z.
----
Constants *
----
constants: c_me like trdir-cnam value 'VNDOVV',
c_myurl type scarr-url value
'http://www.brainbench.com/transcript.jsp?pid=147699',
c_width type i value 260,
c_height type i value 130.
----
Types *
----
types: begin of t_pgm,
year(4) type c,
name like trdir-name,
end of t_pgm,
begin of t_pgmkey,
id type i,
name like trdir-name,
end of t_pgmkey.
----
Data *
----
data: it_pgmkey type table of t_pgmkey.
----
Classes *
----
----
Definitions *
----
class screen_init definition create private.
public section.
class-methods init_screen returning value(this)
type ref to screen_init.
methods constructor.
private section.
class-data a_id type i.
data: splitter_h type ref to cl_gui_splitter_container,
splitter_v type ref to cl_gui_splitter_container,
picture type ref to cl_gui_picture,
tree type ref to cl_gui_simple_tree.
methods: fill_tree,
fill_picture.
endclass.
----
class screen_handler definition.
public section.
methods: constructor importing container
type ref to cl_gui_container,
handle_node_double_click
for event node_double_click
of cl_gui_simple_tree
importing node_key,
handle_picture_double_click
for event picture_dblclick
of cl_gui_picture.
private section.
data: html_viewer type ref to cl_gui_html_viewer,
editor type ref to cl_gui_textedit.
methods: fill_html,
fill_src importing programid type trdir-name.
endclass.
----
Implementations *
----
class screen_init implementation.
----
method init_screen.
data screen type ref to screen_init.
create object screen.
this = screen.
endmethod.
----
method constructor.
data: events type cntl_simple_events,
event like line of events,
event_handler type ref to screen_handler,
container_left type ref to cl_gui_container,
container_right type ref to cl_gui_container,
container_top type ref to cl_gui_container,
container_bottom type ref to cl_gui_container.
create object splitter_h
exporting
parent = cl_gui_container=>screen0
rows = 1
columns = 2.
call method splitter_h->set_border
exporting border = cl_gui_cfw=>false.
call method splitter_h->set_column_mode
exporting mode = splitter_h->mode_absolute.
call method splitter_h->set_column_width
exporting id = 1
width = c_width.
container_left = splitter_h->get_container( row = 1 column = 1 ).
container_right = splitter_h->get_container( row = 1 column = 2 ).
create object splitter_v
exporting
parent = container_left
rows = 2
columns = 1.
call method splitter_v->set_border
exporting border = cl_gui_cfw=>false.
call method splitter_v->set_row_mode
exporting mode = splitter_v->mode_absolute.
call method splitter_v->set_row_height
exporting id = 1
height = c_height.
container_top = splitter_v->get_container( row = 1 column = 1 ).
container_bottom = splitter_v->get_container( row = 2 column = 1 ).
create object picture
exporting parent = container_top.
create object tree
exporting parent = container_bottom
node_selection_mode =
cl_gui_simple_tree=>node_sel_mode_single.
create object event_handler
exporting container = container_right.
event-eventid = cl_gui_simple_tree=>eventid_node_double_click.
event-appl_event = ' '. "system event, does not trigger PAI
append event to events.
call method tree->set_registered_events
exporting events = events.
clear: event, events[].
event-eventid = cl_gui_picture=>eventid_picture_dblclick.
event-appl_event = ' '. "system event, does not trigger PAI
append event to events.
call method picture->set_registered_events
exporting events = events.
set handler: event_handler->handle_node_double_click for tree,
event_handler->handle_picture_double_click for picture.
call method: me->fill_picture,
me->fill_tree.
endmethod.
----
method fill_picture.
call method:
picture->load_picture_from_sap_icons exporting icon = '@J4@',
picture->set_display_mode
exporting display_mode = picture->display_mode_fit_center.
endmethod.
----
method fill_tree.
data: node_table type table of abdemonode,
node type abdemonode,
w_pgm type t_pgm,
w_cdat type rdir_cdate,
it_pgm type table of t_pgm,
w_pgmkey type t_pgmkey.
clear: a_id, it_pgmkey[].
select distinct name cdat from trdir into (w_pgm-name, w_cdat)
where cnam = c_me.
w_pgm-year = w_cdat(4).
append w_pgm to it_pgm.
clear w_pgm.
endselect.
sort it_pgm.
node-hidden = ' '. " All nodes are visible,
node-disabled = ' '. " selectable,
node-isfolder = 'X'. " a folder,
node-expander = ' '. " have no '+' sign for expansion.
loop at it_pgm into w_pgm.
at new year.
node-node_key = w_pgm-year.
clear node-relatkey.
clear node-relatship.
node-text = w_pgm-year.
node-n_image = ' '.
node-exp_image = ' '.
append node to node_table.
endat.
at new name.
add 1 to a_id.
node-node_key = w_pgmkey-id = a_id.
w_pgmkey-name = w_pgm-name.
node-relatkey = w_pgm-year.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = w_pgm-name.
node-n_image = '@0P@'.
node-exp_image = '@0P@'.
append w_pgmkey to it_pgmkey.
endat.
append node to node_table.
endloop.
call method tree->add_nodes
exporting table_structure_name = 'ABDEMONODE'
node_table = node_table.
endmethod.
endclass.
----
class screen_handler implementation.
----
method constructor.
create object: html_viewer exporting parent = container,
editor exporting parent = container
wordwrap_mode =
cl_gui_textedit=>wordwrap_at_fixed_position
wordwrap_position = 72.
call method: fill_html,
editor->set_readonly_mode exporting readonly_mode = 1.
endmethod.
----
method handle_node_double_click.
data: w_name type programm,
w_id type i,
w_year(4) type c,
w_pgmkey type t_pgmkey.
w_name = node_key+4.
w_id = w_name.
clear w_name.
read table it_pgmkey into w_pgmkey with key id = w_id
binary search.
if sy-subrc = 0.
w_name = w_pgmkey-name.
endif.
w_year = node_key(4).
if w_name is initial.
call method: fill_html,
html_viewer->set_visible exporting visible = 'X',
editor->set_visible exporting visible = ' '.
else.
call method: fill_src exporting programid = w_name,
editor->set_visible exporting visible = 'X',
html_viewer->set_visible exporting visible = ' '.
endif.
call method cl_gui_cfw=>flush.
endmethod.
----
method handle_picture_double_click.
call method: fill_html,
html_viewer->set_visible exporting visible = 'X',
editor->set_visible exporting visible = ' '.
call method cl_gui_cfw=>flush.
endmethod.
----
method fill_html.
call method html_viewer->show_url exporting url = c_myurl.
endmethod.
----
method fill_src.
types t_line(72) type c.
data src type table of t_line.
read report programid into src.
call method: editor->delete_text,
editor->set_text_as_r3table exporting table = src[].
endmethod.
endclass.
----
Data *
----
data this_screen type ref to screen_init.
----
Program execution *
----
load-of-program.
call screen 100.
----
Dialog Modules PBO *
----
module status_0100 output.
set pf-status 'SCREEN_100'.
set titlebar 'TIT_100'.
this_screen = screen_init=>init_screen( ).
endmodule.
----
Dialog Modules PAI *
----
module cancel input.
leave program.
endmodule.
----
See this link for any help on ALV it is very clear in the link:
http://www.geocities.com/victorav15/sapr3/abap_ood.html
Plzz reward if it is useful,
Mahi.
01-31-2008 9:35 AM
Hi,
this program creates alv tree using the class cl_salv_tree.
please check:
CREATE OBJECT gr_container
EXPORTING
container_name = 'CONTAINER'.
endif.
create an ALV table
TRY.
cl_salv_tree=>factory(
EXPORTING
r_container = gr_container
IMPORTING
r_salv_tree = gr_tree
CHANGING
t_table = dt_changelog_1 ).
CATCH cx_salv_no_new_data_allowed cx_salv_error.
EXIT.
ENDTRY.
PERFORM create_tree.
Functions
activate ALV generic Functions
DATA: lr_functions TYPE REF TO cl_salv_functions_tree.
lr_functions = gr_tree->get_functions( ).
lr_functions->set_all( gc_true ).
*... set the columns technical
DATA: lr_columns TYPE REF TO cl_salv_columns_tree.
lr_columns = gr_tree->get_columns( ).
lr_columns->set_optimize( gc_true ).
PERFORM set_columns_technical USING lr_columns.
display the table
gr_tree->display( ).
FORM create_tree .
PERFORM build_header.
PERFORM supply_data USING dt_changelog.
ENDFORM. " create_tree
FORM build_header .
build the hierarchy header
DATA: settings TYPE REF TO cl_salv_tree_settings.
settings = gr_tree->get_tree_settings( ).
settings->set_hierarchy_header( text-hd1 ).
settings->set_hierarchy_tooltip( text-ht1 ).
settings->set_hierarchy_size( 30 ).
DATA: title TYPE salv_de_tree_text.
title = sy-title.
settings->set_header( title ).
ENDFORM. " build_header
FORM supply_data USING dt_changelog TYPE STANDARD TABLE.
*supply the data to ALV, building the hierarchy
DATA: ls_data TYPE alv_t_t2.
DATA: l_fname_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey.
LOOP AT dt_changelog INTO ds_changelog.
ON CHANGE OF ds_changelog-fname.
PERFORM add_header_line USING ds_changelog
''
CHANGING l_fname_key.
ENDON.
PERFORM add_complete_line USING ds_changelog
l_fname_key
CHANGING l_last_key.
ENDLOOP.
ENDFORM. " supply_data
FORM set_columns_technical USING ir_columns TYPE REF TO cl_salv_columns_tree.
those columns which should not be seen by the user at all are set technical
DATA: lr_column TYPE REF TO cl_salv_column.
TRY.
lr_column = ir_columns->get_column( 'MANDANT' ).
lr_column->set_visible( if_salv_c_bool_sap=>false ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column = ir_columns->get_column( 'ANNS_NUMBER' ).
lr_column->set_visible( if_salv_c_bool_sap=>false ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column = ir_columns->get_column( 'MEMO_NUMBER' ).
lr_column->set_visible( if_salv_c_bool_sap=>false ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lr_column = ir_columns->get_column( 'ITEM_NUMBER' ).
lr_column->set_visible( if_salv_c_bool_sap=>false ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
ENDFORM. " set_columns_technical(
Hope this helps,
Keerthi.
01-31-2008 1:00 PM
Hi ,
In se38 "BcALV*" type and press F-4 you ill get list of all
the example given by SAP .
Reward usefull points .
Regards
Raul