Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV Tree

Former Member
0 Kudos

Hi,

I have created a ALV tree program using OO-ABAP. I want to make few fields in the Tree as editable.

I went thru the demo program BCALV_TREE_ITEMLAYOUT. Here it has option to change each field to Text,Checkbox,Button. Everything works except for Textbox.

Can anyone pls help me out to make columns as editable.

Is it possible in ALV tree.

Pls help

Thanks

2 REPLIES 2

Former Member
0 Kudos

Hi,

Please see following code it may use full ur requirement.....

if it is use full answer please reward me a points.....

REPORT ztree_container .

CLASS lcl_application DEFINITION DEFERRED.

CLASS cl_gui_cfw DEFINITION LOAD.

  • CAUTION: MTREEITM is the name of the item structure which must

  • be defined by the programmer. DO NOT USE MTREEITM!

TYPES: item_table_type LIKE STANDARD TABLE OF mtreeitm

WITH DEFAULT KEY.

DATA: g_application TYPE REF TO lcl_application,

g_custom_container TYPE REF TO cl_gui_custom_container,

g_tree TYPE REF TO cl_gui_list_tree,

g_ok_code TYPE sy-ucomm.

  • Fields on Dynpro 100

DATA: g_event(30),

g_node_key TYPE tv_nodekey,

g_item_name TYPE tv_itmname.

*START-OF-SELECTION.

*

----


  • CLASS LCL_APPLICATION DEFINITION

----


  • ........ *

----


CLASS lcl_application DEFINITION.

PUBLIC SECTION.

METHODS:

handle_node_double_click

FOR EVENT node_double_click

OF cl_gui_list_tree

IMPORTING node_key,

handle_expand_no_children

FOR EVENT expand_no_children

OF cl_gui_list_tree

IMPORTING node_key,

handle_item_double_click

FOR EVENT item_double_click

OF cl_gui_list_tree

IMPORTING node_key item_name,

handle_button_click

FOR EVENT button_click

OF cl_gui_list_tree

IMPORTING node_key item_name,

handle_link_click

FOR EVENT link_click

OF cl_gui_list_tree

IMPORTING node_key item_name,

handle_checkbox_change

FOR EVENT checkbox_change

OF cl_gui_list_tree

IMPORTING node_key item_name checked.

ENDCLASS.

----


  • CLASS LCL_APPLICATION IMPLEMENTATION

----


  • ........ *

----


CLASS lcl_application IMPLEMENTATION.

METHOD handle_node_double_click.

" this method handles the node double click event of the tree

" control instance

" show the key of the double clicked node in a dynpro field

g_event = 'NODE_DOUBLE_CLICK'.

g_node_key = node_key.

ENDMETHOD.

METHOD handle_item_double_click.

" this method handles the item double click event of the tree

" control instance

" show the key of the node and the name of the item

" of the double clicked item in a dynpro field

g_event = 'ITEM_DOUBLE_CLICK'.

g_node_key = node_key.

g_item_name = item_name.

ENDMETHOD.

METHOD handle_link_click.

" this method handles the link click event of the tree

" control instance

" show the key of the node and the name of the item

" of the clicked link in a dynpro field

g_event = 'LINK_CLICK'.

g_node_key = node_key.

g_item_name = item_name.

ENDMETHOD.

METHOD handle_button_click.

" this method handles the button click event of the tree

" control instance

" show the key of the node and the name of the item

" of the clicked button in a dynpro field

g_event = 'BUTTON_CLICK'.

g_node_key = node_key.

g_item_name = item_name.

ENDMETHOD.

METHOD handle_checkbox_change.

" this method handles the checkbox_change event of the tree

" control instance

" show the key of the node and the name of the item

" of the clicked checkbox in a dynpro field

g_event = 'CHECKBOX_CHANGE'.

g_node_key = node_key.

g_item_name = item_name.

ENDMETHOD.

METHOD handle_expand_no_children.

DATA: node_table TYPE treev_ntab,

node TYPE treev_node,

item_table TYPE item_table_type,

item TYPE mtreeitm.

  • show the key of the expanded node in a dynpro field

g_event = 'EXPAND_NO_CHILDREN'.

g_node_key = node_key.

IF node_key = 'Child2'. "#EC NOTEXT

  • add the children for node with key 'Child2'

  • Node with key 'New3'

CLEAR node.

node-node_key = 'New3'. "#EC NOTEXT

node-relatkey = 'Child2'.

node-relatship = cl_gui_list_tree=>relat_last_child.

APPEND node TO node_table.

  • Node with key 'New4'

CLEAR node.

node-node_key = 'New4'. "#EC NOTEXT

node-relatkey = 'Child2'.

node-relatship = cl_gui_list_tree=>relat_last_child.

APPEND node TO node_table.

  • Items of node with key 'New3'

CLEAR item.

item-node_key = 'New3'.

item-item_name = '1'.

item-class = cl_gui_list_tree=>item_class_text.

item-length = 11.

item-usebgcolor = 'X'. "

item-text = 'SAPTROX1'.

APPEND item TO item_table.

CLEAR item.

item-node_key = 'New3'.

item-item_name = '2'.

item-class = cl_gui_list_tree=>item_class_text.

item-alignment = cl_gui_list_tree=>align_auto.

item-font = cl_gui_list_tree=>item_font_prop.

item-text = 'Comment to SAPTROX1'. "#EC NOTEXT

APPEND item TO item_table.

  • Items of node with key 'New4'

CLEAR item.

item-node_key = 'New4'.

item-item_name = '1'.

item-class = cl_gui_list_tree=>item_class_text.

item-length = 11.

item-usebgcolor = 'X'. "

item-text = 'SAPTRIXTROX'.

APPEND item TO item_table.

CLEAR item.

item-node_key = 'New4'.

item-item_name = '2'.

item-class = cl_gui_list_tree=>item_class_text.

item-alignment = cl_gui_list_tree=>align_auto.

item-font = cl_gui_list_tree=>item_font_prop.

item-text = 'Comment to SAPTRIXTROX'. "#EC NOTEXT

APPEND item TO item_table.

ENDIF.

CALL METHOD g_tree->add_nodes_and_items

EXPORTING

node_table = node_table

item_table = item_table

item_table_structure_name = 'MTREEITM'

EXCEPTIONS

failed = 1

cntl_system_error = 3

error_in_tables = 4

dp_error = 5

table_structure_name_not_found = 6.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

ENDMETHOD.

ENDCLASS.

&----


*& Module STATUS_9000 OUTPUT

&----


  • text

----


MODULE status_9000 OUTPUT.

SET PF-STATUS '9000'.

  • SET TITLEBAR 'xxx'.

IF g_tree IS INITIAL.

" The Tree Control has not been created yet.

" Create a Tree Control and insert nodes into it.

PERFORM create_and_init_tree.

ENDIF.

*ENDMODULE.

ENDMODULE. " STATUS_9000 OUTPUT

&----


*& Form CREATE_AND_INIT_TREE

&----


  • text

----


FORM create_and_init_tree.

DATA: node_table TYPE treev_ntab,

item_table TYPE item_table_type,

events TYPE cntl_simple_events,

event TYPE cntl_simple_event.

  • create a container for the tree control

CREATE OBJECT g_custom_container

EXPORTING

" the container is linked to the custom control with the

" name 'TREE_CONTAINER' on the dynpro

container_name = 'TREE_CONTAINER'

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

create_error = 3

lifetime_error = 4

lifetime_dynpro_dynpro_link = 5.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

  • create a list tree control

CREATE OBJECT g_tree

EXPORTING

parent = g_custom_container

node_selection_mode = cl_gui_list_tree=>node_sel_mode_single

item_selection = 'X'

with_headers = ' '

EXCEPTIONS

cntl_system_error = 1

create_error = 2

failed = 3

illegal_node_selection_mode = 4

lifetime_error = 5.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

  • define the events which will be passed to the backend

" node double click

event-eventid = cl_gui_list_tree=>eventid_node_double_click.

event-appl_event = 'X'. "

APPEND event TO events.

" item double click

event-eventid = cl_gui_list_tree=>eventid_item_double_click.

event-appl_event = 'X'.

APPEND event TO events.

" expand no children

event-eventid = cl_gui_list_tree=>eventid_expand_no_children.

event-appl_event = 'X'.

APPEND event TO events.

" link click

event-eventid = cl_gui_list_tree=>eventid_link_click.

event-appl_event = 'X'.

APPEND event TO events.

" button click

event-eventid = cl_gui_list_tree=>eventid_button_click.

event-appl_event = 'X'.

APPEND event TO events.

" checkbox change

event-eventid = cl_gui_list_tree=>eventid_checkbox_change.

event-appl_event = 'X'.

APPEND event TO events.

CALL METHOD g_tree->set_registered_events

EXPORTING

events = events

EXCEPTIONS

cntl_error = 1

cntl_system_error = 2

illegal_event_combination = 3.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

  • assign event handlers in the application class to each desired event

SET HANDLER g_application->handle_node_double_click FOR g_tree.

SET HANDLER g_application->handle_item_double_click FOR g_tree.

SET HANDLER g_application->handle_expand_no_children FOR g_tree.

SET HANDLER g_application->handle_link_click FOR g_tree.

SET HANDLER g_application->handle_button_click FOR g_tree.

SET HANDLER g_application->handle_checkbox_change FOR g_tree.

  • add some nodes to the tree control

  • NOTE: the tree control does not store data at the backend. If an

  • application wants to access tree data later, it must store the

  • tree data itself.

PERFORM build_node_and_item_table USING node_table item_table.

CALL METHOD g_tree->add_nodes_and_items

EXPORTING

node_table = node_table

item_table = item_table

item_table_structure_name = 'MTREEITM'

EXCEPTIONS

failed = 1

cntl_system_error = 3

error_in_tables = 4

dp_error = 5

table_structure_name_not_found = 6.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

ENDFORM. " CREATE_AND_INIT_TREE

&----


*& Module PAI_100 INPUT

&----


  • text

----


&----


*& Form build_node_and_item_table

&----


  • text

----


  • -->P_NODE_TABLE text

  • -->P_ITEM_TABLE text

----


FORM BUILD_NODE_AND_ITEM_TABLE

USING

NODE_TABLE TYPE TREEV_NTAB

ITEM_TABLE TYPE ITEM_TABLE_TYPE.

DATA: NODE TYPE TREEV_NODE,

ITEM TYPE MTREEITM.

  • Build the node table.

  • Caution: The nodes are inserted into the tree according to the order

  • in which they occur in the table. In consequence, a node must not

  • must not occur in the node table before its parent node.

  • Node with key 'Root'

NODE-NODE_KEY = 'Root'. "#EC NOTEXT

" Key of the node

CLEAR NODE-RELATKEY. " Special case: A root node has no parent

CLEAR NODE-RELATSHIP. " node.

NODE-HIDDEN = ' '. " The node is visible,

NODE-DISABLED = ' '. " selectable,

NODE-ISFOLDER = 'X'. " a folder.

CLEAR NODE-N_IMAGE. " Folder-/ Leaf-Symbol in state "closed":

" use default.

CLEAR NODE-EXP_IMAGE. " Folder-/ Leaf-Symbol in state "open":

" use default

CLEAR NODE-EXPANDER. " see below.

" the width of the item is adjusted to its content (text)

APPEND NODE TO NODE_TABLE.

  • Node with key 'Child1'

CLEAR NODE.

NODE-NODE_KEY = 'Child1'. "#EC NOTEXT

" Key of the node

" Node is inserted as child of the node with key 'Root'.

NODE-RELATKEY = 'Root'.

NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.

NODE-ISFOLDER = 'X'.

APPEND NODE TO NODE_TABLE.

  • Node with key 'New1'

CLEAR NODE.

NODE-NODE_KEY = 'New1'. "#EC NOTEXT

NODE-RELATKEY = 'Child1'.

NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.

APPEND NODE TO NODE_TABLE.

  • Node with key 'New2'

CLEAR NODE.

NODE-NODE_KEY = 'New2'. "#EC NOTEXT

NODE-RELATKEY = 'Child1'.

NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.

APPEND NODE TO NODE_TABLE.

  • Node with key 'Child2'

CLEAR NODE.

NODE-NODE_KEY = 'Child2'. "#EC NOTEXT

NODE-RELATKEY = 'Root'.

NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.

NODE-ISFOLDER = 'X'.

NODE-EXPANDER = 'X'. " The node is marked with a '+', although

" it has no children. When the user clicks on the

" + to open the node, the event expand_nc is

" fired. The programmerr can

" add the children of the

" node within the event handler of the expand_nc

" event (see callback handle_expand_nc).

APPEND NODE TO NODE_TABLE.

  • The items of the nodes:

  • Node with key 'Root'

CLEAR ITEM.

ITEM-NODE_KEY = 'Root'.

ITEM-ITEM_NAME = '1'. " Item with name '1'

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT. " Text Item

" the with of the item is adjusted to its content (text)

ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

" use proportional font for the item

ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

ITEM-TEXT = 'Objekte'. "#EC NOTEXT

APPEND ITEM TO ITEM_TABLE.

  • Node with key 'Child1'

CLEAR ITEM.

ITEM-NODE_KEY = 'Child1'.

ITEM-ITEM_NAME = '1'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

ITEM-TEXT = 'Dynpros'. "#EC NOTEXT

APPEND ITEM TO ITEM_TABLE.

  • Node with key 'Child2'

CLEAR ITEM.

ITEM-NODE_KEY = 'Child2'.

ITEM-ITEM_NAME = '1'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

ITEM-TEXT = 'Programme'. "#EC NOTEXT

APPEND ITEM TO ITEM_TABLE.

  • Items of node with key 'New1'

CLEAR ITEM.

ITEM-NODE_KEY = 'New1'.

ITEM-ITEM_NAME = '1'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 4. " the width of the item is 4 characters

ITEM-IGNOREIMAG = 'X'. " see documentation of Structure

" TREEV_ITEM

ITEM-USEBGCOLOR = 'X'. " item has light grey background

ITEM-T_IMAGE = '@01@'. " icon of the item

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New1'.

ITEM-ITEM_NAME = '2'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 4.

ITEM-USEBGCOLOR = 'X'.

ITEM-TEXT = '0100'.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New1'.

ITEM-ITEM_NAME = '3'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 11.

ITEM-USEBGCOLOR = 'X'. "

ITEM-TEXT = 'MUELLER'.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New1'.

ITEM-ITEM_NAME = '4'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

ITEM-TEXT = 'Comment to Dynpro 100'. "#EC NOTEXT

APPEND ITEM TO ITEM_TABLE.

  • Items of node with key 'New2'

CLEAR ITEM.

ITEM-NODE_KEY = 'New2'.

ITEM-ITEM_NAME = '1'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 4. " the width of the item is 2 characters

ITEM-IGNOREIMAG = 'X'. " see documentation of Structure

" TREEV_ITEM

ITEM-USEBGCOLOR = 'X'. " item has light grey background

ITEM-T_IMAGE = '@02@'. " icon of the item

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New2'.

ITEM-ITEM_NAME = '2'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 4.

ITEM-USEBGCOLOR = 'X'.

ITEM-TEXT = '0200'.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New2'.

ITEM-ITEM_NAME = '3'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-LENGTH = 11.

ITEM-USEBGCOLOR = 'X'. "

ITEM-TEXT = 'HARRYHIRSCH'.

APPEND ITEM TO ITEM_TABLE.

CLEAR ITEM.

ITEM-NODE_KEY = 'New2'.

ITEM-ITEM_NAME = '4'.

ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.

ITEM-ALIGNMENT = CL_GUI_LIST_TREE=>ALIGN_AUTO.

ITEM-FONT = CL_GUI_LIST_TREE=>ITEM_FONT_PROP.

ITEM-TEXT = 'Comment to Dynpro 200'. "#EC NOTEXT

APPEND ITEM TO ITEM_TABLE.

endform. " build_node_and_item_table

&----


*& Module pai_9000 INPUT

&----


  • text

----


module pai_9000 input.

dATA: return_code TYPE i.

  • CL_GUI_CFW=>DISPATCH must be called if events are registered

  • that trigger PAI

  • this method calls the event handler method of an event

CALL METHOD cl_gui_cfw=>dispatch

IMPORTING return_code = return_code.

IF return_code <> cl_gui_cfw=>rc_noevent.

" a control event occured => exit PAI

CLEAR g_ok_code.

EXIT.

ENDIF.

CASE g_ok_code.

WHEN 'BACK'. " Finish program

IF NOT g_custom_container IS INITIAL.

" destroy tree container (detroys contained tree control, too)

CALL METHOD g_custom_container->free

EXCEPTIONS

cntl_system_error = 1

cntl_error = 2.

IF sy-subrc <> 0.

  • MESSAGE a000.

ENDIF.

CLEAR g_custom_container.

CLEAR g_tree.

ENDIF.

LEAVE PROGRAM.

ENDCASE.

  • CAUTION: clear ok code!

CLEAR g_ok_code.

endmodule. " pai_9000 INPUT

CREATE OBJECT g_application.

SET SCREEN 9000.

if it is use full answer please reward me a points.....

regards ,

praveen

0 Kudos

Hey,

Thanks for reply.

But this code doesn't help for Editing fields in Tree