‎2007 Apr 28 6:03 AM
I want to Display Data from 3 tables in Alv tree format..
i.e all the headings for the 3 tables should come one after another and
the corresponding data (3 tables) below those headings....(strictly in tree format)
i am not getting what method to use...
please if it's possible anyone can help me, since i am struggling to acheive this requirement for past 1 week .
‎2007 Apr 29 9:05 PM
Hello Nagaraju
The ALV tree is not intended for displaying different tables but just for the <i>hierarchical tree display of a <b>single </b>table</i> (for examples see reports <b>BCALV_TREE_DEMO</b> and <b>BCALV_TREE_01</b>).
Have a look at the samples shown in the reuse library (<b>SE83</b>) or the Development Workbench Demos (<b>DWDM</b>). Perhaps you will find a tree display there that fits your requirements.
If I understand you correctly then you want to display three different trees within the same tree display. This means that you have to look for the most flexible way of building trees (with heterogeous columns or, in "tree terminology", heterogenous items).
Regards
Uwe
‎2007 Apr 30 6:30 AM
hi Nagaraju,
this example may help u. pls, go thruough it.
data:
begin of fs_spfli,
expand.
include structure spfli.
data end of fs_spfli.
data: gr_table type ref to cl_salv_hierseq_table.
data: ispfli like table of fs_spfli.
data: isflight type table of sflight.
data: ibinding type salv_t_hierseq_binding.
data: xbinding type salv_s_hierseq_binding.
data: gr_functions type ref to cl_salv_functions.
data: gr_columns type ref to cl_salv_columns_hierseq.
data: gr_column type ref to cl_salv_column_hierseq.
data: gr_level type ref to cl_salv_hierseq_level.
select * into corresponding fields of table ispfli from spfli.
select * into table isflight from sflight.
xbinding-master = 'CARRID'.
xbinding-slave = 'CARRID'.
append xbinding to ibinding.
xbinding-master = 'CONNID'.
xbinding-slave = 'CONNID'.
append xbinding to ibinding.
cl_salv_hierseq_table=>factory(
exporting
t_binding_level1_level2 = ibinding
importing
r_hierseq = gr_table
changing
t_table_level1 = ispfli
t_table_level2 = isflight ).
gr_functions = gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
gr_columns = gr_table->get_columns( level = 1 ).
gr_columns->set_expand_column( 'EXPAND' ).
gr_level = gr_table->get_level( 1 ).
gr_level->set_items_expanded( ).
gr_table->display( ). <b></b>
regards,
Naresh.
‎2007 Apr 30 10:24 AM
hi,
ALV TREE
check these links.
http://www.erpgenie.com/sap/abap/SalesOrderFlow.htm
http://www.sapdevelopment.co.uk/reporting/alv/alvtree/alvtree_basic.htm
Check these programs.
e.g
BCALV_TREE_01 ALV tree control: build up the hierarchy tree
BCALV_TREE_02 ALV tree control: event handling
BCALV_TREE_03 ALV tree control: use an own context menu
BCALV_TREE_04 ALV tree control: add a button to the toolbar
BCALV_TREE_05 ALV tree control: add a menu to the toolbar
BCALV_TREE_06 ALV tree control: Icon column and icon for nodes/items
BCALV_TREE_DEMO Demo for ALV tree control
BCALV_TREE_DND ALV tree control: Drag & Drop within a hierarchy tree
BCALV_TREE_DND_MULTIPLE ALV tree control: Drag & Drop within a hierarchy tree
BCALV_TREE_EVENT_RECEIVER Include BCALV_TREE_EVENT_RECEIVER
BCALV_TREE_EVENT_RECEIVER01
BCALV_TREE_ITEMLAYOUT ALV Tree: Change Item Layouts at Runtime
BCALV_TREE_MOVE_NODE_TEST Demo for ALV tree control
BCALV_TREE_SIMPLE_DEMO Program BCALV_TREE_SIMPLE_DEMO
BCALV_TREE_VERIFY Verifier for ALV Tree and Simple ALV Tree
Also please check the transaction DWDM This will give info also on trees.
‎2007 Apr 30 11:12 AM
Hello nagaraju,
Check out the code below , it will definitely help you
PROGRAM ZSAC_PROMGMT1.
*tables : ZPM_EMP_HEAD_DET,
ZPM_EMP_ITEM_DET,
ZPM_PROJECT_DET,
ZPM_PROJECT_ITEM.
*
***********PROJECT INTERNAL TABLE *************
DATA : lt_proj_header TYPE TABLE OF ZPM_EMP_HEAD_DET,
lt_proj_item_det TYPE TABLE OF ZPM_PROJECT_ITEM.
DATA: lt_emp_header TYPE TABLE OF zpm_emp_head_det,
lt_emp_item_det TYPE TABLE OF zpm_emp_item_det,
lt_emp_leave TYPE TABLE OF zpm_emp_leave,
lt_project_det TYPE TABLE OF zpm_project_det,
lt_project_item TYPE TABLE OF zpm_project_item,
lt_task_master TYPE TABLE OF zpm_task_master.
DATA : lt_emp_det type zpm_emp_det occurs 0.
DATA: ls_emp_header LIKE LINE OF lt_emp_header,
ls_emp_item_det LIKE LINE OF lt_emp_item_det,
ls_emp_leave LIKE LINE OF lt_emp_leave,
ls_project_det LIKE LINE OF lt_project_det,
ls_project_item LIKE LINE OF lt_project_item,
ls_task_master LIKE LINE OF lt_task_master.
*********EMPLOYEE INTERNAL TABLES**************
*DATA : lt_emp_header TYPE TABLE OF ZPM_PROJECT_DET,
lt_emp_item_det TYPE TABLE OF ZPM_EMP_ITEM_DET.
DATA : ok_code like sy-ucomm,
save_ok like sy-ucomm. "OK-Code
types : begin of itab_emp_struct,
empid type ZPM_EMP_HEAD_DET-EMPID,
empname type ZPM_EMP_HEAD_DET-EMPLOYEE_NAME,
desig type ZPM_EMP_HEAD_DET-DESIGNATION,
projname type ZPM_EMP_ITEM_DET-PROJECT_NAME,
role type ZPM_EMP_ITEM_DET-ROLE_OF_EMP,
compe type ZPM_EMP_ITEM_DET-COMPETANCY,
end of itab_emp_struct.
DATA : itab_emp type table of ZPM_EMP_HEAD_DET with header line .
DATA : wa_itab_emp type ZPM_EMP_HEAD_DET.
*DATA : itab_emp type ZPM_EMP_HEAD_DET occurs 0.
with header line .
*
*DATA : wa_itab_emp type ZPM_EMP_HEAD_DET.
DATA : itab_emp1 type table of ZPM_EMP_ITEM_DET.
DATA : wa_itab_emp1 type ZPM_EMP_ITEM_DET.
data: g_alv_tree type ref to cl_gui_alv_tree,
g_custom_container type ref to cl_gui_custom_container.
*----
*
CLASS TREE1 DEFINITION
*----
*
*
*----
*
CLASS TREE1 DEFINITION.
PUBLIC SECTION.
METHODS : SELECTION , TREESEL.
ENDCLASS. "TREE1 DEFINITION
*----
*
CLASS TREE1 IMPLEMENTATION
*----
*
*
*----
*
CLASS TREE1 IMPLEMENTATION.
METHOD SELECTION.
ENDMETHOD. "SELECTION
METHOD TREESEL.
data: save_ok like sy-ucomm, "OK-Code
g_max type i value 255.
if g_alv_tree is initial.
****FOR INITIALISING THE TREE
perform init_tree.
call method cl_gui_cfw=>flush
EXCEPTIONS
cntl_system_error = 1
cntl_error = 2.
if sy-subrc ne 0.
call function 'POPUP_TO_INFORM'
EXPORTING
titel = 'Automation Queue failure'(801)
txt1 = 'Internal error:'(802)
txt2 = 'A method in the automation queue'(803)
txt3 = 'caused a failure.'(804).
endif.
endif.
ENDMETHOD. "TREESEL
ENDCLASS. "TREE1 IMPLEMENTATION
ENDMETHOD. "SELECTION
*&----
*
*& Module STATUS_0100 OUTPUT
*&----
*
text
*----
*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'ALV_TREE_GUI_STATUS'.
SET TITLEBAR 'xxx'.
DATA : OBJ1 TYPE REF TO TREE1.
CREATE OBJECT OBJ1.
CALL METHOD OBJ1->SELECTION.
CALL METHOD OBJ1->TREESEL.
ENDMODULE. " STATUS_0100 OUTPUT
*&----
*
*& Module USER_COMMAND_0100 INPUT
*&----
*
text
*----
*
MODULE USER_COMMAND_0100 INPUT.
case ok_code.
when 'EXIT' or 'BACK' or 'CANC'.
perform exit_program.
when others.
call method cl_gui_cfw=>dispatch.
endcase.
clear ok_code.
call method cl_gui_cfw=>flush.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&----
*
*& Form init_tree
*&----
*
text
*----
*
form init_tree.
data: l_tree_container_name(30) type c.
l_tree_container_name = 'SS_TREE'.
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 'ERROR'(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 = 'X'
no_html_header = 'X'
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.
§2. Create Hierarchy-header
data l_hierarchy_header type treev_hhdr.
perform build_hierarchy_header changing l_hierarchy_header.
call method g_alv_tree->set_table_for_first_display
EXPORTING
i_structure_name = 'ZPM_EMP_DET'
is_hierarchy_header = l_hierarchy_header
CHANGING
it_outtab = lt_emp_det. "table must be empty !
perform create_hierarchy.
*§5. Send data to frontend.
call method g_alv_tree->frontend_update.
endform. "init_tree
*&----
*
*& Form build_hierarchy_header
*&----
*
text
*----
*
-->P_HIERARCHY_HEADER text
*----
*
form build_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = 'PROJ / EMP ID'(300).
p_hierarchy_header-tooltip = 'PROJECT MANAGEMENT SYSTEM '(400).
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ' '.
endform. " build_hierarchy_header
*&----
*
*& Form exit_program
*&----
*
text
*----
*
form exit_program.
call method g_custom_container->free.
leave program.
endform. " exit_program
*&----
*
*& Form create_hierarchy
*&----
*
text
*----
*
form create_hierarchy.
DATA: ls_emp TYPE zpm_emp_det,
lt_emp TYPE zpm_emp_det OCCURS 0,
l_projectname TYPE zpm_emp_item_det-project_name,
l_empid TYPE zpm_emp_item_det-empid,
l_empid_last TYPE zpm_emp_item_det-empid.
data: l_proj_key type lvc_nkey,
l_emp_key type lvc_nkey,
l_last_key type lvc_nkey.
DATA: l_projectname_key TYPE lvc_nkey,
l_ROLE_OF_EMP_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey.
DATA: lt_project TYPE zpm_emp_det OCCURS 0,
ls_project TYPE zpm_emp_det.
DATA: lt_project1 TYPE zpm_emp_det OCCURS 0,
ls_project1 TYPE zpm_emp_det.
SELECT * FROM zpm_project_det INTO CORRESPONDING FIELDS OF TABLE lt_project WHERE zpm_project_det~projectid = '0000000004'.
LOOP AT lt_project INTO ls_project.
ENDLOOP.
SELECT * FROM zpm_emp_item_det INTO CORRESPONDING FIELDS OF TABLE lt_project WHERE zpm_emp_item_det~project_name = ls_project-project_name.
SELECT empid employee_type FROM zpm_emp_head_det
INTO CORRESPONDING FIELDS OF TABLE lt_project1 FOR ALL ENTRIES IN lt_project
WHERE zpm_emp_head_det~empid = lt_project-empid.
LOOP AT lt_project1 INTO ls_project1.
MODIFY lt_project FROM ls_project1 TRANSPORTING employee_type WHERE empid = ls_project1-empid.
ENDLOOP.
REFRESH lt_project1.
SELECT employee_name empid DESIGNATION FROM zpm_emp_head_det INTO CORRESPONDING FIELDS OF TABLE lt_project1 FOR ALL ENTRIES IN lt_project
WHERE zpm_emp_head_det~empid = lt_project-empid.
LOOP AT lt_project1 INTO ls_project1.
MODIFY lt_project FROM ls_project1 TRANSPORTING employee_name DESIGNATION WHERE empid = ls_project1-empid.
ENDLOOP.
SORT lt_project BY project_name employee_type empid.
LOOP AT lt_project INTO ls_project.
ON CHANGE OF ls_project-project_name.
PERFORM add_project USING ls_project
''
CHANGING l_proj_key.
ENDON.
ON CHANGE OF ls_project-ROLE_OF_EMP.
PERFORM add_employee_type USING ls_project
l_proj_key
CHANGING l_emp_key.
ENDON.
PERFORM add_final USING ls_project
l_emp_key
CHANGING l_last_key.
endloop.
endform. "create_hierarchy
*&----
*
*& Form add_project
*&----
*
text
*----
*
-->P_LS_PROJECT text
-->P_0598 text
<--P_L_PROJECTNAME_KEY text
*----
*
FORM add_project USING ps_emp TYPE zpm_emp_det
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
demo_emp TYPE zpm_emp_det. "Should be empty
l_node_text = ps_emp-project_name.
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 = demo_emp
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_project
*&----
*
*& Form add_employee_type
*&----
*
text
*----
*
-->P_LS_PROJECT text
-->P_L_PROJECTNAME_KEY text
<--P_L_EMP_KEY text
*----
*
FORM add_employee_type USING ps_emp TYPE zpm_emp_det
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
demo_emp TYPE zpm_emp_det. "Should be empty
l_node_text = ps_emp-ROLE_OF_EMP.
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 = demo_emp
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_employee_type
*&----
*
*& Form add_final
*&----
*
text
*----
*
-->P_LS_PROJECT text
-->P_L_EMP_KEY text
<--P_L_LAST_KEY text
*----
*
FORM add_final USING ps_emp TYPE zpm_emp_det
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_emp1 TYPE zpm_emp_det.
l_node_text = ps_emp-empid.
CALL METHOD g_alv_tree->add_node
EXPORTINGis_outtab_line = ps_emp
IS_NODE_LAYOUT =
IT_ITEM_LAYOUT =
I_NODE_TEXT = l_node_text
IMPORTING
e_new_node_key = p_node_key.
EXCEPTIONS
RELAT_NODE_NOT_FOUND = 1
NODE_NOT_FOUND = 2
others = 3
ENDFORM. " add_final
Reward points if helpful 🙂
Thanks,
Sachin