09-18-2008 6:00 AM
Hi all,
please someone guide me with the code to create alv tree using oops..
regards,
kushagra
09-18-2008 6:03 AM
Chk this sample pgm.
http://sapprograms.blogspot.com/2008/08/alv-tree-demo-example.html
09-18-2008 8:23 AM
Hi,
check the following links for oops alv:-
https://wiki.sdn.sap.com/wiki/x/ZIM
https://wiki.sdn.sap.com/wiki/x/ip
https://wiki.sdn.sap.com/wiki/x/T5E
You can get many more links in sdn wiki.Search for OOPS + alv
Good luck,
Bhumika
09-18-2008 8:26 AM
Hi sharma,
. Create a Control (for Custom and Split Containers only)
2. Instantiate a Container Object (in case of Custom and Split Containers, specify the control which is created by us in Screen painter) CREATE OBJECT
3. Instantiate an Object of the kind of report that has to be displayed (List, Grid or Tree). CREATE OBJECT . Here we need to specify the Parent Container as the so that it sits in that container.
4. Call appropriate methods to display the report on the screen. CALL METHOD ->
Example:
DATA : g_dock TYPE REF TO cl_gui_docking_container,
g_split TYPE REF TO cl_gui_easy_splitter_container,
g_cont1 TYPE REF TO cl_gui_container,
g_cont2 TYPE REF TO cl_gui_container,
g_grid1 TYPE REF TO cl_gui_alv_grid,
g_grid2 TYPE REF TO cl_gui_alv_grid.
i_mara is an internal table of structure MARA
SELECT * FROM mara INTO TABLE i_mara.
i_kna1 is an internal table of structure KNA1
SELECT * FROM kna1 INTO TABLE i_kna1.
To create an Object of type Docking Container
CREATE OBJECT g_dock
EXPORTING
side = cl_gui_docking_container=>dock_at_top
extension = 200 .
To Create an Object of Type Split Container. Here we can see that the Docking *Container Created above has been used as a parent .
CREATE OBJECT g_split
EXPORTING
parent = g_dock
orientation = 1 .
Easy Split container splits one Control into 2 manageable controls, each of them is used * to handle one GUI Container each
g_cont1 = g_split->top_left_container.
g_cont2 = g_split->bottom_right_container.
To Create an Object of type Grid . Here we can see that the Left Split Container * Created above has been used as a parent .
CREATE OBJECT g_grid1
EXPORTING
i_parent = g_cont1 .
To Create an Object of type Grid . Here we can see that the Right Split Container * Created above has been used as a parent .
CREATE OBJECT g_grid2
EXPORTING
i_parent = g_cont2 .
The method of Grid Control Object is used to display the Data.
CALL METHOD g_grid1->set_table_for_first_display
EXPORTING
i_structure_name = 'MARA'
CHANGING
it_outtab = i_mara[] .
The method of Grid Control Object is used to display the Data.
CALL METHOD g_grid2->set_table_for_first_display
EXPORTING
i_structure_name = 'KNA1'
CHANGING
it_outtab = i_kna1[] .
use these too
ALV OOPS Blog
Simple ALV report
http://www.sapgenie.com/abap/controls/alvgrid.htm
http://wiki.ittoolbox.com/index.php/Code:Ultimate_ALV_table_toolbox
ALV Interactive Reports
ALV Easy Reference Guide OOPS
ALV
1. Please give me general info on ALV.
http://www.sapfans.com/forums/viewtopic.php?t=58286
http://www.sapfans.com/forums/viewtopic.php?t=76490
http://www.sapfans.com/forums/viewtopic.php?t=20591
http://www.sapfans.com/forums/viewtopic.php?t=66305 - this one discusses which way should you use - ABAP Objects calls or simple function modules.
2. How do I program double click in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=11601
http://www.sapfans.com/forums/viewtopic.php?t=23010
Check the program in the following link:
http://sap-img.com/abap/display-secondary-list-using-alv-grid.htm
3. How do I add subtotals (I have problem to add them)...
http://www.sapfans.com/forums/viewtopic.php?t=20386
http://www.sapfans.com/forums/viewtopic.php?t=85191
http://www.sapfans.com/forums/viewtopic.php?t=88401
http://www.sapfans.com/forums/viewtopic.php?t=17335
http://www.sapdevelopment.co.uk/reporting/alv/alvgrid_basic.htm
4. How to add list heading like top-of-page in ABAP lists?
http://www.sapfans.com/forums/viewtopic.php?t=58775
http://www.sapfans.com/forums/viewtopic.php?t=60550
http://www.sapfans.com/forums/viewtopic.php?t=16629
5. How to print page number / total number of pages X/XX in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=29597 (no direct solution)
6. ALV printing problems. The favourite is: The first page shows the number of records selected but I don't need this.
http://www.sapfans.com/forums/viewtopic.php?t=64320
http://www.sapfans.com/forums/viewtopic.php?t=44477
7. How can I set the cell color in ALV?
8. How do I print a logo/graphics in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=81149
http://www.sapfans.com/forums/viewtopic.php?t=35498
http://www.sapfans.com/forums/viewtopic.php?t=5013
9. How do I create and use input-enabled fields in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=84933
http://www.sapfans.com/forums/viewtopic.php?t=69878
10. How can I use ALV for reports that are going to be run in background?
http://www.sapfans.com/forums/viewtopic.php?t=83243
http://www.sapfans.com/forums/viewtopic.php?t=19224
11. How can I display an icon in ALV? (Common requirement is traffic light icon).
http://www.sapfans.com/forums/viewtopic.php?t=79424
http://www.sapfans.com/forums/viewtopic.php?t=24512
12. How can I display a checkbox in ALV?
http://www.sapfans.com/forums/viewtopic.php?t=88376
http://www.sapfans.com/forums/viewtopic.php?t=40968
http://www.sapfans.com/forums/viewtopic.php?t=6919
13. Top-of-page in ALV
14. ALV Group Heading
http://www.sap-img.com/fu037.htm
How to add list heading like top-of-page in ABAP lists?
http://www.sapfans.com/forums/viewtopic.php?t=58775
http://www.sapfans.com/forums/viewtopic.php?t=60550
http://www.sapfans.com/forums/viewtopic.php?t=16629
15. ALV output to PDF conversion
It has an example code for PDF Conversion.
http://www.erpgenie.com/abap/code/abap51.htm
Go thru these programs they may help u to try on some hands on
ALV Demo program
BCALV_DEMO_HTML
BCALV_FULLSCREEN_DEMO ALV Demo: Fullscreen Mode
BCALV_FULLSCREEN_DEMO_CLASSIC ALV demo: Fullscreen mode
BCALV_GRID_DEMO Simple ALV Control Call Demo Program
BCALV_TREE_DEMO Demo for ALV tree control
BCALV_TREE_SIMPLE_DEMO
BC_ALV_DEMO_HTML_D0100
regards.
nagendra
09-18-2008 8:27 AM
09-18-2008 9:31 AM
Hello Kushagra
You may want to have a look at my sample report ZUS_SDN_ALV_TREE_DEMO in
Regards
Uwe
09-19-2008 7:24 AM
Hi Kushagra,
Go to transaction DWDM you will get lot of examples there for alv tree using oops.
Regards
Lalit
09-24-2008 6:36 PM
This is a example about ALV Tree using OO ABAP. i used the class cl_gui_alv_tree. Look all code:
*& Report Z_ALV_TREE *
****This program is a example about ALV Tree using OO ABAP
REPORT z_alv_tree .
****TYPES
TYPE-POOLS: slis.
****INCLUDE
INCLUDE <icon>.
INCLUDE bcalv_tree_event_receiver.
****CLASS
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
****TABLES
TYPES: BEGIN OF it ,
node_main(15) TYPE c,
node_n01(15) TYPE c,
node_n02(15) TYPE c,
node_n03(15) TYPE c,
END OF it.
DATA: it_exit TYPE it OCCURS 0,
it_exit1 TYPE it occurs 0,
wa_exit1 LIKE LINE OF it_exit,
wa_exit LIKE LINE OF it_exit.
****STRUCTURE FOR ALV TREE
DATA:
lt_list_commentary TYPE slis_t_listheader, """COMENTARY
l_logo TYPE sdydo_value, """LOGO
ls_variant TYPE disvariant, """VARIANT
l_hierarchy_header TYPE treev_hhdr, """HEADER
tree1 TYPE REF TO cl_gui_alv_tree, """TREE
gt_fieldcatalog TYPE lvc_t_fcat, """CATALOG
ok_code TYPE sy-ucomm. """OK-CODE
****INITIALIZATION
INITIALIZATION.
CLEAR: it_exit, wa_exit.
*****START-OF-SELECTION
START-OF-SELECTION.
MAIN NODE
CLEAR:it_exit, wa_exit.
break p33ggotera.
MOVE 'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
FIRST NODE
MOVE : 'First Level' TO wa_exit-node_n01,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
MOVE : 'First Level A' TO wa_exit-node_n02,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
MOVE : 'First Level B' TO wa_exit-node_n02,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
SECOND NODE
MOVE: 'Second Level' TO wa_exit-node_n01,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
MOVE: 'Second Level A' TO wa_exit-node_n02,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
MOVE: 'Second Level B' TO wa_exit-node_n03,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
THIRD NODE
MOVE: 'Third Level' TO wa_exit-node_n01,
'Main Node' TO wa_exit-node_main.
APPEND wa_exit TO it_exit.
CLEAR wa_exit.
****SCREEN
CALL SCREEN 100.
&----
*& Module STATUS_0100 OUTPUT
&----
MODULE status_0100 OUTPUT.
SET PF-STATUS 'ALVTREE'.
IF tree1 IS INITIAL.
CATALOG
PERFORM fo_fieldcat.
CREATE TREE
PERFORM create_tree.
create Hierarchy-header
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
create info-table for html-header
PERFORM build_comment USING
lt_list_commentary.
repid for saving variants
ls_variant-report = sy-repid.
Creation of ALV
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = l_hierarchy_header
it_list_commentary = lt_list_commentary
i_save = 'A'
is_variant = ls_variant
CHANGING
it_outtab = it_exit1
it_fieldcatalog = gt_fieldcatalog.
create hierarchy
PERFORM create_hierarchy.
register events
PERFORM register_events.
ENDIF.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " STATUS_0100 OUTPUT
&----
*& Module USER_COMMAND_0100 INPUT
&----
MODULE user_command_0100 INPUT.
CLEAR ok_code.
ok_code = sy-ucomm.
CASE ok_code.
WHEN 'EXIT' OR 'BACK' .
PERFORM exit_program.
WHEN 'BACK1'.
CALL METHOD tree1->free.
LEAVE TO SCREEN 0.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CLEAR ok_code.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
*& Form exit_program
&----
FORM exit_program.
CALL METHOD tree1->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
&----
*& Form fo_fieldcat
&----
FORM fo_fieldcat.
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
****MAIN NODE
ls_fieldcatalog-col_pos = '1'.
ls_fieldcatalog-fieldname = 'NODE_MAIN'.
ls_fieldcatalog-tabname = 'IT_EXIT'.
ls_fieldcatalog-coltext = 'Main Node'.
ls_fieldcatalog-key = 'X'.
ls_fieldcatalog-just = 'L'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-outputlen = '15'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR ls_fieldcatalog.
****FIRST LEVEL
ls_fieldcatalog-col_pos = '2'.
ls_fieldcatalog-fieldname = 'NODE_N01'.
ls_fieldcatalog-tabname = 'IT_EXIT'.
ls_fieldcatalog-coltext = 'First Level'.
ls_fieldcatalog-key = 'X'.
ls_fieldcatalog-just = 'L'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-outputlen = '15'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR ls_fieldcatalog.
****SECOND LEVEL
ls_fieldcatalog-col_pos = '3'.
ls_fieldcatalog-fieldname = 'NODE_N02'.
ls_fieldcatalog-tabname = 'IT_EXIT'.
ls_fieldcatalog-coltext = 'Second Level'.
ls_fieldcatalog-key = 'X'.
ls_fieldcatalog-just = 'L'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-outputlen = '15'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR ls_fieldcatalog.
****THIRD LEVEL
ls_fieldcatalog-col_pos = '4'.
ls_fieldcatalog-fieldname = 'NODE_N03'.
ls_fieldcatalog-tabname = 'IT_EXIT'.
ls_fieldcatalog-coltext = 'Third Level'.
ls_fieldcatalog-key = 'X'.
ls_fieldcatalog-just = 'L'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-outputlen = '15'.
APPEND ls_fieldcatalog TO gt_fieldcatalog.
CLEAR ls_fieldcatalog.
ENDFORM. " fo_fieldcat
&----
*& Form create_tree
&----
FORM create_tree.
create container for alv-tree
DATA: l_tree_container_name(30) TYPE c,
l_custom_container TYPE REF TO cl_gui_custom_container.
l_tree_container_name = 'TREE1'.
IF sy-batch IS INITIAL.
CREATE OBJECT l_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'.
ENDIF.
ENDIF.
create tree control
CREATE OBJECT tree1
EXPORTING
parent = l_custom_container
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = 'X'
no_html_header = ''
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.
****
ENDFORM. " create_tree
&----
*& Form build_hierarchy_header
&----
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Node'.
p_hierarchy_header-width = 15.
p_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
&----
*& Form build_comment
&----
text
----
-->P_LT_LIST_COMMENTARY text
----
FORM build_comment USING
pt_list_commentary TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader, text(60) TYPE c.
*
LIST HEADING LINE: TYPE H
CLEAR ls_line.
ls_line-typ = 'H'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = sy-title.
APPEND ls_line TO pt_list_commentary.
STATUS LINE: TYPE S
CLEAR ls_line.
ls_line-key = 'Date:'.
WRITE sy-datum TO ls_line-info USING EDIT MASK '__/__/____'.
ls_line-typ = 'S'.
APPEND ls_line TO pt_list_commentary.
*
CLEAR ls_line.
ls_line-key = 'User:'.
ls_line-info = sy-uname.
ls_line-typ = 'S'.
APPEND ls_line TO pt_list_commentary.
ENDFORM. " build_comment
&----
*& Form create_hierarchy
&----
FORM create_hierarchy.
add data to tree
DATA: l_key_main TYPE lvc_nkey,
l_key_node1 TYPE lvc_nkey,
l_key_node2 TYPE lvc_nkey,
l_key_node3 TYPE lvc_nkey,
l_node TYPE lvc_value.
*****
LOOP AT it_exit INTO wa_exit.
*****main node
MOVE-CORRESPONDING wa_exit TO wa_exit1.
AT NEW node_main.
CLEAR l_node.
l_node = wa_exit1-node_main.
PERFORM add_node_main USING wa_exit1
''
l_node
CHANGING l_key_main.
ENDAT.
****node 1
MOVE-CORRESPONDING wa_exit1 to wa_exit.
IF NOT wa_exit-node_n01 IS INITIAL.
CLEAR l_node.
l_node = wa_exit-node_n01.
PERFORM add_node USING wa_exit
l_key_main
l_node
CHANGING l_key_node1.
ENDIF.
****node 2
IF NOT wa_exit-node_n02 IS INITIAL.
CLEAR l_node.
l_node = wa_exit-node_n02.
PERFORM add_node USING wa_exit
l_key_node1
l_node
CHANGING l_key_node2.
ENDIF.
****node 3
IF NOT wa_exit-node_n03 IS INITIAL.
CLEAR l_node.
l_node = wa_exit-node_n03.
PERFORM add_node USING wa_exit
l_key_node2
l_node
CHANGING l_key_node3.
ENDIF.
ENDLOOP.
this method must be called to send the data to the frontend
CALL METHOD tree1->frontend_update.
*****
ENDFORM. " create_hierarchy
&----
*& Form register_events
&----
FORM register_events.
define the events which will be passed to the backend
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event.
define the events which will be passed to the backend
l_event-eventid = cl_gui_column_tree=>eventid_expand_no_children.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_checkbox_change.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_context_men_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_context_menu_req.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_header_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_keypress.
APPEND l_event TO lt_events.
CALL METHOD tree1->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc <> 0.
MESSAGE x208(00) WITH 'ERROR'. "#EC NOTEXT
ENDIF.
set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->handle_node_ctmenu_request
FOR tree1.
SET HANDLER l_event_receiver->handle_node_ctmenu_selected
FOR tree1.
SET HANDLER l_event_receiver->handle_item_ctmenu_request
FOR tree1.
SET HANDLER l_event_receiver->handle_item_ctmenu_selected
FOR tree1.
ENDFORM. " register_events
&----
*& Form add_node_main
&----
FORM add_node USING p_aux TYPE it
p_relat_key TYPE lvc_nkey
p_node TYPE lvc_value
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight.
set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
APPEND ls_item_layout TO lt_item_layout.
add node
l_node_text = p_node.
CALL METHOD tree1->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 = p_aux
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
*****
ENDFORM. " add_node
&----
*& Form add_complete_line
&----
FORM add_complete_line USING p_aux TYPE it
p_relat_key TYPE lvc_nkey
p_node TYPE lvc_value
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value.
set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-class = cl_gui_column_tree=>item_class_text.
ls_item_layout-editable = 'X'.
APPEND ls_item_layout TO lt_item_layout.
l_node_text = p_node.
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = p_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = p_aux
i_node_text = l_node_text
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_complete_line
&----
*& Form add_node_main
&----
FORM add_node_main USING p_aux TYPE it
p_relat_key TYPE lvc_nkey
p_node TYPE lvc_value
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight.
set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3P@'.
ls_item_layout-fieldname = tree1->c_hierarchy_column_name.
ls_item_layout-style =
cl_gui_column_tree=>style_intensifd_critical.
APPEND ls_item_layout TO lt_item_layout.
add node
l_node_text = p_node.
CALL METHOD tree1->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 = p_aux
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = p_node_key.
*****
ENDFORM. " add_node_main