ALV tree help required
Hello All,
I need a help on ALV tree
My requirement is! i need to edit some fields in ALV tree.
In order to do this. I have written the below code
gs_layout_node-fieldname = 'ZMENGE1'.
gs_layout_node-editable = 'X'.
APPEND gs_layout_node TO gt_layout_node.
CALL METHOD lcl_gui_alv_tree2->add_node
EXPORTING
i_relat_node_key = p_node_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = node_text
is_outtab_line = gs_merkpl
it_item_layout = gt_layout_node
IMPORTING
e_new_node_key = s_node_key.
The program dumps when i expand nodes and it gives the following error. The fields are not in editable mode.
Exception condition "CNTL_ERROR" raised.
You may able to find an interim solution to the problem
in the SAP note system. If you have access to the note system yourself,
use the following search criteria:
"RAISE_EXCEPTION" C
"CL_GUI_CFW====================CP" or "CL_GUI_CFW====================CM00P"
"UPDATE_VIEW"
or
"CL_GUI_CFW====================CP" "CNTL_ERROR"
or
"ZV_HF_TREE " "CNTL_ERROR"
If you cannot solve the problem yourself, please send the
following documents to SAP:
1. A hard copy print describing the problem.
To obtain this, select the "Print" function on the current screen.
2. A suitable hardcopy prinout of the system log.
To obtain this, call the system log with Transaction SM21
and select the "Print" function to print out the relevant
part.
3. If the programs are your own programs or modified SAP programs,
supply the source code.
To do this, you can either use the "PRINT" command in the editor or
print the programs using the report RSINCL00.
4. Details regarding the conditions under which the error occurred
or which actions and input led to the error.
000040 CALL FUNCTION 'AC_SYSTEM_FLUSH'
000050 exporting CALLED_BY_SYSTEM = called_by_system
000060 EXCEPTIONS
000070 CNTL_SYSTEM_ERROR = 1
000080 CNTL_ERROR = 2
000090 OTHERS = 3.
000100
000110 CASE SY-SUBRC.
000120 WHEN 0.
000130 WHEN 1. "// system_error
000140 RAISE CNTL_SYSTEM_ERROR.
000150 WHEN 2. "// method_call_error
> RAISE CNTL_ERROR.
000170 WHEN 3. "// property_set_error
000180 RAISE CNTL_ERROR.
000190 WHEN 4. "// property_get_error
000200 RAISE CNTL_ERROR.
000210 WHEN OTHERS.
000220 RAISE CNTL_ERROR.
000230 ENDCASE.
000240
000250 ENDMETHOD.
Can any tell me what is the mistake i am doing.
Regards,
Lisa
Edited by: Lisa Roy on Apr 16, 2008 11:16 AM
Requirement changed
Similar Messages
-
Sample Program for Creating ALV Tree
Hello Guys,
Can some One Send me some sample program for creating ALV Tree.
my Requirement is like below Diagram.
ALV Tree | ALV GrId
|
|
I want to also about event in ALV , As per requirement when user select (Double click or press any push button) a node of ALV Tree That Node (Contain Sales order and as a child billing Doc No) In the ALV Grid All the details about Sales order Will be display.
Please guide me.
Thanks
Swati....Hi..
check the following demo programs:
RSDEMO_DRAG_DROP_EDIT_TREE
RSDEMO_DRAG_DROP_TREE_MULTI
BCALV_GRID_DND_TREE
BCALV_GRID_DND_TREE_SIMPL
BCALV_TEST_COLUMN_TREE
BCALV_TEST_SIMPLE_TREE
BCALV_TREE_01
BCALV_TREE_02
BCALV_TREE_03
BCALV_TREE_04
BCALV_TREE_05
BCALV_TREE_06
BCALV_TREE_DEMO
BCALV_TREE_DND
BCALV_TREE_DND_MULTIPLE
BCALV_TREE_EVENT_RECEIVER
BCALV_TREE_EVENT_RECEIVER
BCALV_TREE_ITEMLAYOUT
BCALV_TREE_MOVE_NODE_TEST
BCALV_TREE_SIMPLE_DEMO
BCALV_TREE_VERIFY
hope this helps..
-kothai -
Help required in ALV Tree Control
Hi All,
I am using OO ALV tree Control in my Project every thing is working fine.
in treecontrol 'If we double click on Node I con it displays resultant screen'- its fine for us
'If we double click on Node Text it is displaying nothing means no Event is triggering.
my Requirement is tha 'it should work even if we click on Node Text' . Like in standard Applications SE15 .
Suggest some Methods regarding this. Note All these nodes are Dynamic Nodes comes from Data Base table.
Thanks in Adv.
MurthyJust check Tcode: DWDM.
Good no of example programs for oops tree are available there -
Editable field with F4 help in alv tree output using cl_gui_alv_tree
HI
i need Editable field with F4 help in alv tree output using cl_gui_alv_tree
Regards
NareshHi Naresh,
Pass the field catalog with the additional parameter (ls_fcat-edit = 'X'.).
for F4 help if the data element have the search help it automatically will come. other wise include the additional parameter in the field catalog (ls_fcat-F4AVAILABL = 'X')
Reward if found helpful.
Regards,
Boobalan Suburaj -
Double click on the node,ALV tree, subscreen
Hi,
I have a small requirement in ALV Tree
left side i get a tree and when i double click on one of it , i'm trying to display the subscreen. even though i am setting the paramaters to the screen but i'm unable to get those values in the subscreen.
example
Name Description subscreen 0101
xyz xyz desc (double click on this) name = XYZ
ABC abs desc descrip = xyz desc
This is what the requirement is:
Please help me out with the solution.
BhavanaHi Bhavana,
Register your double click event in the ALV Tree program. Then call the respective subscreen using sy-ucomm value.
IF NOT r_ucomm IS INITIAL.
CASE r_ucomm.
WHEN '&F03'.
SET SCREEN 100.
LEAVE SCREEN.
endif.
Refer the below code for setting the registering the event.
CALL METHOD tree->get_registered_events
IMPORTING
events = l_events_s.
l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
APPEND l_event TO l_events_s.
CALL METHOD tree->set_registered_events
EXPORTING
events = l_events_s
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
CREATE OBJECT l_events_receiver.
SET HANDLER l_events_receiver->handle_item_click FOR tree.
CLASS lcl_events_receiver DEFINITION. "#EC *
PUBLIC SECTION.
METHODS:
handle_item_click FOR EVENT item_double_click OF cl_gui_alv_tree
IMPORTING node_key fieldname.
ENDCLASS. "lcl_handle_events DEFINITION
CLASS lcl_events_receiver IMPLEMENTATION.
METHOD handle_item_click.
PERFORM employee_data USING node_key fieldname.
CALL SCREEN 300.
ENDMETHOD. "HANDLE_ITEM_DOUBLE_CLICK
ENDCLASS. "lcl_events_receiver IMPLEMENTATION
Thanks.
Ganesh R K
Edited by: Ganesh.rk83 on Jun 23, 2011 11:21 AM -
Double click in ALV tree output????
Hi all,
I am able to display output in tree format. But I want to add the double click functionality to some of the fields in output. Means if I double click on some value in output tree, it should call some transaction. Please help me with this issue of double clicking.
Please tell how to handle events in this report tree display.
For the following code its displaying output in tree format and in right way. But i need to add double click functionality to this.
So provide me some sample program for this one....
* create hierarchy
CALL METHOD tree1->set_table_for_first_display
EXPORTING
it_list_commentary = lt_list_commentary
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
CHANGING
it_sort = gt_sort[]
it_outtab = itab_outtab
it_fieldcatalog = t_fieldcat. "gt_fieldcatalog.
* expand first level
CALL METHOD tree1->expand_tree
EXPORTING
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.
In grid ALV we can have double cilck functionality using code:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
is_layout = ls_layout
it_fieldcat = gt_fc[]
Here we can write subroutine for USER_COMMAND and handle the double click evenet. But tell me how to provide this in tree ALV.
<REMOVED BY MODERATOR>
Regards,
Sachin
Edited by: Alvaro Tejada Galindo on Feb 14, 2008 1:47 PMHello Sachin
The following sample report ZUS_SDN_ALV_TREE_DEMO demonstrates the crucial parts for double-click event handling (nodes & items) in ALV trees.
*& Report ZUS_SDN_ALV_TREE_DEMO
*& Thread: double click in ALV tree output????
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="742412"></a>
REPORT zus_sdn_alv_tree_demo.
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
TYPE-POOLS: abap.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knvv AS data.
TYPES: nkey TYPE lvc_nkey.
TYPES: parent_key TYPE lvc_nkey.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA: gt_outtab TYPE ty_t_outtab.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_tree TYPE REF TO cl_gui_alv_tree.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_node_double_click
FOR EVENT node_double_click OF cl_gui_alv_tree
IMPORTING node_key,
handle_item_double_click
FOR EVENT item_double_click OF cl_gui_alv_tree
IMPORTING node_key
fieldname.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_node_double_click.
message 'Event=Double-Click on Node' type 'I'.
call transaction 'XD03'.
ENDMETHOD. "handle_node_double_click
METHOD handle_item_double_click.
message 'Event=Double-Click on Item' type 'I'.
call transaction 'VA03'.
ENDMETHOD. "handle_item_double_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* container =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
lifetime_dynpro_dynpro_link = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL SCREEN '0100'.
** NOTE: no elements on screen
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'REFRESH'.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form init_controls
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* create tree control
CREATE OBJECT go_tree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X' " required for double-click event on item
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.
* create Hierarchy-header
DATA ls_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
* create emty tree-control
CALL METHOD go_tree->set_table_for_first_display
EXPORTING
** i_structure_name = 'KNVV'
is_variant = gs_variant
i_save = 'A'
* i_default = 'X'
is_hierarchy_header = ls_hierarchy_header
* is_exception_field =
* it_special_groups =
* it_list_commentary =
* i_logo =
* i_background_id =
* it_toolbar_excluding =
* it_except_qinfo =
CHANGING
it_outtab = gt_outtab
* it_filter =
it_fieldcatalog = gt_fcat.
* create hierarchy
PERFORM create_hierarchy.
* register events
PERFORM register_events.
* adjust column_width
CALL METHOD go_tree->column_optimize.
ENDFORM. " init_controls
*& Form build_hierarchy_header
* build hierarchy-header-information
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Hierarchy Header'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNVV'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE gt_fcat FROM 8.
ENDFORM. " BUILD_FIELDCATALOG
*& Form SET_LAYOUT_AND_VARIANT
* text
* --> p1 text
* <-- p2 text
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_variant-report = syst-repid.
gs_variant-handle = 'TREE'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
DATA: ls_knvv TYPE sflight,
ls_outtab TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
* get data
SELECT * FROM knvv INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 200 ROWS . "#EC CI_NOWHERE
SORT lt_outtab BY kunnr vkorg.
* add data to tree
DATA: ld_kunnr_key TYPE lvc_nkey,
ld_vkorg_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey.
LOOP AT lt_outtab INTO ls_outtab.
ON CHANGE OF ls_outtab-kunnr.
PERFORM add_customer_line USING ls_outtab-data
CHANGING ld_kunnr_key.
ENDON.
ON CHANGE OF ls_outtab-vkorg.
PERFORM add_salesorg_line USING ls_outtab-data
ld_kunnr_key
CHANGING ld_vkorg_key.
ENDON.
PERFORM add_complete_line USING ls_outtab-data
ld_vkorg_key
CHANGING ld_last_key.
ENDLOOP.
* calculate totals
CALL METHOD go_tree->update_calculations.
* this method must be called to send the data to the frontend
CALL METHOD go_tree->frontend_update.
ENDFORM. " create_hierarchy
*& Form add_customer_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_customer_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_data TYPE ty_s_outtab-data.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@A0@'. " icon_customer.
ls_item_layout-fieldname = go_tree->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 = us_data-kunnr.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_data
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_customer_line
*& Form add_salesorg_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_salesorg_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_data TYPE ty_s_outtab-data.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@DS@'. " ICON_PARTNER_SALES_ACTIVITY
ls_item_layout-fieldname = go_tree->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 = us_data-vkorg.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_data
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_salesorg_line
*& Form add_cmplete_line
* add hierarchy-level 3 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_complete_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_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 = go_tree->c_hierarchy_column_name.
ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
** ls_item_layout-editable = 'X'.
APPEND ls_item_layout TO lt_item_layout.
** CLEAR ls_item_layout.
** ls_item_layout-fieldname = 'PLANETYPE'.
** ls_item_layout-alignment = cl_gui_column_tree=>align_right.
** APPEND ls_item_layout TO lt_item_layout.
l_node_text = us_data-vtweg.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = us_data
i_node_text = l_node_text
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
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.
l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
APPEND l_event TO lt_events.
CALL METHOD go_tree->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
set handler:
lcl_eventhandler=>handle_node_double_click for go_tree,
lcl_eventhandler=>handle_item_double_click for go_tree.
** 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.
** SET HANDLER l_event_receiver->handle_checkbox_change FOR tree1.
ENDFORM. " register_events
Regards
Uwe -
How to change the color of specific row in ALV tree
Hi,
I m using method set_table_for_first_display of a class CL_GUI_ALV_TREE.
The req is to change the color of specific row. Now can anybody tell me how to change the color of ALV tree. As in ALV tree and in this method 'set_table_for_first_display', there is no parameter IS_Layout.
Pls suggest...hi
hope this code will help you.
Reward if help.
REPORT zsharad_test1.
TABLES: ekko.
TYPE-POOLS: slis. "ALV Declarations
*Data Declaration
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
line_color(4) TYPE c, "Used to store row color attributes
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
gd_tab_group TYPE slis_t_sp_group_alv,
gd_layout TYPE slis_layout_alv,
gd_repid LIKE sy-repid.
*Start-of-selection.
START-OF-SELECTION.
PERFORM data_retrieval.
PERFORM build_fieldcatalog.
PERFORM build_layout.
PERFORM display_alv_report.
*& Form BUILD_FIELDCATALOG
Build Fieldcatalog for ALV Report
FORM build_fieldcatalog.
There are a number of ways to create a fieldcat.
For the purpose of this example i will build the fieldcatalog manualy
by populating the internal table fields individually and then
appending the rows. This method can be the most time consuming but can
also allow you more control of the final product.
Beware though, you need to ensure that all fields required are
populated. When using some of functionality available via ALV, such as
total. You may need to provide more information than if you were
simply displaying the result
I.e. Field type may be required in-order for
the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-datatype = 'CURR'.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
APPEND fieldcatalog TO fieldcatalog.
CLEAR fieldcatalog.
ENDFORM. " BUILD_FIELDCATALOG
*& Form BUILD_LAYOUT
Build layout for ALV grid report
FORM build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
Set layout field for row attributes(i.e. color)
gd_layout-info_fieldname = 'LINE_COLOR'.
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
ENDFORM. " BUILD_LAYOUT
*& Form DISPLAY_ALV_REPORT
Display report using ALV grid
FORM display_alv_report.
gd_repid = sy-repid.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
TABLES
t_outtab = it_ekko
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " DISPLAY_ALV_REPORT
*& Form DATA_RETRIEVAL
Retrieve data form EKPO table and populate itab it_ekko
FORM data_retrieval.
DATA: ld_color(1) TYPE c.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
UP TO 10 ROWS
FROM ekpo
INTO TABLE it_ekko.
*Populate field with color attributes
LOOP AT it_ekko INTO wa_ekko.
Populate color variable with colour properties
Char 1 = C (This is a color property)
Char 2 = 3 (Color codes: 1 - 7)
Char 3 = Intensified on/off ( 1 or 0 )
Char 4 = Inverse display on/off ( 1 or 0 )
i.e. wa_ekko-line_color = 'C410'
ld_color = ld_color + 1.
Only 7 colours so need to reset color value
IF ld_color = 8.
ld_color = 1.
ENDIF.
CONCATENATE 'C' ld_color '10' INTO wa_ekko-line_color.
wa_ekko-line_color = 'C410'.
MODIFY it_ekko FROM wa_ekko.
ENDLOOP.
ENDFORM. " DATA_RETRIEVAL -
Display Traffic Lights in ALV TREE
Hi,
I have to display traffic light in ALV tree but i am not able to find out what parameter i should pass like in ALV grid where we can set is_layout (BCALV_GRID_04).
Thanks in advance.
Regards,
HarshHi,
Please take a look at my code below. Hope it suits your requirement.
P.S. Please award points if it helps...
*& Report ZMM_R_PO_TO_IPURCH_XI
*& PROGRAM TYPE : Report
*& RICEF ID :
*& TITLE : ZMM_R_PO_TO_IPURCH_XI
*& SAP Module : MM
*& CREATION DATE : 02/06/2008
*& AUTHOR : Aris Hidalgo
*& DESIGNER : Aris Hidalgo
*& DESCRIPTION :
*$**********************************************************************
*$ CHANGE HISTORY
*$----------------------------------------------------------------------
*$ DATE | T-Num | Description | Reference
** | | |
*$**********************************************************************
REPORT zmm_r_po_to_ipurch_xi
NO STANDARD PAGE HEADING
MESSAGE-ID zmm.
* Data Dictionary Table/s *
TABLES: edidc.
* SELECTION-SCREEN *
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_credat FOR edidc-credat OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-002.
PARAMETERS: rb_sum RADIOBUTTON GROUP grp1,
rb_det RADIOBUTTON GROUP grp1.
SELECTION-SCREEN END OF BLOCK b2.
*/ CLASS DEFINITION/S /*
* CLASS lcl_data_def DEFINITION
CLASS lcl_data_def DEFINITION ABSTRACT.
PUBLIC SECTION.
TYPES: BEGIN OF t_edidc,
docnum TYPE edidc-docnum,
docrel TYPE edidc-docrel,
status TYPE edidc-status,
doctyp TYPE edidc-doctyp,
direct TYPE edidc-direct,
rcvpor TYPE edidc-rcvpor,
rcvprt TYPE edidc-rcvprt,
rcvprn TYPE edidc-rcvprn,
rcvsad TYPE edidc-rcvsad,
sndpor TYPE edidc-sndpor,
sndprt TYPE edidc-sndprt,
sndprn TYPE edidc-sndprn,
sndsad TYPE edidc-sndsad,
credat TYPE edidc-credat,
cretim TYPE edidc-cretim,
mestyp TYPE edidc-mestyp,
idoctp TYPE edidc-idoctp,
END OF t_edidc.
TYPES: BEGIN OF t_output,
exception TYPE char1,
ebeln TYPE ekko-ebeln,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
credat TYPE edidc-credat,
cretim TYPE edidc-cretim,
END OF t_output.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekko-ebeln,
lifnr TYPE ekko-lifnr,
END OF t_ekko.
TYPES: BEGIN OF t_lfa1,
lifnr TYPE lfa1-lifnr,
name1 TYPE lfa1-name1,
END OF t_lfa1.
DATA: gt_edidc TYPE STANDARD TABLE OF t_edidc,
gt_output TYPE STANDARD TABLE OF t_output,
wa_output LIKE LINE OF gt_output,
gt_ekko TYPE HASHED TABLE OF t_ekko
WITH UNIQUE KEY ebeln,
gt_lfa1 TYPE HASHED TABLE OF t_lfa1
WITH UNIQUE KEY lifnr.
ENDCLASS. "lcl_data_def DEFINITION
CLASS lcl_alv_routines DEFINITION DEFERRED.
CLASS lcl_handle_events DEFINITION DEFERRED.
* CLASS lcl_get_data DEFINITION
CLASS lcl_get_data DEFINITION INHERITING FROM lcl_data_def.
PUBLIC SECTION.
METHODS: get_idocs,
read_idocs,
process_data
IMPORTING
im_docnum TYPE edidc-docnum.
PRIVATE SECTION.
CONSTANTS: lc_mestyp TYPE edidc-mestyp VALUE 'ZMARKETSITE_PURCHASE_ORDER',
lc_idoctp TYPE edidc-idoctp VALUE 'ZMARKETSITE_PURCHASE_ORDER01',
lc_segnam TYPE edid4-segnam VALUE 'ZMARKETSITE_ORDER_HEADER1'.
CONSTANTS: lc_red TYPE i VALUE 1,
lc_yellow TYPE i VALUE 2,
lc_green TYPE i VALUE 3.
DATA: lv_stat_message TYPE bdidocattr-message,
o_lcl_alv_routines TYPE REF TO lcl_alv_routines.
DATA: ls_idoc_control TYPE edidc,
lv_tot_data_recs TYPE sy-dbcnt, "#EC NEEDED
lv_tot_status_recs TYPE sy-dbcnt. "#EC NEEDED
DATA: lt_edids TYPE STANDARD TABLE OF edids,
lt_edidd TYPE STANDARD TABLE OF edidd.
ENDCLASS. "lcl_get_data DEFINITION
* CLASS lcl_alv_routines DEFINITION
CLASS lcl_alv_routines DEFINITION INHERITING FROM lcl_get_data.
PUBLIC SECTION.
DATA: lcl_table TYPE REF TO cl_salv_table,
lcl_container TYPE REF TO cl_gui_custom_container,
lcl_handle_events TYPE REF TO lcl_handle_events,
lcl_columns TYPE REF TO cl_salv_columns_table,
lcl_column TYPE REF TO cl_salv_column_table,
lcl_events2 TYPE REF TO cl_salv_events_table,
lcl_display_settings TYPE REF TO cl_salv_display_settings,
lcl_functions TYPE REF TO cl_salv_functions_list,
lcl_display TYPE REF TO cl_salv_display_settings,
lcl_aggregations TYPE REF TO cl_salv_aggregations,
lcl_sorts TYPE REF TO cl_salv_sorts,
lcl_content TYPE REF TO cl_salv_form_element,
lcl_header TYPE REF TO cl_salv_form_header_info,
ls_color TYPE lvc_s_colo.
DATA: lcl_grid TYPE REF TO cl_salv_form_layout_grid,
lcl_grid_1 TYPE REF TO cl_salv_form_layout_grid,
lcl_grid_2 TYPE REF TO cl_salv_form_layout_grid,
lcl_label TYPE REF TO cl_salv_form_label,"#EC NEEDED
lcl_text TYPE REF TO cl_salv_form_text,
gt_t247 TYPE STANDARD TABLE OF t247,
wa_t247 LIKE LINE OF gt_t247,
lv_text TYPE string.
METHODS: display_data
IMPORTING
im_output LIKE gt_output,
display_top_of_page.
PRIVATE SECTION.
DATA: lv_string TYPE string,
lv_date1 TYPE c LENGTH 10,
lv_time TYPE c LENGTH 10,
lv_title TYPE string.
ENDCLASS. "lcl_alv_routines DEFINITION
* CLASS lcl_handle_events DEFINITION
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
METHODS:
on_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
*/ IMPLEMENTATION/S /*
* CLASS lcl_get_data IMPLEMENTATION
CLASS lcl_get_data IMPLEMENTATION.
* METHOD get_idocs
METHOD get_idocs.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
text = text-p01.
SELECT docnum docrel status doctyp
direct rcvpor rcvprt rcvprn
rcvsad sndpor sndprt sndprn
sndsad credat cretim mestyp
idoctp
FROM edidc
INTO TABLE gt_edidc
WHERE mestyp = lc_mestyp
AND idoctp = lc_idoctp
AND credat IN s_credat.
IF gt_edidc[] IS NOT INITIAL.
* Get IDOC details
CALL METHOD me->read_idocs.
ENDIF.
ENDMETHOD. "get_idocs
* METHOD read_idocs
METHOD read_idocs.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
* PERCENTAGE = 0
text = text-p02.
FIELD-SYMBOLS: <fs_edidc> LIKE LINE OF gt_edidc,
<fs_output> LIKE LINE OF gt_output,
<fs_ekko> LIKE LINE OF gt_ekko,
<fs_lfa1> LIKE LINE OF gt_lfa1.
LOOP AT gt_edidc ASSIGNING <fs_edidc>.
CLEAR ls_idoc_control.
REFRESH: lt_edids, lt_edidd.
* Get status text of IDOC
CALL FUNCTION 'IDOC_GET_MESSAGE_ATTRIBUTE'
EXPORTING
idoc_number = <fs_edidc>-docnum
IMPORTING
idoc_message = lv_stat_message.
* Get IDOC details
CALL FUNCTION 'IDOC_READ_COMPLETELY'
EXPORTING
document_number = <fs_edidc>-docnum
IMPORTING
idoc_control = ls_idoc_control
number_of_data_records = lv_tot_data_recs
number_of_status_records = lv_tot_status_recs
TABLES
int_edids = lt_edids
int_edidd = lt_edidd
EXCEPTIONS
document_not_exist = 1
document_number_invalid = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Pass data to output table
CALL METHOD me->process_data
EXPORTING
im_docnum = <fs_edidc>-docnum.
ENDLOOP.
DELETE gt_output WHERE ebeln IS INITIAL.
IF gt_output[] IS NOT INITIAL.
* Get vendor for fetched POs
SELECT ebeln lifnr
FROM ekko
INTO TABLE gt_ekko
FOR ALL ENTRIES IN gt_output
WHERE ebeln = gt_output-ebeln.
IF gt_ekko[] IS NOT INITIAL.
* Get name of vendors
SELECT lifnr name1
FROM lfa1
INTO TABLE gt_lfa1
FOR ALL ENTRIES IN gt_ekko
WHERE lifnr = gt_ekko-lifnr.
ENDIF.
* Pass vendor details to output table
LOOP AT gt_output ASSIGNING <fs_output>.
READ TABLE gt_ekko ASSIGNING <fs_ekko>
WITH TABLE KEY ebeln = <fs_output>-ebeln.
IF sy-subrc = 0.
READ TABLE gt_lfa1 ASSIGNING <fs_lfa1>
WITH TABLE KEY lifnr = <fs_ekko>-lifnr.
IF sy-subrc = 0.
<fs_output>-lifnr = <fs_lfa1>-lifnr.
<fs_output>-name1 = <fs_lfa1>-name1.
ENDIF.
ENDIF.
ENDLOOP.
CREATE OBJECT o_lcl_alv_routines.
CALL METHOD o_lcl_alv_routines->display_data
EXPORTING
im_output = gt_output[].
ENDIF.
ENDMETHOD. "read_idocs
* METHOD process_data
METHOD process_data.
FIELD-SYMBOLS: <fs_edidd> LIKE LINE OF lt_edidd.
IF lv_stat_message CP 'ok' OR
lv_stat_message CP 'positive'.
wa_output-exception = lc_green.
ELSEIF lv_stat_message CP 'error' OR
lv_stat_message CP 'negative'.
wa_output-exception = lc_red.
ELSE.
wa_output-exception = lc_yellow.
ENDIF.
READ TABLE lt_edidd ASSIGNING <fs_edidd>
WITH KEY docnum = im_docnum
segnam = lc_segnam.
IF sy-subrc = 0.
wa_output-ebeln = <fs_edidd>-sdata+0(10).
ENDIF.
wa_output-credat = ls_idoc_control-credat.
wa_output-cretim = ls_idoc_control-cretim.
APPEND wa_output TO gt_output.
CLEAR wa_output.
ENDMETHOD. "process_data
ENDCLASS. "lcl_get_data IMPLEMENTATION
* CLASS lcl_alv_routines IMPLEMENTATION
CLASS lcl_alv_routines IMPLEMENTATION.
* METHOD display_data
METHOD display_data.
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = 0
text = text-p03.
gt_output[] = im_output[].
TRY.
cl_salv_table=>factory(
EXPORTING
list_display = ''
IMPORTING
r_salv_table = lcl_table
CHANGING
t_table = gt_output ).
CATCH cx_salv_msg. "#EC NO_HANDLER
ENDTRY.
lcl_functions = lcl_table->get_functions( ).
* Set all standard ALV functions
lcl_functions->set_all( abap_true ).
lcl_columns = lcl_table->get_columns( ).
lcl_columns->set_optimize( '' ).
* Set display to striped pattern
lcl_display = lcl_table->get_display_settings( ).
lcl_display->set_striped_pattern( cl_salv_display_settings=>true ).
*/Sort columns
TRY.
lcl_sorts = lcl_table->get_sorts( ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
lcl_sorts->set_group_active( ).
TRY.
lcl_sorts->add_sort(
columnname = 'EBELN'
subtotal = '' ).
CATCH cx_salv_not_found cx_salv_existing cx_salv_data_error."#EC NO_HANDLER
ENDTRY.
*/Set column names
TRY.
lcl_columns->set_exception_column( 'EXCEPTION' ).
CATCH cx_salv_data_error. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'EXCEPTION' ).
lcl_column->set_short_text( text-h01 ).
lcl_column->set_medium_text( text-h01 ).
lcl_column->set_long_text( text-h01 ).
lcl_column->set_output_length( '6' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'EBELN' ).
lcl_column->set_short_text( text-h02 ).
lcl_column->set_medium_text( text-h02 ).
lcl_column->set_long_text( text-h02 ).
lcl_column->set_output_length( '9' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'LIFNR' ).
* lcl_column->set_short_text( text-h03 ).
lcl_column->set_medium_text( text-h03 ).
lcl_column->set_long_text( text-h03 ).
lcl_column->set_output_length( '11' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'NAME1' ).
* lcl_column->set_short_text( text-h04 ).
* lcl_column->set_medium_text( text-h04 ).
lcl_column->set_long_text( text-h04 ).
lcl_column->set_output_length( '30' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'CREDAT' ).
* lcl_column->set_short_text( text-h05 ).
* lcl_column->set_medium_text( text-h05 ).
lcl_column->set_long_text( text-h05 ).
lcl_column->set_output_length( '13' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
TRY.
lcl_column ?= lcl_columns->get_column( 'CRETIM' ).
* lcl_column->set_short_text( text-h06 ).
* lcl_column->set_medium_text( text-h06 ).
lcl_column->set_long_text( text-h06 ).
lcl_column->set_output_length( '13' ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
*/Set aggregations
* TRY.
* lcl_aggregations = lcl_table->get_aggregations( ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
* TRY.
* lcl_aggregations->add_aggregation( '' ).
* CATCH cx_salv_not_found cx_salv_data_error cx_salv_existing."#EC NO_HANDLER
* ENDTRY.
*/Hide columns
* TRY.
* lcl_column ?= lcl_columns->get_column( 'DESCRIPT' ).
* lcl_column->set_visible( if_salv_c_bool_sap=>false ).
* CATCH cx_salv_not_found. "#EC NO_HANDLER
* ENDTRY.
*/Display top of page
CALL METHOD me->display_top_of_page.
lcl_table->set_top_of_list( lcl_content ).
*/Handle ALV events
lcl_events2 = lcl_table->get_event( ).
CREATE OBJECT lcl_handle_events.
SET HANDLER lcl_handle_events->on_link_click FOR lcl_events2.
lcl_display_settings = lcl_table->get_display_settings( ).
lcl_table->display( ).
ENDMETHOD. "display_data
* METHOD display_top_of_page
METHOD display_top_of_page.
CREATE OBJECT lcl_grid.
lv_title = text-t01.
lcl_grid->create_header_information(
row = 1
column = 1
text = lv_title
tooltip = lv_title ).
lcl_grid->add_row( ).
lcl_grid_1 = lcl_grid->create_grid(
row = 3
column = 1 ).
CLEAR lv_string.
CONCATENATE: sy-datum+4(2) '/' sy-datum+6(2) '/' sy-datum+0(4)
INTO lv_date1.
CONCATENATE: text-t02 lv_date1
INTO lv_string
SEPARATED BY space.
lcl_label = lcl_grid_1->create_label(
row = 1
column = 1
text = lv_string
tooltip = lv_string ).
CLEAR lv_string.
CONCATENATE: sy-uzeit+0(2) ':' sy-uzeit+2(2) ':' sy-uzeit+4(2)
INTO lv_time.
CONCATENATE: text-t03 lv_time
INTO lv_string
SEPARATED BY space.
lcl_label = lcl_grid_1->create_label(
row = 2
column = 1
text = lv_string
tooltip = lv_string ).
lcl_content = lcl_grid.
ENDMETHOD. "display_top_of_page
ENDCLASS. "lcl_alv_routines IMPLEMENTATION
* CLASS lcl_handle_events IMPLEMENTATION
CLASS lcl_handle_events IMPLEMENTATION.
* METHOD on_link_click
METHOD on_link_click.
ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION
* START-OF-SELECTION *
START-OF-SELECTION.
DATA: o_lcl_get_data TYPE REF TO lcl_get_data.
CREATE OBJECT o_lcl_get_data.
CALL METHOD o_lcl_get_data->get_idocs. -
ALV Tree Report without using ABAP Objects
Hi all,
I want to know the name of a function module to create ALV Tree in SE38 as a report. I am required to create this ALV Tree Report without using ABAP OBJECTS. Can u pls help me as early as possible.Hi
see this link
http://www.sapdev.co.uk/reporting/alv/alvtree.htm
*& Report ZBCALV_TREE
REPORT ZBCALV_TREE.
class cl_gui_column_tree definition load.
class cl_gui_cfw definition load.
data tree1 type ref to cl_gui_alv_tree.
data mr_toolbar type ref to cl_gui_toolbar.
include <icon>.
include bcalv_toolbar_event_receiver.
include bcalv_tree_event_receiver.
data: toolbar_event_receiver type ref to lcl_toolbar_event_receiver.
data: gt_VBAK type VBAK occurs 0, "Output-Table
gt_fieldcatalog type lvc_t_fcat, "Fieldcatalog
ok_code like sy-ucomm. "OK-Code
start-of-selection.
end-of-selection.
call screen 100.
*& Module STATUS_0100 OUTPUT
text
module STATUS_0100 output.
SET PF-STATUS 'MAIN'.
if tree1 is initial.
perform Zinit_tree.
endif.
call method cl_gui_cfw=>flush.
endmodule. " STATUS_0100 OUTPUT
*& Form Zinit_tree
text
--> p1 text
<-- p2 text
form Zinit_tree .
perform Zbuild_fieldcatalog.
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'. "#EC NOTEXT
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.
create Hierarchy-header
data l_hierarchy_header type treev_hhdr.
perform zbuild_hierarchy_header changing l_hierarchy_header.
create info-table for html-header
data: lt_list_commentary type slis_t_listheader,
l_logo type sdydo_value.
perform Zbuild_comment using
lt_list_commentary
l_logo.
repid for saving variants
data: ls_variant type disvariant.
ls_variant-report = sy-repid.
create emty tree-control
call method tree1->set_table_for_first_display
exporting
is_hierarchy_header = l_hierarchy_header
it_list_commentary = lt_list_commentary
i_logo = l_logo
i_background_id = 'ALV_BACKGROUND'
i_save = 'A'
is_variant = ls_variant
changing
it_outtab = gt_VBAK "table must be emty !!
it_fieldcatalog = gt_fieldcatalog.
create hierarchy
perform Zcreate_hierarchy.
add own functioncodes to the toolbar
perform zchange_toolbar.
register events
perform zregister_events.
endform. " Zinit_tree
*& Form Zbuild_fieldcatalog
text
--> p1 text
<-- p2 text
form Zbuild_fieldcatalog .
get fieldcatalog
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'VBAK'
changing
ct_fieldcat = gt_fieldcatalog.
sort gt_fieldcatalog by scrtext_l.
change fieldcatalog
data: ls_fieldcatalog type lvc_s_fcat.
loop at gt_fieldcatalog into ls_fieldcatalog.
case ls_fieldcatalog-fieldname.
when 'AUART' .
ls_fieldcatalog-no_out = 'X'.
ls_fieldcatalog-key = ''.
endcase.
modify gt_fieldcatalog from ls_fieldcatalog.
endloop.
endform. " Zbuild_fieldcatalog
*& Form zbuild_hierarchy_header
text
<--P_L_HIERARCHY_HEADER text
form zbuild_hierarchy_header changing
p_hierarchy_header type treev_hhdr.
p_hierarchy_header-heading = 'Hierarchy Header'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.
endform. " zbuild_hierarchy_header
*& Form Zbuild_comment
text
-->P_LT_LIST_COMMENTARY text
-->P_L_LOGO text
form Zbuild_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 = 'ALV-tree-demo: flight-overview'. "#EC NOTEXT
append ls_line to pt_list_commentary.
STATUS LINE: TYPE S
clear ls_line.
ls_line-typ = 'S'.
ls_line-key = 'valid until'. "#EC NOTEXT
ls_line-info = 'January 29 1999'. "#EC NOTEXT
append ls_line to pt_list_commentary.
ls_line-key = 'time'.
ls_line-info = '2.00 pm'. "#EC NOTEXT
append ls_line to pt_list_commentary.
ACTION LINE: TYPE A
clear ls_line.
ls_line-typ = 'A'.
LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = 'actual data'. "#EC NOTEXT
append ls_line to pt_list_commentary.
p_logo = 'ENJOYSAP_LOGO'.
endform. " Zbuild_comment
*& Form Zcreate_hierarchy
text
--> p1 text
<-- p2 text
form Zcreate_hierarchy .
data: ls_vbak type vbak,
lt_vbak type vbak occurs 0.
get data
select * from vbak into table lt_vbak
up to 200 rows . "#EC CI_NOWHERE
sort lt_vbak by AUART.
add data to tree
data: l_AUART_key type lvc_nkey.
loop at lt_vbak into ls_vbak.
on change of ls_vbak-AUART.
perform Zadd_AUART_line using ls_vbak
changing l_AUART_key.
endon.
endloop.
calculate totals
call method tree1->update_calculations.
this method must be called to send the data to the frontend
call method tree1->frontend_update.
endform. " Zcreate_hierarchy
*& Form Zadd_AUART_line
text
-->P_LS_vbak text
-->P_0379 text
<--P_L_AUART_KEY text
form Zadd_AUART_line using p_ls_vbak type vbak
p_relat_key type lvc_nkey
changing p_node_key type lvc_nkey.
data: l_node_text type lvc_value,
ls_vbak type vbak.
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_ls_vbak-AUART.
data: ls_node type lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
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 = ls_vbak
is_node_layout = ls_node
it_item_layout = lt_item_layout
importing
e_new_node_key = p_node_key .
endform. " Zadd_AUART_line
*& Form zchange_toolbar
text
--> p1 text
<-- p2 text
form zchange_toolbar .
get toolbar control
call method tree1->get_toolbar_object
importing
er_toolbar = mr_toolbar.
check not mr_toolbar is initial.
add seperator to toolbar
call method mr_toolbar->add_button
exporting
fcode = ''
icon = ''
butn_type = cntb_btype_sep
text = ''
quickinfo = 'This is a Seperator'. "#EC NOTEXT
add Standard Button to toolbar (for Delete Subtree)
call method mr_toolbar->add_button
exporting
fcode = 'DELETE'
icon = '@18@'
butn_type = cntb_btype_button
text = ''
quickinfo = 'Delete subtree'. "#EC NOTEXT
add Dropdown Button to toolbar (for Insert Line)
call method mr_toolbar->add_button
exporting
fcode = 'INSERT_LC'
icon = '@17@'
butn_type = cntb_btype_dropdown
text = ''
quickinfo = 'Insert Line'. "#EC NOTEXT
set event-handler for toolbar-control
create object toolbar_event_receiver.
set handler toolbar_event_receiver->on_function_selected
for mr_toolbar.
set handler toolbar_event_receiver->on_toolbar_dropdown
for mr_toolbar.
endform. " zchange_toolbar
*& Form zregister_events
text
--> p1 text
<-- p2 text
form zregister_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. " zregister_events
*& Module USER_COMMAND_0100 INPUT
text
module USER_COMMAND_0100 input.
ok_code = sy-ucomm.
clear sy-ucomm.
case ok_code.
when 'EXIT' or 'BACK' or 'CANC'.
perform Zexit_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 Zexit_program
text
--> p1 text
<-- p2 text
form Zexit_program .
call method tree1->free.
leave program.
endform. " Zexit_program
<b>Reward if usefull</b> -
Double Click Event In ALV Tree
Hello guys,
There is a requirement that when I double click on an item in ALV tree it takes me to a standard transaction code.
Can anyone suggest me how to proceed on this.
Thanks in Advance.
Regards,
AbhinavHi,
Refer:
Get cursor field in ALV Tree
Hope this helps you.
Regards,
Tarun -
Select all checkbox in ALV tree
Hi There,
I have developed a report using ALV tree with 3 level nodes. I have introduced checkbox in one of the column in the node..
By this I can select the checkbox individually. I have got the requirement to select all the checkboxes simultaneously using a button. I tried several things but no help..
Please help me with this..I have used class 'cl_gui_alv_tree' for designing the Tree.Hi,
You need to add a button to the toolbar manually, when the button is pressed loop at all the nodes that have a checkbox and update the checkbox field.
Something like....
data: go_tree1 type ref to cl_gui_alv_tree,
go_toolbar type ref to cl_gui_toolbar
* Add buttons to the toolbar
call method go_tree1->get_toolbar_object
importing
er_toolbar = go_toolbar.
check go_toolbar is not initial.
call method go_toolbar->add_button
exporting
fcode = 'SELALL'
icon = icon_select_all
butn_type = cntb_btype_button
text = ''
quickinfo = 'Select All'.
* Define an event handler
data: go_receiver type ref to lcl_event_receiver.
class lcl_event_receiver definition.
public section.
methods:
function_selected for event function_selected of cl_gui_toolbar
importing fcode.
endclass.
class lcl_event_receiver implementation.
method function_selected.
case fcode.
when 'SELALL'.
perform select_all.
endmethod.
* Register the event
create object go_receiver.
set handler go_receiver->function_selected for go_toolbar.
form select_all.
data: lv_field type lvc_fname.
* Update the checkbox on each node of the ALV tree
lv_field = 'CHECK'. "Whatever you've called the checkbox
call method go_tree1->change_item
exporting
i_node_key = node_key "<-- loop at the nodes and repeat for each one with a checkbox
i_fieldname = lv_field
i_data = ' '
exceptions
node_not_found = 1
others = 2.
call method go_tree1->frontend_update. "call this onces all updates have been made
endform.
Regards,
Darren -
Hi,
I am developing an ALV TREE. I need help Its really urgent. In the output screen there will be 2 level nodes. in the item line 1 field should be input enabled using which the database table is to be modified.when user left clicks on this field a drop down list will appear from which he selects his choice.
I looked into BCALV_TREE_SIMPLE_DEMO reports available in SAP.
I would also like to know what is register_events, what is an handler.
help me.
Edited by: Sudipa Das on Oct 4, 2008 11:53 AM
Edited by: Sudipa Das on Oct 4, 2008 11:53 AM
Edited by: Sudipa Das on Oct 4, 2008 11:54 AMHello Sudipa
I do not think you can have editable fields other than checkboxes in ALV trees. In sample report ZUS_SDN_ALV_TREE_DEMO_1 I have set the fieldcatalog property LS_FCAT-EDIT = 'X' for all fields yet only LOEVM is editable because it is defined as checkbox, too.
However, you may use the LINK_CLICK of the ALV tree (set LS_FCAT-HOTSPOT = 'X' in fieldcatalog) to trigger e.g. a seach help for input.
*& Report ZUS_SDN_ALV_TREE_DEMO
*& Thread: drop down list in alv tree
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1074082"></a>
*& Thread: alv tree checbox problem when attempt to get the selected checjboxes
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1050473"></a>
*& Thread: alv tree checkbox problem
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1046535"></a>
*& Thread: double click in ALV tree output????
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="742412"></a>
*& Flow logic of screen '0100' (contains no screen elements):
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
*& user-command (for command window): DISPLAY, SELECTED_NODES
REPORT zus_sdn_alv_tree_demo_1.
CLASS cl_gui_column_tree DEFINITION LOAD.
CLASS cl_gui_cfw DEFINITION LOAD.
TYPE-POOLS: abap, shlp.
TYPES: BEGIN OF ty_s_key.
TYPES: nkey TYPE lvc_nkey.
TYPES: parent_key TYPE lvc_nkey.
TYPES: END OF ty_s_key.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE knvv AS data.
INCLUDE TYPE ty_s_key AS key.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA: gt_outtab TYPE ty_t_outtab.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syst-repid,
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_tree TYPE REF TO cl_gui_alv_tree.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
handle_node_double_click
FOR EVENT node_double_click OF cl_gui_alv_tree
IMPORTING node_key,
handle_item_double_click
FOR EVENT item_double_click OF cl_gui_alv_tree
IMPORTING node_key
fieldname,
handle_checkbox_change
FOR EVENT checkbox_change OF cl_gui_alv_tree
IMPORTING checked
fieldname
node_key,
handle_link_click
FOR EVENT link_click OF cl_gui_alv_tree
IMPORTING fieldname
node_key.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_node_double_click.
MESSAGE 'Event=Double-Click on Node' TYPE 'I'.
CALL TRANSACTION 'XD03'.
ENDMETHOD. "handle_node_double_click
METHOD handle_item_double_click.
MESSAGE 'Event=Double-Click on Item' TYPE 'I'.
CALL TRANSACTION 'VA03'.
ENDMETHOD. "handle_item_double_click
METHOD handle_checkbox_change.
DATA: ls_outtab TYPE ty_s_outtab.
BREAK-POINT.
IF ( fieldname = 'LOEVM' ).
CALL METHOD go_tree->get_outtab_line
EXPORTING
i_node_key = node_key
IMPORTING
e_outtab_line = ls_outtab
* e_node_text =
* et_item_layout =
* es_node_layout =
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ls_outtab-loevm = checked.
MODIFY gt_outtab FROM ls_outtab
TRANSPORTING loevm
WHERE ( nkey = node_key ).
ENDIF.
" Trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH'
* IMPORTING
* rc =
ENDMETHOD. "handle_checkbox_change
METHOD handle_link_click.
data: ls_shlp type SHLP_DESCR,
lt_retvalues type STANDARD TABLE OF DDSHRETVAL.
BREAK-POINT.
CALL FUNCTION 'F4IF_GET_SHLP_DESCR'
EXPORTING
shlpname = 'USER_COMP'
* SHLPTYPE = 'SH'
IMPORTING
SHLP = ls_shlp.
CALL FUNCTION 'F4IF_START_VALUE_REQUEST'
EXPORTING
shlp = ls_shlp
* DISPONLY = ' '
* MAXRECORDS = 500
* MULTISEL = ' '
* CUCOL = SY-CUCOL
* CUROW = SY-CUROW
* IMPORTING
* RC =
tables
return_values = lt_retvalues.
ENDMETHOD. "handle_link_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* container =
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
lifetime_dynpro_dynpro_link = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL SCREEN '0100'.
** NOTE: no elements on screen
** PROCESS BEFORE OUTPUT.
** MODULE STATUS_0100.
** PROCESS AFTER INPUT.
** MODULE USER_COMMAND_0100.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
TRANSLATE gd_okcode TO UPPER CASE.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'REFRESH'.
CALL METHOD go_tree->update_calculations
* EXPORTING
* no_frontend_update =
WHEN 'SELECTED_NODES'.
PERFORM get_selected_nodes.
WHEN 'DISPLAY'.
PERFORM display.
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form init_controls
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
OTHERS = 6.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* create tree control
CREATE OBJECT go_tree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X' " required for double-click event on item
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.
* create Hierarchy-header
DATA ls_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING ls_hierarchy_header.
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
* create emty tree-control
CALL METHOD go_tree->set_table_for_first_display
EXPORTING
** i_structure_name = 'KNVV'
is_variant = gs_variant
i_save = 'A'
* i_default = 'X'
is_hierarchy_header = ls_hierarchy_header
* is_exception_field =
* it_special_groups =
* it_list_commentary =
* i_logo =
* i_background_id =
* it_toolbar_excluding =
* it_except_qinfo =
CHANGING
it_outtab = gt_outtab
* it_filter =
it_fieldcatalog = gt_fcat.
* create hierarchy
PERFORM create_hierarchy.
* register events
PERFORM register_events.
* adjust column_width
CALL METHOD go_tree->column_optimize.
ENDFORM. " init_controls
*& Form build_hierarchy_header
* build hierarchy-header-information
* -->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Hierarchy Header'. "#EC NOTEXT
p_hierarchy_header-tooltip =
'This is the Hierarchy Header !'. "#EC NOTEXT
p_hierarchy_header-width = 30.
p_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
DATA: ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'KNVV'
* I_CLIENT_NEVER_DISPLAY = 'X'
i_bypassing_buffer = 'X'
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DELETE gt_fcat FROM 10.
ls_fcat-tech = 'X'.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING tech
WHERE ( key = 'X' ).
ls_fcat-edit = 'X'.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING edit
WHERE ( key NE 'X' ).
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'LOEVM'.
IF ( syst-subrc = 0 ).
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
** ls_fcat-hotspot = 'X'.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDIF.
READ TABLE gt_fcat INTO ls_fcat
WITH KEY fieldname = 'ERNAM'.
IF ( syst-subrc = 0 ).
ls_fcat-hotspot = 'X'.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDIF.
ENDFORM. " BUILD_FIELDCATALOG
*& Form SET_LAYOUT_AND_VARIANT
* text
* --> p1 text
* <-- p2 text
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_variant-report = syst-repid.
gs_variant-handle = 'TREE'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
DATA: ls_knvv TYPE sflight,
ld_idx TYPE i,
ls_outtab TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
* get data
SELECT * FROM knvv INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 20 ROWS . "#EC CI_NOWHERE
SORT lt_outtab BY kunnr vkorg.
* add data to tree
DATA: ld_root_key TYPE lvc_nkey,
ld_kunnr_key TYPE lvc_nkey,
ld_vkorg_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey.
ld_idx = 0.
LOOP AT lt_outtab INTO ls_outtab.
AT FIRST.
PERFORM add_root_line USING ls_outtab-data
CHANGING ld_root_key.
ADD 1 TO ld_idx.
ls_outtab-nkey = ld_root_key.
ls_outtab-parent_key = space.
MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
TRANSPORTING key.
ENDAT.
ON CHANGE OF ls_outtab-kunnr.
PERFORM add_customer_line USING ls_outtab-data
ld_root_key
CHANGING ld_kunnr_key.
ADD 1 TO ld_idx.
ls_outtab-nkey = ld_kunnr_key.
ls_outtab-parent_key = ld_root_key.
MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
TRANSPORTING key.
ENDON.
ON CHANGE OF ls_outtab-vkorg.
PERFORM add_salesorg_line USING ls_outtab-data
ld_kunnr_key
CHANGING ld_vkorg_key.
ADD 1 TO ld_idx.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-parent_key = ld_kunnr_key.
MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
TRANSPORTING key.
ENDON.
PERFORM add_complete_line USING ls_outtab-data
ld_vkorg_key
CHANGING ld_last_key.
ADD 1 TO ld_idx.
ls_outtab-nkey = ld_last_key.
ls_outtab-parent_key = ld_vkorg_key.
MODIFY gt_outtab FROM ls_outtab INDEX ld_idx
TRANSPORTING key.
ENDLOOP.
* calculate totals
CALL METHOD go_tree->update_calculations.
* this method must be called to send the data to the frontend
CALL METHOD go_tree->frontend_update.
ENDFORM. " create_hierarchy
*& Form add_customer_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_root_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_data TYPE ty_s_outtab-data.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@3Q@'. " icon_overview
ls_item_layout-fieldname = go_tree->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 = 'Overview: Sales Areas'.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_data
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_root_line
*& Form add_customer_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_customer_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_data TYPE ty_s_outtab-data.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@A0@'. " icon_customer.
ls_item_layout-fieldname = go_tree->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 = us_data-kunnr.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_data
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_customer_line
*& Form add_salesorg_line
* add hierarchy-level 1 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_salesorg_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_data TYPE ty_s_outtab-data.
* set item-layout
DATA: lt_item_layout TYPE lvc_t_layi,
ls_item_layout TYPE lvc_s_layi.
ls_item_layout-t_image = '@DS@'. " ICON_PARTNER_SALES_ACTIVITY
ls_item_layout-fieldname = go_tree->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 = us_data-vkorg.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = l_node_text
is_outtab_line = ls_data
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_salesorg_line
*& Form add_cmplete_line
* add hierarchy-level 3 to tree
* -->P_LS_SFLIGHT sflight
* -->P_RELEATKEY relatkey
* <-->p_node_key new node-key
FORM add_complete_line USING us_data TYPE ty_s_outtab-data
ud_relat_key TYPE lvc_nkey
CHANGING cd_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 = go_tree->c_hierarchy_column_name.
ls_item_layout-class = cl_gui_column_tree=>item_class_checkbox.
ls_item_layout-editable = 'X'.
APPEND ls_item_layout TO lt_item_layout.
** clear: ls_item_layout.
** ls_item_layout-fieldname = 'BEGRU'.
** ls_item_layout-class = cl_gui_column_tree=>ITEM_CLASS_CHECKBOX.
** ls_item_layout-editable = 'X'.
** APPEND ls_item_layout TO lt_item_layout.
** CLEAR ls_item_layout.
** ls_item_layout-fieldname = 'PLANETYPE'.
** ls_item_layout-alignment = cl_gui_column_tree=>align_right.
** APPEND ls_item_layout TO lt_item_layout.
l_node_text = us_data-vtweg.
DATA: ls_node TYPE lvc_s_layn.
ls_node-n_image = space.
ls_node-exp_image = space.
CALL METHOD go_tree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = us_data
i_node_text = l_node_text
is_node_layout = ls_node
it_item_layout = lt_item_layout
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
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.
l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_item_double_click.
APPEND l_event TO lt_events.
l_event-eventid = cl_gui_column_tree=>eventid_link_click.
APPEND l_event TO lt_events.
CALL METHOD go_tree->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
SET HANDLER:
lcl_eventhandler=>handle_node_double_click FOR go_tree,
lcl_eventhandler=>handle_item_double_click FOR go_tree,
lcl_eventhandler=>handle_checkbox_change FOR go_tree,
lcl_eventhandler=>handle_link_click FOR go_tree.
** 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.
** SET HANDLER l_event_receiver->handle_checkbox_change FOR tree1.
ENDFORM. " register_events
*& Form DISPLAY
* text
* --> p1 text
* <-- p2 text
FORM display .
DATA: ls_outtab TYPE ty_s_outtab,
ls_line TYPE ty_s_outtab,
ld_msg TYPE bapi_msg.
BREAK-POINT.
LOOP AT gt_outtab INTO ls_outtab
WHERE ( loevm = 'X' ).
CONCATENATE 'Checkbox:'
ls_outtab-kunnr
ls_outtab-vkorg
ls_outtab-vtweg
ls_outtab-spart
ls_outtab-loevm
INTO ld_msg SEPARATED BY space.
MESSAGE ld_msg TYPE 'I'.
ENDLOOP.
IF ( syst-subrc NE 0 ).
MESSAGE 'No marked checkboxes found' TYPE 'I'.
ENDIF.
PERFORM get_selected_nodes.
ENDFORM. " DISPLAY
*& Form GET_SELECTED_NODES
* text
* --> p1 text
* <-- p2 text
FORM get_selected_nodes.
* define local data
DATA: ld_msg TYPE bapi_msg,
lt_nodes TYPE lvc_t_nkey,
ls_outtab TYPE ty_s_outtab,
ld_nkey TYPE lvc_nkey,
lt_items TYPE lvc_t_layi,
ls_item TYPE lvc_s_layi.
CALL METHOD go_tree->get_selected_nodes
CHANGING
ct_selected_nodes = lt_nodes
EXCEPTIONS
cntl_system_error = 1
dp_error = 2
failed = 3
OTHERS = 4.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CHECK ( lt_nodes IS NOT INITIAL ).
BREAK-POINT.
LOOP AT lt_nodes INTO ld_nkey.
CALL METHOD go_tree->get_outtab_line
EXPORTING
i_node_key = ld_nkey
IMPORTING
e_outtab_line = ls_outtab-data
* e_node_text =
et_item_layout = lt_items
* es_node_layout =
EXCEPTIONS
node_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT lt_items INTO ls_item
WHERE ( chosen = 'X' ).
CONCATENATE 'Item:'
ls_outtab-kunnr
ls_outtab-vkorg
ls_outtab-vtweg
ls_outtab-spart
ls_outtab-loevm
INTO ld_msg SEPARATED BY space.
MESSAGE ld_msg TYPE 'I'.
ENDLOOP.
ENDLOOP.
ENDFORM. " GET_SELECTED_NODES
Regards
Uwe -
Displaying ALV tree in expanded form in first ouput
Hi all,
I have a problem with alv tree. My requirement is, on the first output itself the alv tree should appear expanded depending on one of the filter criteria in the tool bar. How can i trigger the toolbar event in PBO itself? Can it be done? if yes please provide sample code. Points assured for helpfull answers.
Thanks,
ShafiqHi Walter,
The method CL_GUI_ALV_TREE->EXPAND_NODES has only one importing parameter and that is the nodes of the ALV tree. But the commenting of the following lines from my code made it work which i have made it bold.Thank you very much for your help.I Have awarded points for you.
REPORT ztest_2105.
DATA: g_alv_tree TYPE REF TO cl_gui_alv_tree,
g_custom_container TYPE REF TO cl_gui_custom_container.
DATA: gt_sflight TYPE sflight OCCURS 0, "Output-Table
gt_fieldcatalog TYPE lvc_t_fcat,
ok_code LIKE sy-ucomm,
save_ok LIKE sy-ucomm, "OK-Code
g_max TYPE i VALUE 255. "maximum of db records to select
DATA : it_node_key TYPE lvc_t_nkey,
wa_node_key LIKE LINE OF it_node_key.
LOCAL CLASSES
*§1. Define a (local) class for event handling
CLASS lcl_tree_event_receiver DEFINITION.
PUBLIC SECTION.
*§2. Define an event handler method for each event you want to react to
METHODS handle_node_double_click
FOR EVENT node_double_click OF cl_gui_alv_tree
IMPORTING node_key sender.
'sender' is an implicit event parameter that is provided by
ABAP Objects runtime system. It contains a reference to the
object that fired the event. You may directly use it to
call methods of this instance.
ENDCLASS.
CLASS lcl_tree_event_receiver IMPLEMENTATION.
*§3. Implement your event handler methods.
METHOD handle_node_double_click.
DATA: lt_children TYPE lvc_t_nkey.
*first check if the node is a leaf, i.e. can not be expanded
CALL METHOD sender->get_children
EXPORTING i_node_key = node_key
IMPORTING et_children = lt_children.
IF NOT lt_children IS INITIAL.
CALL METHOD sender->expand_node
EXPORTING i_node_key = node_key
i_level_count = 2.
ENDIF.
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
END-OF-SELECTION.
CALL SCREEN 100.
*& Module PBO OUTPUT
process before output
MODULE pbo OUTPUT.
SET PF-STATUS 'MAIN100'.
SET TITLEBAR 'MAINTITLE'.
IF g_alv_tree IS INITIAL.
PERFORM init_tree.
CALL METHOD g_alv_tree->expand_nodes
EXPORTING
it_node_key = it_node_key
EXCEPTIONS
FAILED = 1
CNTL_SYSTEM_ERROR = 2
ERROR_IN_NODE_KEY_TABLE = 3
DP_ERROR = 4
NODE_NOT_FOUND = 5
others = 6
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
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.
ENDMODULE. " PBO OUTPUT
*& Module PAI INPUT
process after input
MODULE pai INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'EXIT' OR 'BACK' OR 'CANC'.
PERFORM exit_program.
WHEN OTHERS.
§5. Call dispatch to process toolbar functions
Toolbar events are registered in constructur method of
CL_ALV_TREE_BASE as application events. So the dispatch call
is a must if you want to use the standard toolbar.
CALL METHOD cl_gui_cfw=>dispatch.
ENDCASE.
CALL METHOD cl_gui_cfw=>flush.
ENDMODULE. " PAI INPUT
*& Form init_tree
text
--> p1 text
<-- p2 text
FORM init_tree.
create container for alv-tree
DATA: l_tree_container_name(30) TYPE c.
l_tree_container_name = 'CCONTAINER1'.
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.
DATA l_hierarchy_header TYPE treev_hhdr.
PERFORM build_hierarchy_header CHANGING l_hierarchy_header.
Hide columns and sum up values initially using the fieldcatalog
PERFORM build_fieldcatalog.
IMPORTANT: Table 'gt_sflight' must be empty. Do not change this table
(even after this method call). You can change data of your table
by calling methods of CL_GUI_ALV_TREE.
Furthermore, the output table 'gt_outtab' must be global and can
only be used for one ALV Tree Control.
CALL METHOD g_alv_tree->set_table_for_first_display
EXPORTING
is_hierarchy_header = l_hierarchy_header
CHANGING
it_fieldcatalog = gt_fieldcatalog
it_outtab = gt_sflight. "table must be empty!
PERFORM create_hierarchy.
PERFORM register_events.
Update calculations which were initially defined by field DO_SUM
of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD g_alv_tree->update_calculations.
Send data to frontend.
CALL METHOD g_alv_tree->frontend_update.
ENDFORM. " init_tree
*& Form build_hierarchy_header
build hierarchy-header-information
-->P_L_HIERARCHY_HEADER strucxture for hierarchy-header
FORM build_hierarchy_header CHANGING
p_hierarchy_header TYPE treev_hhdr.
p_hierarchy_header-heading = 'Totals/Month/Carrier/Date'(300).
p_hierarchy_header-tooltip = 'Flights in a month'(400).
p_hierarchy_header-width = 35.
p_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form exit_program
free object and leave program
FORM exit_program.
CALL METHOD g_custom_container->free.
LEAVE PROGRAM.
ENDFORM. " exit_program
FORM build_fieldcatalog.
DATA: ls_fieldcatalog TYPE lvc_s_fcat.
The following function module generates a fieldcatalog according
to a given structure.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SFLIGHT'
CHANGING
ct_fieldcat = gt_fieldcatalog.
Now change the fieldcatalog to hide fields and to determine
some initial calculations for chosen fields.
LOOP AT gt_fieldcatalog INTO ls_fieldcatalog.
CASE ls_fieldcatalog-fieldname.
hide columns which are already displayed in our tree
WHEN 'CARRID' OR 'FLDATE'.
ls_fieldcatalog-no_out = 'X'.
Do some initial calculations:
ALV Tree uses the field 'do_sum' to declare that a function
for the corresponding column shall be calculated.
Use 'h_ftype' to set the function type (MAX, MIN, SUM, AVG).
WHEN 'PRICE'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'MAX'.
WHEN 'SEATSMAX'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'SUM'.
WHEN 'SEATSOCC'.
ls_fieldcatalog-do_sum = 'X'.
ls_fieldcatalog-h_ftype = 'AVG'.
ENDCASE.
MODIFY gt_fieldcatalog FROM ls_fieldcatalog.
ENDLOOP.
The fieldcatalog is provided in form 'init_tree' using method
set_table_for_first_display.
ENDFORM. " build_fieldcatalog
FORM register_events.
*§4. Event registration: tell ALV Tree which events shall be passed
from frontend to backend.
DATA: lt_events TYPE cntl_simple_events,
l_event TYPE cntl_simple_event,
l_event_receiver TYPE REF TO lcl_tree_event_receiver.
*§4a. Frontend registration(i): get already registered tree events.
The following four tree events registers ALV Tree in the constructor
method itself.
- cl_gui_column_tree=>eventid_expand_no_children
(needed to load data to frontend when a user expands a node)
- cl_gui_column_tree=>eventid_header_context_men_req
(needed for header context menu)
- cl_gui_column_tree=>eventid_header_click
(allows selection of columns (only when item selection activated))
- cl_gui_column_tree=>eventid_item_keypress
(needed for F1-Help (only when item selection activated))
Nevertheless you have to provide their IDs again if you register
additional events with SET_REGISTERED_EVENTS (see below).
To do so, call first method GET_REGISTERED_EVENTS (this way,
all already registered events remain registered, even your own):
CALL METHOD g_alv_tree->get_registered_events
IMPORTING events = lt_events.
(If you do not these events will be deregistered!!!).
You do not have to register events of the toolbar again.
*§4b. Frontend registration(ii): add additional event ids
l_event-eventid = cl_gui_column_tree=>eventid_node_double_click.
APPEND l_event TO lt_events.
*§4c. Frontend registration(iii):provide new event table to alv tree
CALL METHOD g_alv_tree->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.
*§4d. Register events on backend (ABAP Objects event handling)
CREATE OBJECT l_event_receiver.
SET HANDLER l_event_receiver->handle_node_double_click FOR g_alv_tree
ENDFORM. " register_events
*& Form create_hierarchy
text
--> p1 text
<-- p2 text
FORM create_hierarchy.
See BCALV_TREE_01 for more comments on building the hierarchy
DATA: ls_sflight TYPE sflight,
lt_sflight TYPE sflight OCCURS 0,
l_yyyymm(6) TYPE c, "year and month of sflight-fldate
l_yyyymm_last(6) TYPE c,
l_carrid LIKE sflight-carrid,
l_carrid_last LIKE sflight-carrid.
DATA: l_month_key TYPE lvc_nkey,
l_carrid_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey,
l_top_key TYPE lvc_nkey.
Select data
SELECT * FROM sflight INTO TABLE lt_sflight UP TO g_max ROWS.
sort table according to conceived hierarchy
SORT lt_sflight BY fldate0(6) carrid fldate6(2).
CLEAR : it_node_key, wa_node_key.
* wa_node_key = '&VIRTUALROOT'.
APPEND wa_node_key TO it_node_key.</b>
Define one top node. In this way it is possible to calculate
values for the whole hierarchy.
CALL METHOD g_alv_tree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = text-050
IMPORTING
e_new_node_key = l_top_key.
wa_node_key = l_top_key.
APPEND wa_node_key TO it_node_key.
LOOP AT lt_sflight INTO ls_sflight.
l_yyyymm = ls_sflight-fldate+0(6).
l_carrid = ls_sflight-carrid.
IF l_yyyymm <> l_yyyymm_last. "on change of l_yyyymm
l_yyyymm_last = l_yyyymm.
month nodes
PERFORM add_month USING l_yyyymm
l_top_key
CHANGING l_month_key.
clear l_carrid_last because this is a new month
CLEAR l_carrid_last.
wa_node_key = l_month_key.
APPEND wa_node_key TO it_node_key.
ENDIF.
Carrier nodes:
IF l_carrid <> l_carrid_last. "on change of l_carrid
l_carrid_last = l_carrid.
PERFORM add_carrid_line USING ls_sflight
l_month_key
CHANGING l_carrid_key.
wa_node_key = l_carrid_key.
APPEND wa_node_key TO it_node_key.
ENDIF.
Leaf:
PERFORM add_complete_line USING ls_sflight
l_carrid_key
CHANGING l_last_key.
* wa_node_key = l_last_key.
APPEND wa_node_key TO it_node_key.</b>
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form add_month
FORM add_month USING p_yyyymm TYPE c
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight,
l_month(15) TYPE c. "output string for month
get month name for node text
PERFORM get_month USING p_yyyymm
CHANGING l_month.
l_node_text = l_month.
add node
CALL METHOD g_alv_tree->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 = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_month
FORM add_carrid_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value,
ls_sflight TYPE sflight.
add node
l_node_text = ps_sflight-carrid.
CALL METHOD g_alv_tree->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 = ls_sflight
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_carrid_line
*& Form add_complete_line
FORM add_complete_line USING ps_sflight TYPE sflight
p_relat_key TYPE lvc_nkey
CHANGING p_node_key TYPE lvc_nkey.
DATA: l_node_text TYPE lvc_value.
WRITE ps_sflight-fldate TO l_node_text MM/DD/YYYY.
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 = ps_sflight
i_node_text = l_node_text
IMPORTING
e_new_node_key = p_node_key.
ENDFORM. " add_complete_line
*& Form GET_MONTH
text
-->P_P_YYYYMM text
<--P_L_MONTH text
FORM get_month USING p_yyyymm
CHANGING p_month.
DATA: l_monthdigits(2) TYPE c.
l_monthdigits = p_yyyymm+4(2).
CASE l_monthdigits.
WHEN '01'.
p_month = 'January'(701).
WHEN '02'.
p_month = 'February'(702).
WHEN '03'.
p_month = 'March'(703).
WHEN '04'.
p_month = 'April'(704).
WHEN '05'.
p_month = 'May'(705).
WHEN '06'.
p_month = 'June'(706).
WHEN '07'.
p_month = 'July'(707).
WHEN '08'.
p_month = 'August'(708).
WHEN '09'.
p_month = 'September'(709).
WHEN '10'.
p_month = 'October'(710).
WHEN '11'.
p_month = 'November'(711).
WHEN '12'.
p_month = 'December'(712).
ENDCASE.
CONCATENATE p_yyyymm+0(4) '->' p_month INTO p_month.
ENDFORM. " GET_MONTH -
About ALV tree model transaction
Hi Every One..
I got a requirement that we need to display some transactions in alv tree model. and if we click on that transaction then it should display that transaction in next half of custom container (like se80 transaction) .
Please help me out, it's urgent..
Thanks & Regards,
NagalakshmiHi Nagalakshmi,
Check these sample codes:
BCALV_TREE_SIMPLE_DEMO
BCALV_TREE_DEMO
BCALV_GRID_DEMO
BCALV_FULLSCREEN_DEMO_CLASSIC
BCALV_FULLSCREEN_DEMO
BCALV_DEMO_HTML
BC_ALV_DEMO_HTML_D0100
BCALV_TREE_SIMPLE_DEMO
Reward If Useful.
Regards,
Chitra -
How to alter the alv tree node text?
hi
i want to alter the alv tree node text, many people say it cann't be changed, but
i look into the sample code 'BCALV_TREE_04', the average funtion(select a column and then select average function in the tool bar) can alter the tree node text dynamically.
i try to look into the source code, the it's the sap standard code, all the funtions that user input, it goes to the statement " CALL METHOD cl_gui_cfw=>dispatch.", and i don't understand what this statement do, can someone helps me?hi
good
The ALV tree report produces uses OBJECT METHOD functionality in-order to produce a
tree structured ALV output.
The creation of an ALVtree report first requires the creation of a simple program to build the ALV
details such as the fieldcatalog and to call a screen which will be used to display the ALVTree.
The screen should be created with a 'custom control' where you wish the ALVtree report to appear.
For the following example it will have the name 'SCREEN_CONTAINER'.
http://www.sapdevelopment.co.uk/reporting/alv/alvtree%5Calvtree_basic.htm
reward point if helpful.
thanks
mrutyun^
Maybe you are looking for
-
Does Fireworks CS3 on Mac produce larger file sizes?
I have some png's originally created on a windows version that export in the 6-8k range but on the Mac I can't get them below 15! Whats the deal?
-
Upgrading to iTunes 8.2.1
I was prompted to upgrade to the latest version of iTunes 8.2.1. I went forward with the upgrade, but when I tried to launch iTunes I received a Microsoft Windows pop up screen that states 'iTunes has stopped working - A problem has caused the progra
-
Events while creation of z-table?
Hi All, Could any one explain me the importance of events when we are creating a z-table? how can we create and what is its purpose? Thanks in advance. Abhilash.
-
Upgrade from Mac OS X 10.9.5 to 10.10 only
Hi, I want to upgrade from Mac OS X 10.9.5 to 10.10 only. Is there a way of doing this without upgrading directly 10.10.2? Thanks for your help.
-
Ipad-to-itunes transfer hosed during OS update
I purchased a tv season directly to the ipad. the next time I synched to itunes I got a notification of an OS update - which I naturally selected "yes" to. Sometime later i noticed my pc was locked up and i had to reboot. The ipad restore worked grea