Tree Control With Oops
Tree Control With Oops
Tree Control With Oops
"lcl_eventreceiver DEFINITION
"handle_node_double_click
ENDCLASS.
"lcl_eventreceiver IMPLEMENTATION
= 'CST'.
= cust_cont
node_selection_mode
= cl_gui_simple_tree=>node_sel_mode_single.
PERFORM addnodes.
ENDIF.
ENDMODULE.
WHEN 'BACK'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
FORM addnodes .
CLEAR ls_nodes.
ls_nodes-node_key = 'RT'. """"root node'
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'Transactions'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'SO'. """"root node'
ls_nodes-relatkey = 'RT'.
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'Sales Order'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'PO'. """"root node'
ls_nodes-relatkey = 'RT'.
ls_nodes-isfolder = 'X'.
ls_nodes-expander = 'X'.
ls_nodes-text = 'PURCHASE Order'.
APPEND ls_nodes TO lt_nodes.
CLEAR ls_nodes.
ls_nodes-node_key = 'CSO'. """"root node'
ls_nodes-relatkey = 'SO'.
ls_nodes-n_image = '@15@'.
table_structure_name = 'ABDEMONODE'
node_table
= lt_nodes[].
ENDFORM.
" ADDNODES
FORM registerhandlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_node_double_click FOR o_tree.
CLEAR ls_events.
ls_events-eventid = cl_gui_simple_tree=>eventid_node_double_click.
APPEND ls_events TO lt_events.
CALL METHOD o_tree->set_registered_events
EXPORTING
events = lt_events.
ENDFORM.
" registerhandlers
OOPS ALV REPORT WITH TREE CONTROL:This is the sample code copied from web site its working fine.
Create screen no 100.
In PBO (please dont do any code changes in exiting code. like whatever it
is in comments just leave it as it is.) for PAI also.
Create a module with name as follows
Module pbo.
Create a module with name as follows in PAI
Module pai.
In screen layout create a custom control with name TREE1.
REPORT zrk_oop_treeview2.
= gt_fieldcatalog.
* change fieldcatalog
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
CASE ls_fieldcatalog-fieldname.
WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'.
ls_fieldcatalog-do_sum = 'X'.
ENDCASE.
MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
ENDLOOP.
ENDFORM. " BUILD_FIELDCATALOG
FORM build_outtab.
SELECT * FROM sflight INTO TABLE gt_sflight.
ENDFORM. " BUILD_OUTTAB
FORM build_sort_table.
DATA ls_sort_wa TYPE lvc_s_sort.
* create sort-table
ls_sort_wa-spos = 1.
ls_sort_wa-fieldname = 'CARRID'.
ls_sort_wa-up = 'X'.
ls_sort_wa-subtot = 'X'.
APPEND ls_sort_wa TO gt_sort.
ls_sort_wa-spos = 2.
ls_sort_wa-fieldname = 'CONNID'.
ls_sort_wa-up = 'X'.
ls_sort_wa-subtot = 'X'.
APPEND ls_sort_wa TO gt_sort.
ls_sort_wa-spos = 3.
ls_sort_wa-fieldname = 'FLDATE'.
ls_sort_wa-up = 'X'.
APPEND ls_sort_wa TO gt_sort.
ENDFORM. " BUILD_SORT_TABLE
MODULE pbo OUTPUT.
IF tree1 IS INITIAL.
PERFORM init_tree.
ENDIF.
SET PF-STATUS 'ZSTATUS'.
ENDMODULE. " PBO OUTPUT
= lt_events
EXCEPTIONS
cntl_error
=1
cntl_system_error
=2
illegal_event_combination = 3.
* set Handler
DATA: l_event_receiver TYPE REF TO lcl_tree_event_receiver.
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->on_add_hierarchy_node
FOR tree1.
ENDFORM. " register_events
FORM build_comment USING
pt_list_commentary TYPE slis_t_listheader
p_logo TYPE sdydo_value.
DATA: ls_line TYPE slis_listheader.
* LIST HEADING LINE: TYPE H
CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'RAJKUMAR SIRIPURAM'.
APPEND ls_line TO pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
ENDFORM. "build_comment
FORM init_tree.
PERFORM build_fieldcatalog.
PERFORM build_outtab.
PERFORM build_sort_table.
* 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'.
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.
* create tree control
CREATE OBJECT tree1
EXPORTING
i_parent = l_custom_container
i_node_selection_mode =
cl_gui_column_tree=>node_sel_mode_multiple
i_item_selection = 'X'
i_no_html_header = ''
i_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.
* create info-table for html-header
DATA: lt_list_commentary TYPE slis_t_listheader,
l_logo TYPE sdydo_value.
PERFORM build_comment USING
lt_list_commentary
l_logo.
* repid for saving variants
DATA: ls_variant TYPE disvariant.
ls_variant-report = sy-repid.
* register events
PERFORM register_events.
* create hierarchy
CALL METHOD tree1->set_table_for_first_display
EXPORTING
it_list_commentary = lt_list_commentary
i_logo
= l_logo
i_background_id
= 'ALV_BACKGROUND'
i_save
= 'A'
is_variant
= ls_variant
CHANGING
it_sort
= gt_sort
it_outtab
it_fieldcatalog
= gt_sflight
= gt_fieldcatalog.
i_level = 1.
* optimize column-width
CALL METHOD tree1->column_optimize
EXPORTING
i_start_column = tree1->c_hierarchy_column_name
i_end_column = tree1->c_hierarchy_column_name.
ENDFORM. " init_tree " registerhandlers
module STATUS_0100 output.
SET PF-STATUS 'ABC'.
* SET TITLEBAR 'xxx'.
endmodule.
REPORT zrk_oop_alv02.
"lcl_eventreceiver DEFINITION
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
"handle_hotspot_click
METHOD handle_button_click.
READ TABLE lt_vbak INTO ls_vbak
INDEX es_row_no-row_id TRANSPORTING vbeln.
IF sy-subrc EQ 0.
CLEAR lv_vbeln.
lv_vbeln = ls_vbak-vbeln.
IF lv_vbeln IS NOT INITIAL.
PERFORM getsalesitems.
IF lt_vbap[] IS NOT INITIAL.
CALL SCREEN 300.
ELSE.
MESSAGE 'No sales items' TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
ENDMETHOD.
"handle_button_click
METHOD handle_double_click.
CASE e_column-fieldname.
WHEN 'MATNR'.
READ TABLE lt_vbap INTO ls_vbap
INDEX e_row-index TRANSPORTING matnr.
IF sy-subrc EQ 0.
SET PARAMETER ID 'MAT' FIELD ls_vbap-matnr.
ENDIF.
CALL TRANSACTION 'MM03'.
WHEN OTHERS.
MESSAGE 'Please click on material' TYPE 'I'.
ENDCASE.
ENDMETHOD.
"handle_double_click
ENDCLASS.
"lcl_eventreceiver IMPLEMENTATION
= 'CST1'.
= kna1_cont.
PERFORM getcustomers.
IF lt_kna1[] IS NOT INITIAL.
PERFORM fldcatkna1.
PERFORM layoutkna1.
PERFORM registerhandlers.
PERFORM displaykna1.
ENDIF.
ENDIF.
ENDMODULE.
"USER_COMMAND_0100 INPUT
FORM displaykna1 .
CALL METHOD kna1_grid->set_table_for_first_display
EXPORTING
is_layout
= ls_layo
CHANGING
it_outtab
= lt_kna1[]
it_fieldcatalog = lt_fcat[].
ENDFORM.
" displaykna1
FORM fldcatkna1 .
CLEAR ls_fcat.
ls_fcat-fieldname = 'KUNNR'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Customer No'.
ls_fcat-hotspot = 'X'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'LAND1'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Country'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'NAME1'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Customer Name'.
ls_fcat-outputlen = 20.
APPEND ls_fcat TO lt_fcat.
ENDFORM.
" fldcatkna1
FORM getcustomers .
SELECT kunnr land1 name1 FROM kna1
INTO TABLE lt_kna1
WHERE kunnr IN so_kunnr.
ENDFORM.
" getcustomers
FORM layoutkna1 .
CLEAR ls_layo.
ls_layo-grid_title = 'CUSTOMER MASTER DATA'.
ENDFORM.
" layoutkna1
FORM getsalesorders .
SELECT vbeln erdat erzet ernam FROM vbak
INTO CORRESPONDING FIELDS OF TABLE lt_vbak
WHERE kunnr = lv_kunnr.
ENDFORM.
" getsalesorders
= 'CST2'.
= vbak_cont.
PERFORM fldcatvbak.
PERFORM layoutvbak.
PERFORM cellstyles.
PERFORM reghandlers.
PERFORM displayvbak.
ENDIF.
ENDMODULE.
FORM displayvbak .
CALL METHOD vbak_grid->set_table_for_first_display
EXPORTING
is_layout
= ls_layo
CHANGING
it_outtab
= lt_vbak[]
it_fieldcatalog = lt_fcat[].
ENDFORM.
" displayvbak
FORM fldcatvbak .
REFRESH lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Doc'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ERDAT'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Date'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ERZET'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Time'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ERNAM'.
ls_fcat-col_pos = 4.
ls_fcat-coltext = 'Person'.
APPEND ls_fcat TO lt_fcat.
ENDFORM.
" fldcatvbak
FORM layoutvbak .
CLEAR ls_layo.
ls_layo-grid_title = 'SALES DOCUMENT HEADER DATA'.
ls_layo-stylefname = 'CELLSTYLES'.
ENDFORM.
" layoutvbak
FORM cellstyles .
DATA lv_date TYPE d.
CLEAR ls_vbak.
LOOP AT lt_vbak INTO ls_vbak.
lv_date = ls_vbak-erdat+0(4).
IF lv_date >= '2000'.
ls_styl-fieldname = 'VBELN'.
ls_styl-style = cl_gui_alv_grid=>mc_style_button.
INSERT ls_styl INTO TABLE ls_vbak-cellstyles.
" cellstyles
FORM getsalesitems .
SELECT vbeln posnr matnr FROM vbap
INTO TABLE lt_vbap
WHERE vbeln = lv_vbeln.
ENDFORM.
" getsalesitems
= 'CST3'.
= vbap_cont.
PERFORM fldcatvbap.
PERFORM layoutvbap.
PERFORM reg_handlers.
PERFORM displayvbap.
ENDIF.
ENDMODULE.
WHEN 'BACK'.
LEAVE TO SCREEN 200.
ENDCASE.
ENDMODULE.
FORM reghandlers .
create object ob.
set handler ob->handle_button_click for vbak_grid.
ENDFORM.
" reghandlers
FORM registerhandlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_hotspot_click FOR kna1_grid.
ENDFORM.
" registerhandlers
FORM fldcatvbap .
REFRESH lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VBELN'.
ls_fcat-col_pos = 1.
ls_fcat-coltext = 'Sales Doc'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'POSNR'.
ls_fcat-col_pos = 2.
ls_fcat-coltext = 'Item no'.
APPEND ls_fcat TO lt_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'MATNR'.
ls_fcat-col_pos = 3.
ls_fcat-coltext = 'Material'.
APPEND ls_fcat TO lt_fcat.
ENDFORM.
" fldcatvbap
FORM layoutvbap .
CLEAR ls_layo.
ls_layo-grid_title = 'SALES DOCUMENT ITEM DATA'.
ENDFORM.
" layoutvbap
FORM reg_handlers .
CREATE OBJECT ob.
SET HANDLER ob->handle_double_click FOR vbap_grid.
ENDFORM.
" reg_handlers
FORM displayvbap .
CALL METHOD vbap_grid->set_table_for_first_display
EXPORTING
is_layout
= ls_layo
CHANGING
it_outtab
= lt_vbap[]
it_fieldcatalog = lt_fcat[].
ENDFORM.
" displayvbap..