filmov
tv
Video 9: ABAP for ALL - OO ALV Tree Structure
Показать описание
Explained the way to understand the ALV tree structure design.
Program Code: (Angle brackets removed, please add it after copy paste the code)
TYPES: BEGIN OF stu_porders,
aufnr TYPE aufnr,
aufpl TYPE co_aufpl,
vornr TYPE vornr,
END OF stu_porders.
DATA: it_data TYPE TABLE OF stu_porders,
it_data_tree type TABLE OF stu_porders.
DATA: obj_tree TYPE REF TO cl_salv_tree,
obj_nodes TYPE REF TO cl_salv_nodes,
obj_node TYPE REF TO cl_salv_node,
obj_settings TYPE REF TO cl_salv_tree_settings.
* Step 1 - get ref. obj_tree
TRY.
CALL METHOD cl_salv_tree=factory
IMPORTING
r_salv_tree = obj_tree
CHANGING
t_table = it_data.
CATCH cx_salv_error .
ENDTRY.
*Step 2 - Header Settings
obj_settings = obj_tree-get_tree_settings( ).
obj_settings-set_header( 'ALV Tree Samples' ).
obj_settings-set_hierarchy_header( 'Order Hir' ).
obj_settings-set_hierarchy_tooltip( 'Test' ).
obj_settings-set_hierarchy_size( 20 ).
* Step 3 - read the nodes
obj_nodes = obj_tree-get_nodes( ).
if 1 = 2.
* Step 4 - data to ALV trees
DO 5 TIMES.
obj_node = obj_nodes-add_node( related_node = ' '
text = 'Parent 1'
relationship = ' ' ).
data(lv_parent_key) = obj_node-get_key( ).
obj_node = obj_nodes-add_node( related_node = lv_parent_key
text = 'Child 1'
relationship = cl_gui_column_tree=relat_first_child ).
data(lv_child_key) = obj_node-get_key( ).
obj_node = obj_nodes-add_node( related_node = lv_child_key
text = 'Child 1A'
relationship = cl_gui_column_tree=relat_first_sibling ).
ENDDO.
ENDIF.
Select aufnr afko~aufpl vornr from afko INNER JOIN afvc
on afko~aufpl = afvc~aufpl
into table it_data_tree UP TO 100 rows.
data lv_text type lvc_value.
LOOP AT it_data_tree into data(wa_data).
CONCATENATE 'Order Number' wa_data-aufnr into lv_text SEPARATED BY space.
on CHANGE OF wa_data-aufnr.
obj_node = obj_nodes-add_node( related_node = ' '
text = lv_text
* data_row = wa_data
relationship = ' ' ).
data(lv_order_key) = obj_node-get_key( ).
endon.
on CHANGE OF wa_data-aufpl.
CONCATENATE 'Activity' wa_data-aufpl into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_order_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).
data(lv_activity_key) = obj_node-get_key( ).
endon.
CONCATENATE 'Operations' wa_data-vornr into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_activity_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).
ENDLOOP.
* Step 5 - display the tree
obj_tree-display( ).
Program Code: (Angle brackets removed, please add it after copy paste the code)
TYPES: BEGIN OF stu_porders,
aufnr TYPE aufnr,
aufpl TYPE co_aufpl,
vornr TYPE vornr,
END OF stu_porders.
DATA: it_data TYPE TABLE OF stu_porders,
it_data_tree type TABLE OF stu_porders.
DATA: obj_tree TYPE REF TO cl_salv_tree,
obj_nodes TYPE REF TO cl_salv_nodes,
obj_node TYPE REF TO cl_salv_node,
obj_settings TYPE REF TO cl_salv_tree_settings.
* Step 1 - get ref. obj_tree
TRY.
CALL METHOD cl_salv_tree=factory
IMPORTING
r_salv_tree = obj_tree
CHANGING
t_table = it_data.
CATCH cx_salv_error .
ENDTRY.
*Step 2 - Header Settings
obj_settings = obj_tree-get_tree_settings( ).
obj_settings-set_header( 'ALV Tree Samples' ).
obj_settings-set_hierarchy_header( 'Order Hir' ).
obj_settings-set_hierarchy_tooltip( 'Test' ).
obj_settings-set_hierarchy_size( 20 ).
* Step 3 - read the nodes
obj_nodes = obj_tree-get_nodes( ).
if 1 = 2.
* Step 4 - data to ALV trees
DO 5 TIMES.
obj_node = obj_nodes-add_node( related_node = ' '
text = 'Parent 1'
relationship = ' ' ).
data(lv_parent_key) = obj_node-get_key( ).
obj_node = obj_nodes-add_node( related_node = lv_parent_key
text = 'Child 1'
relationship = cl_gui_column_tree=relat_first_child ).
data(lv_child_key) = obj_node-get_key( ).
obj_node = obj_nodes-add_node( related_node = lv_child_key
text = 'Child 1A'
relationship = cl_gui_column_tree=relat_first_sibling ).
ENDDO.
ENDIF.
Select aufnr afko~aufpl vornr from afko INNER JOIN afvc
on afko~aufpl = afvc~aufpl
into table it_data_tree UP TO 100 rows.
data lv_text type lvc_value.
LOOP AT it_data_tree into data(wa_data).
CONCATENATE 'Order Number' wa_data-aufnr into lv_text SEPARATED BY space.
on CHANGE OF wa_data-aufnr.
obj_node = obj_nodes-add_node( related_node = ' '
text = lv_text
* data_row = wa_data
relationship = ' ' ).
data(lv_order_key) = obj_node-get_key( ).
endon.
on CHANGE OF wa_data-aufpl.
CONCATENATE 'Activity' wa_data-aufpl into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_order_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).
data(lv_activity_key) = obj_node-get_key( ).
endon.
CONCATENATE 'Operations' wa_data-vornr into lv_text SEPARATED BY space.
obj_node = obj_nodes-add_node( related_node = lv_activity_key
text = lv_text
data_row = wa_data
relationship = cl_gui_column_tree=relat_first_child ).
ENDLOOP.
* Step 5 - display the tree
obj_tree-display( ).
Комментарии