Unable to expand child links in ALV Tree
Hi,
I have written the following code for ALV Tree using function modules.
REPORT ZSID_ALV_TREE.
type pool declarations for tree
TYPE-POOLS : fibs,stree.
tables: ekko.
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,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
it_ekpo TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
it_emptytab TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko,
wa_ekpo TYPE t_ekko.
DATA:w_repid type sy-cprog.
*Data declaration for additional node information
DATA : t_node TYPE snodetext.
*Internal table and wa decl for nodes
DATA : it_node LIKE TABLE OF t_node INITIAL SIZE 0,
wa_node LIKE t_node.
*Start of selection event
START-OF-SELECTION.
*Select the data for tree
PERFORM fetch_data.
*Build the hierarchy for tree
PERFORM build_hierarchy.
*Build Tree for display
PERFORM build_tree.
*& Form fetch_data
text
--> p1 text
<-- p2 text
FORM fetch_data .
SELECT ebeln
up to 10 rows
FROM ekko
INTO corresponding fields of TABLE it_ekko .
loop at it_ekko into wa_ekko.
SELECT ebeln ebelp statu aedat matnr menge meins netpr peinh
FROM ekpo
appending TABLE it_ekpo
where ebeln eq wa_ekko-ebeln.
endloop.
endform.
*& Form build_hierarchy
text
--> p1 text
<-- p2 text
FORM build_hierarchy .
*Building the nodes and hierarchy for tree
CLEAR : it_node[], wa_node.
wa_node-type = 'T'.
wa_node-name = 'Product Hierarchy Level'.
wa_node-tlevel = '01'.
wa_node-nlength = '35'.
wa_node-color = '4'.
wa_node-text = 'Test'.
wa_node-tlength ='20'.
wa_node-tcolor = 3.
APPEND wa_node TO it_node.
CLEAR wa_node.
loop at it_ekpo into wa_ekpo.
wa_node-type = 'P'.
wa_node-name = 'Purchasing Doc'.
wa_node-tlevel = '02'.
wa_node-nlength = '25'.
wa_node-color = '4'.
wa_node-text = wa_ekpo-ebeln.
wa_node-tlength ='20'.
wa_node-tcolor = 3.
APPEND wa_node TO it_node.
CLEAR wa_node.
*Filling the values of internal table into tree
wa_node-type = 'P'.
wa_node-name = 'Material No'.
wa_node-tlevel = '03'.
wa_node-nlength = '20'.
wa_node-color = '1'.
wa_node-text = wa_ekpo-matnr.
wa_node-tlength ='20'.
wa_node-tcolor = 4.
APPEND wa_node TO it_node.
CLEAR wa_node.
ENDLOOP.
ENDFORM. " build_hierarchy
*& Form build_tree
text
--> p1 text
<-- p2 text
FORM build_tree .
*Fm for constructing the tree
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
nodetab = it_node.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
w_repid = SY-CPROG.
*FM for displaying the tree
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = w_repid
CALLBACK_USER_COMMAND = 'USER1_COMMAND'
CALLBACK_TEXT_DISPLAY =
CALLBACK_MOREINFO_DISPLAY =
CALLBACK_COLOR_DISPLAY =
CALLBACK_TOP_OF_PAGE =
CALLBACK_GUI_STATUS =
CALLBACK_CONTEXT_MENU =
STATUS = 'IMPLICIT'
CHECK_DUPLICATE_NAME = '0'
COLOR_OF_NODE = '4'
COLOR_OF_MARK = '3'
COLOR_OF_LINK = '1'
COLOR_OF_MATCH = '5'
LOWER_CASE_SENSITIVE = 'X'
MODIFICATION_LOG = 'X'
NODE_LENGTH = 40
TEXT_LENGTH = 75
TEXT_LENGTH1 = 0
TEXT_LENGTH2 = 0
RETURN_MARKED_SUBTREE = 'X'
SCREEN_START_COLUMN = 0
SCREEN_START_LINE = 0
SCREEN_END_COLUMN = 0
SCREEN_END_LINE = 0
SUPPRESS_NODE_OUTPUT = 'X'
LAYOUT_MODE = ' '
USE_CONTROL = 'L'.
IMPORTING
F15 =
ENDFORM. " build_tree
FORM USER1_COMMAND TABLES node STRUCTURE seucomm
USING command
CHANGING value(exit)
VALUE(LIST_REFRESH).
write 'Hi'.
endform.
But I have a problem
1. I can expand the child links in tree structure when I comment the exporting parameter CALLBACK_USER_COMMAND in the function Module 'RS_TREE_LIST_DISPLAY'.
2 But when i uncomment the exporting parameter I am unable to expand the child links in output.
Please let me know if i have missed something in the code.
Useful answers will be rewarded
Regards,
Siddharth
Hi Sidhhart,
Check out this prog.
REPORT Z_KULDEEP_ALV_HIERARCHY
message-id zord
line-size 270.
Tables:
Vbap,
Vbak.
*& PROGRAM VARIABLES
type-pools slis.
*& INTERNAL TABLES & STRUCTURES
data:
begin of t_header occurs 0,
EXPCOL type c,
vbeln type vbak-vbeln,
audat type vbak-audat,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
end of t_header,
begin of t_item occurs 0,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
arktx type vbap-arktx,
pstyv type vbap-pstyv,
end of t_item,
t_fieldcat type standard table of slis_fieldcat_alv with header line,
t_event type standard table of slis_alv_event with header line,
x_keyinfo type slis_keyinfo_alv,
x_layout type slis_layout_alv,
x_variant like disvariant.
*& GLOBAL VARIABLES
data:
g_repid type sy-repid,
g_formname type slis_formname value 'TOP_OF_PAGE'.
*& SELECTION SCREEN *
selection-screen begin of block a with frame title text-000.
Select-options : s_date for vbak-audat obligatory.
p_date type vbak-audat.
selection-screen end of block a.
*& INITIALIZATION *
initialization.
clear : g_repid,t_header,t_item.
refresh : t_header,t_item.
g_repid = sy-repid.
*& AT SELECTION-SCREEN *
at selection-screen.
if s_date-high > sy-datum.
message e001.
endif.
start-of-selection.
select vbeln audat vkorg vtweg spart from vbak
into corresponding fields of table t_header
where audat in s_date.
select vbeln posnr matnr arktx pstyv from vbap
into table t_item
for all entries in t_header
where vbeln = t_header-vbeln.
end-of-selection.
perform sub_display_alv.
*& Form sub_display_alv
text
--> p1 text
<-- p2 text
form sub_display_alv.
*column 1
perform sub_populate_fieldcatalog using:
'VBELN' " field name
'T_HEADER' " table name
'ORDER' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 2
perform sub_populate_fieldcatalog using:
'AUDAT' " field name
'T_HEADER' " table name
'ORDERDATE' " column heading
'10' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 3
perform sub_populate_fieldcatalog using:
'VKORG' " field name
'T_HEADER' " table name
'SALES ORG' " column heading
'6' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 4
perform sub_populate_fieldcatalog using:
'VTWEG' " field name
'T_HEADER' " table name
'DIVISION' " column heading
'2' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 5
perform sub_populate_fieldcatalog using:
'SPART' " field name
'T_HEADER' " table name
'CHANNEL' " column heading
'4' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 6
perform sub_populate_fieldcatalog using:
'vbeln' " field name
'T_item' " table name
'Order' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 7
perform sub_populate_fieldcatalog using:
'POSNR' " field name
'T_ITEM' " table name
'SALES DOC.ITEM' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 8
perform sub_populate_fieldcatalog using:
'MATNR' " field name
'T_ITEM' " table name
'MATERIAL' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 9
perform sub_populate_fieldcatalog using:
'ARKTX' " field name
'T_ITEM' " table name
'SALES ORDER ITEM' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
*column 10
perform sub_populate_fieldcatalog using:
'PSTYV' " field name
'T_ITEM' " table name
'ITEM CATEGORY' " column heading
'8' " column width
' ' " fix column?
' ' " key
' ' " no display
' ' " sum this column
'X' " do not sum
' ' " input allowed?
' ' " currenct type field name
' ' " data type
'X'. " hotspot.
perform sub_assign_events.
Create a Layout for the ALV
perform sub_layout.
Define the key fields that links the header & item tables
perform sub_define_key.
dispaly list
perform sub_call_list_display.
endform. " sub_display_alv
*& Form sub_populate_fieldcatalog
text
-->P_G_FIELDCAT text
-->P_0198 text
-->P_0199 text
-->P_0200 text
-->P_0201 text
-->P_0202 text
-->P_0203 text
-->P_0204 text
-->P_0205 text
-->P_0206 text
-->P_0207 text
-->P_0208 text
-->P_0209 text
-->P_0210 text
-->P_0211 text
-->P_0212 text
-->P_0213 text
form sub_populate_fieldcatalog using
l_fieldname
l_tabname
l_column_heading
l_outputlen
l_fix_column
l_key
l_no_out
l_do_sum
l_no_sum
l_input
l_cfieldname
l_datatype
l_hotspot.
t_fieldcat-fieldname = l_fieldname.
t_fieldcat-tabname = l_tabname.
t_fieldcat-reptext_ddic = l_column_heading.
t_fieldcat-outputlen = l_outputlen.
t_fieldcat-fix_column = l_fix_column.
t_fieldcat-key = l_key.
t_fieldcat-no_out = l_no_out.
t_fieldcat-do_sum = l_do_sum.
t_fieldcat-no_sum = l_no_sum.
t_fieldcat-cfieldname = l_cfieldname.
t_fieldcat-datatype = l_datatype.
t_fieldcat-hotspot = l_hotspot.
append t_fieldcat.clear t_fieldcat.
endform. " sub_populate_fieldcatalog
*& Form sub_assign_events
text
--> p1 text
<-- p2 text
form sub_assign_events.
refresh t_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 1
importing
et_events = t_event[]
exceptions
list_type_wrong = 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.
Read the record for the top-of-page event
read table t_event with key slis_ev_top_of_page.
if sy-subrc = 0.
t_event-form = g_formname.
append t_event.
endif.
endform. " sub_assign_events
*& Form SUB_LAYOUT
text
--> p1 text
<-- p2 text
form sub_layout.
clear x_layout.
x_layout-f2code = 'QUOTE'.
x_layout-zebra = 'X'.
x_layout-expand_fieldname = 'EXPCOL'. " Field for expand/collapse
*Stat
x_layout-colwidth_optimize = 'X'.
x_layout-no_totalline = 'X'. " 0001+
endform. " SUB_LAYOUT
*& Form SUB_DEFINE_KEY
text
--> p1 text
<-- p2 text
form sub_define_key.
clear x_keyinfo.
x_keyinfo-header01 = 'VBELN'.
x_keyinfo-item01 = 'VBELN'.
endform. " SUB_DEFINE_KEY
form top_of_page.
write :/10 sy-datum, 20 sy-pagno, 30 sy-uname.
endform.
form sub_user_command using f_ucomm like sy-ucomm
f_selfield type slis_selfield.
if f_ucomm = 'QUOTE'.
if f_selfield-fieldname = 'VBELN'.
Set Parameter id 'AUN' field f_selfield-value.
call transaction 'VA03'.
endif.
endif.
endform.
*& Form sub_call_list_display
text
--> p1 text
<-- p2 text
form sub_call_list_display.
call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
exporting
i_callback_program = g_repid
i_callback_user_command = 'SUB_USER_COMMAND '
is_layout = x_layout
it_fieldcat = t_fieldcat[]
i_save = 'A'
it_events = t_event[]
i_tabname_header = 'T_HEADER'
i_tabname_item = 'T_ITEM'
is_keyinfo = x_keyinfo
tables
t_outtab_header = t_header[]
t_outtab_item = t_item[]
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. " sub_call_list_display
Similar Messages
-
Hi folks,
I've done a report with an ALV TREE (CL_GUI_ALV_TREE) and I want to get on the first node the totals of its children.
I have used the method UPDATE_CALCULATIONS and FRONT_END_UPDATE, everything it's ok when displaying the values, but when
I try to get top node's calculated values by using the GET_OUTTAB_LINE method I get old values instead of updated ones.
How can I get calculated values?
Thnx in advance.refer this link
Re: alv tree
Class CL_GUI_ALV_TREE has two methods for refreshing the display:
- FRONTEND_UPDATE (Sends Changed/Inserted Nodes to Control)
- UPDATE_CALCULATIONS (Recalculate Columns)
The second methods implicitly calls method FRONTEND_UPDATE except if you suppress it using parameter NO_FRONTEND_UPDATE = 'X'. -
Unable to expand tree in safari 5.1.7 for windows
Hi,
I am using Safari v5.1.7 in Windows OS. There is a left navigational panel with tree structure in web content page. When I open web content in safari 5.1.7, I am unable to expand the tree. This happening with the pages which are carrying huge data. For the normal pages, I could able to expand the children of the tree.
Please anyone help on this.Above issue is an urgent issue. Any help would be appreciated. Thanks
-
How to expand a Root-Element in ALV-Tree?
Hi,
i use ALV-Tree and try to expand the first hierarchie.
I try this:
TRY.
GR_TREE_NODE = GR_TREE_NODES->ADD_NODE(
RELATED_NODE = ROOT_KEY
*EXPANDER = ABAP_TRUE*
RELATIONSHIP = CL_GUI_COLUMN_TREE=>RELAT_FIRST_CHILD
TEXT = 'Meldungen').
CATCH CX_SALV_MSG.
ENDTRY.
but this element will not be expandet?
I know this for expand all: CALL METHOD GR_TREE_NODES->EXPAND_ALL.
but want to expand only the first hierarch-elemet (root).
Can anyone tell me what i'm doing wrong?
Thanks.
Regards, DieterHi,
solved by this:
GR_TREE_NODE->EXPAND( ).
Regards, Dieter -
Unable to expand Tree in EP (e.g. Portal Content)
Dear Portal Gurus,
We are on EP 6.0,SP12.
We are unable to expand any tree structure (including stanadard Tree Structure) inside EP.
I get the following message :
Could not load or refresh node Tree creation failed on node: pcd:portal_content .
Pls let me know what needs to be done.
Thx.when I exported a transport package I saved it on Portal conect and after doing all the transporting, when I opened the content administration and try to expand the portal content, I get the following error:
Could not load or refresh node Tree creation failed on node: pcdportal_content
<a href="http://ing.perez.googlepages.com/portal.jpg" target="_blank"><img src="http://ing.perez.googlepages.com/portal.jpg" border="0" /></a>
I get this error from the log
1.5#0011856BDDE1006D00000086000011B000042238FAC1E7DA#1163528027322#com.sap.portal.pcd.Gl.Notification.Engine#sap.com/irj#com.sap.portal.pcd.Gl.Notification.Engine#IENAFS02#197##091402wb79_EPD_2059550#IENAFS02#0a01e440740b11dba4e00011856bdde1#Thread[T-IMPORT-1114_121327_931_71801fdd2c1d2d9b,5,SAPEngine_Application_Thread[impl:3]_Group]##0#0#Error#1#/System/Server#Java###[XfsNotificationEngine.register] Exception occured:
[EXCEPTION]
{0}#1#PcdRuntimeException: SQLException is not transient, error code = 0, sql state = HY000
[SAP_NWMss][SQLServer JDBC Driver]IO Error creating temp file: null
com.sapportals.portal.pcd.pl.PlRuntimeException: SQLException is not transient, error code = 0, sql state = HY000
[SAP_NWMss][SQLServer JDBC Driver]IO Error creating temp file: null
at com.sapportals.portal.pcd.pl.PlFactory.handleUnexpectedSQLError(PlFactory.java:2428)
at com.sapportals.portal.pcd.pl.PlFactory.checkDeadlockResolution(PlFactory.java:2436)
at com.sapportals.portal.pcd.pl.PlContext.lookupSubtree(PlContext.java:280)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.<init>(XfsContext.java:128)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.<init>(XfsContext.java:85)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.getXfsChildFromPlChild(XfsContext.java:590)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.readXfsObjectFromPersistence(XfsContext.java:535)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.getChildAtomicName(XfsContext.java:433)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.getChild(XfsContext.java:277)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.getChild(XfsContext.java:280)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.getChild(XfsContext.java:280)
at com.sapportals.portal.pcd.gl.xfs.XfsContext.lookup(XfsContext.java:228)
at com.sapportals.portal.pcd.gl.xfs.notif.XfsNotificationEngine.triggerInformDanglingDeltalinks(XfsNotificationEngine.java:463)
at com.sapportals.portal.pcd.gl.xfs.notif.XfsNotificationEngine.register(XfsNotificationEngine.java:302)
at com.sapportals.portal.pcd.gl.transport.PcdGlTransportAdapter.endElement(PcdGlTransportAdapter.java:346)
at com.sapportals.portal.pcd.gl.xml.ContentHandlerManager.endElement(ContentHandlerManager.java:204)
at com.sapportals.portal.pcd.gl.xml.PcdXMLContentHandler.endElement(PcdXMLContentHandler.java:107)
at com.sap.engine.lib.xml.parser.handlers.SAXDocHandler.endElement(SAXDocHandler.java:154)
at com.sap.engine.lib.xml.parser.XMLParser.scanEndTag(XMLParser.java:1913)
at com.sap.engine.lib.xml.parser.XMLParser.scanElement(XMLParser.java:1809)
at com.sap.engine.lib.xml.parser.XMLParser.scanDocument(XMLParser.java:2792)
at com.sap.engine.lib.xml.parser.XMLParser.parse0(XMLParser.java:227)
at com.sap.engine.lib.xml.parser.AbstractXMLParser.parseAndCatchException(AbstractXMLParser.java:141)
at com.sap.engine.lib.xml.parser.AbstractXMLParser.parse(AbstractXMLParser.java:156)
at com.sap.engine.lib.xml.parser.AbstractXMLParser.parse(AbstractXMLParser.java:259)
at com.sap.engine.lib.xml.parser.Parser.parseWithoutSchemaValidationProcessing(Parser.java:278)
at com.sap.engine.lib.xml.parser.Parser.parse(Parser.java:340)
at com.sap.engine.lib.xml.parser.SAXParser.parse(SAXParser.java:125)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at com.sapportals.portal.pcd.gl.xml.PcdXMLParser.parse(PcdXMLParser.java:85)
at com.sapportals.portal.pcd.gl.xml.PcdXMLParser.parse(PcdXMLParser.java:54)
at com.sapportals.portal.pcd.gl.transport.PcdGlTransportManager.importObject(PcdGlTransportManager.java:612)
at com.sapportals.portal.transport.Transport.importObject(Transport.java:110)
at com.sapportals.portal.transport.app.ImportRunner.importObject(ImportRunner.java:322)
at com.sapportals.portal.transport.app.ImportRunner.run(ImportRunner.java:164)
at java.lang.Thread.run(Thread.java:534)
Caused by: java.sql.SQLException: [SAP_NWMss][SQLServer JDBC Driver]IO Error creating temp file: null
at com.sap.nwmss.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.sap.nwmss.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.sap.nwmss.jdbc.base.BaseImplClobEmulated.<init>(Unknown Source)
at com.sap.nwmss.jdbc.sqlserver.SQLServerImplResultSet.getData(Unknown Source)
at com.sap.nwmss.jdbc.base.BaseResultSet.getClob(Unknown Source)
at com.sap.sql.jdbc.basic.BasicResultSet.getClob(BasicResultSet.java:432)
at com.sap.sql.jdbc.direct.DirectResultSet.getClob(DirectResultSet.java:1060)
at com.sap.sql.jdbc.common.dispatch.ClobResultColumn.getClob(ClobResultColumn.java:138)
at com.sap.sql.jdbc.common.CommonResultSet.createClob(CommonResultSet.java:1035)
at com.sap.sql.jdbc.common.CommonResultSet.getClob(CommonResultSet.java:302)
at com.sap.sql.jdbc.common.dispatch.ClobResultColumn.dispatchGetString(ClobResultColumn.java:114)
at com.sap.sql.jdbc.common.CommonResultSet.getString(CommonResultSet.java:448)
at com.sapportals.portal.pcd.pl.AttributeHeadersTable.readStringValue(AttributeHeadersTable.java:934)
at com.sapportals.portal.pcd.pl.AttributeHeadersTable.readFirstValue(AttributeHeadersTable.java:657)
at com.sapportals.portal.pcd.pl.AttributeHeadersTable.readAttributeHeader(AttributeHeadersTable.java:639)
at com.sapportals.portal.pcd.pl.AttributeHeadersTable.selectSubtreeObjectsAttributeHeaders(AttributeHeadersTable.java:762)
at com.sapportals.portal.pcd.pl.PlFactory.getSubtreeSegment(PlFactory.java:878)
at com.sapportals.portal.pcd.pl.PlFactory.getSubtree(PlFactory.java:804)
at com.sapportals.portal.pcd.pl.PlContext.lookupSubtree(PlContext.java:253)
at com.sapportals.portal.pcd.pl.PlContext.lookupSubtree(PlContext.java:274)
... 33 more -
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 -
ALV Tree, Expanded node do not show data in certain column
Hi all,
I need your help regard to below problem.
I have an ALV grid in which one of the columns has F4 (search help). If search help is called by pressing a F4 button a dialog box will be shown with ALV tree on it.
The ALV Tree has 2 columns which are: hierarchy column and one other column called WBS column. At the first show, all expanded node show data contained in WBS column, but if I click to expand a collapsed node, data is not shown in WBS column for the new expanded rows, only shows data in hierarchy column. How to show data in WBS column for the new expanded rows..?
Basically if at the first show I expand all node, data in WBS column are shown for all rows. It seems that the Expand Node event doesn't update all column data to be shown.
Please share if anyone of you has faced this kind of problem. Thank you.
Regards,
Ramses Hutahaean
Edited by: Ramses Hutahaean on Feb 29, 2012 1:38 PMHi Fenja,
as the click-events only raise the node_key (at least I couldn't detect another information), I assume the only way is maintaining an internal helper table by yourself which you build up in parallel when creating the tree and its nodes.
The (hashed) table might contain 2 columns:
1. node_key (as table key)
2. reference to an object
When a click-event is raised, you look up the corresponding object reference in your table.
Regards,
Ulrich -
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 -
Hi,
i want to download the <b>alv tree output</b> as it displays to <b>excel</b>,means with expand collapse functions. how to achive this .
rgds
Madhuhi
good
go through this code
REPORT ZTH_TEST
no standard page heading
data:
t_nodes like table of SNODETEXT with header line.
start-of-selection.
t_nodes-name = 'root node'.
t_nodes-tlevel = 1.
t_nodes-id = 1.
t_nodes-parent = 0.
append t_nodes.
t_nodes-name = 'child node 1'.
t_nodes-parent = 1.
t_nodes-id = 2.
t_nodes-tlevel = 2.
append t_nodes.
t_nodes-name = 'child node 2'.
t_nodes-parent = 1.
t_nodes-id = 3.
t_nodes-tlevel = 2.
append t_nodes.
end-of-selection.
CALL FUNCTION 'RS_TREE_CONSTRUCT'
TABLES
NODETAB = t_nodes
EXCEPTIONS
TREE_FAILURE = 1
ID_NOT_FOUND = 2
WRONG_RELATIONSHIP = 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.
SET PF-STATUS 'ZTH_TREE'.
CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
EXPORTING
CALLBACK_PROGRAM = 'zth_test'
thanks
mrutyun^ -
Coloring column in an ALV tree
Hi all,
What I want to do is set background color for columns in a tree-view ALV(class cl_gui_alv_tree). However no matter how I set the field EMPHASIZE in the fieldcatalog internal table, the display of the ALV tree keeps unchange. Anyone can help me on this?
Thanks,
Chen ChangHi,
<b>If u want to change the node colr in ALV tree do as follows</b>
Adding Root Nodes for the tree.
Key:
NODE_KEY, RELATKEY, RELATSHIP, HIDDEN, DISABLED, ISFOLDER, N_IMAGE,
EXP_IMAGE, <b>STYLE</b>, LAST_HITEM, NO_BRANCH, EXPANDER, DRAGDROPID, TEXT
perform f9101_node_list using: '1' 'ROOT' '' '' '' c_x '' '' '' '' ''
c_x '' text-003.
Adding subitems for the root node.
perform f9101_node_list using:
Material Details
'MATRL' '1' '' '' '' '' '' '' '' '' '' '' ''
text-001,
Document Details
'DOCU' '1' '' '' '' '' '' '' '' '' '' '' ''
text-002.
form f9101_node_list using value(pnodekey)
value(prelatkey)
value(prelatship)
value(phidden)
value(pdisabled)
value(pisfolder)
value(pimage)
value(pexpimage)
value(pstyle)
value(plastitem)
value(pnobranch)
value(pexpander)
value(pdragdropid)
value(ptext).
w_nodes-node_key = pnodekey.
w_nodes-relatkey = prelatkey.
w_nodes-relatship = prelatship. "Natural number
w_nodes-hidden = phidden.
w_nodes-disabled = pdisabled.
w_nodes-isfolder = pisfolder.
w_nodes-n_image = pimage. "Icons / embedded bitmap
w_nodes-exp_image = pexpimage. "Icons / embedded bitmap
<b> w_nodes-style = pstyle.</b> w_nodes-last_hitem = plastitem. "Tree Control: Column Name / Item
"Name
w_nodes-no_branch = pnobranch.
w_nodes-expander = pexpander.
w_nodes-dragdropid = pdragdropid.
w_nodes-text = ptext.
append w_nodes to i_nodes.
endform. " f9101_node_list
Try changing the style so that u can change the column color.
If u want that in ALV grid
1. different color in line of alv
2. Coloring Cells/rows in ALV Grid.
Got this from forum
report .
Use of colours in ALV grid (cell, line and column) *
Table
tables : mara.
Type
types : begin of ty_mara,
matnr like mara-matnr,
matkl like mara-matkl,
counter(4) type n,
free_text(15) type c,
color_line(4) type c, " Line color
color_cell type lvc_t_scol, " Cell color
end of ty_mara.
Structures
data : wa_mara type ty_mara,
wa_fieldcat type lvc_s_fcat,
is_layout type lvc_s_layo,
wa_color type lvc_s_scol.
Internal table
data : it_mara type standard table of ty_mara,
it_fieldcat type standard table of lvc_s_fcat,
it_color type table of lvc_s_scol.
Variables
data : okcode like sy-ucomm,
w_alv_grid type ref to cl_gui_alv_grid,
w_docking_container type ref to cl_gui_docking_container.
parameters : p_column as checkbox,
p_line as checkbox,
p_cell as checkbox.
at selection-screen output.
perform get_data.
perform fill_catalog.
if w_docking_container is initial.
perform create_objects.
endif.
*& Form create_objects
form create_objects.
create object w_docking_container
exporting
ratio = 60
exceptions
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
others = 6.
create object w_alv_grid
exporting
i_parent = w_docking_container.
Field that identify color line in internal table
move 'COLOR_LINE' to is_layout-info_fname.
Field that identify cell color in inetrnal table
move 'COLOR_CELL' to is_layout-ctab_fname.
call method w_alv_grid->set_table_for_first_display
exporting
is_layout = is_layout
changing
it_outtab = it_mara
it_fieldcatalog = it_fieldcat
exceptions
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4.
endform.
*& Form get_data
form get_data.
select * from mara up to 5 rows.
clear : wa_mara-color_line, wa_mara-color_cell.
move-corresponding mara to wa_mara.
add 1 to wa_mara-counter.
move 'Blabla' to wa_mara-free_text.
if wa_mara-counter = '0002'
and p_line = 'X'.
Color line move 'C410' to wa_mara-color_line.
elseif wa_mara-counter = '0004'
and p_cell = 'X'.
Color cell
move 'FREE_TEXT' to wa_color-fname.
move '6' to wa_color-color-col.
move '1' to wa_color-color-int.
move '1' to wa_color-color-inv.
append wa_color to it_color.
wa_mara-color_cell[] = it_color[].
endif.
append wa_mara to it_mara.
endselect.
endform.
*& Form fill_catalog
form fill_catalog.
Colour code : *
Colour is a 4-char field where : *
- 1st char = C (color property) *
- 2nd char = color code (from 0 to 7) *
0 = background color *
1 = blue *
2 = gray *
3 = yellow *
4 = blue/gray *
5 = green *
6 = red *
7 = orange *
- 3rd char = intensified (0=off, 1=on) *
- 4th char = inverse display (0=off, 1=on) *
Colour overwriting priority : *
1. Line *
2. Cell *
3. Column *
data : w_position type i value '1'.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATNR' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATNR' to wa_fieldcat-ref_field.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'MATKL' to wa_fieldcat-fieldname.
move 'MARA' to wa_fieldcat-ref_table.
move 'MATKL' to wa_fieldcat-ref_field.
Color column
if p_column = 'X'.
move 'C610' to wa_fieldcat-emphasize.
endif.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'COUNTER' to wa_fieldcat-fieldname.
move 'N' to wa_fieldcat-inttype.
move '4' to wa_fieldcat-intlen.
move 'Counter' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
add 1 to w_position.
clear wa_fieldcat.
move w_position to wa_fieldcat-col_pos.
move 'FREE_TEXT' to wa_fieldcat-fieldname.
move 'C' to wa_fieldcat-inttype.
move '20' to wa_fieldcat-intlen.
move 'Text' to wa_fieldcat-coltext.
append wa_fieldcat to it_fieldcat.
endform.
Check this link to get code for different colors http://www.sapdesignguild.org/resources/ma_guidelines/VisualDesignRules/colors.html
Try this out the same thing will work for Reuse also.
Thanks & Regards,
Judith.
Message was edited by: Judith Jessie Selvi -
Drag and Drop between two ALV Tree Controls
Hello all,
I have designed a spilt control of two ALV Trees using CL_GUI_ALV_TREE.
I have a top node as the Sales order Number and the child node as the items belonging to that sales order number.
Now i need to drag and drop the lines from one sales order to another.
Also these drag drop can take place between the nodes of the two different trees.
Can someone provide with a detail example as i need to complete the same urgently.
Regards,
ArunOnce check the Below code For tree to tree drag an drop
* CLASS lcl_main DEFINITION
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
* Types
TYPES:
BEGIN OF t_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF t_ekpo.
TYPES:
BEGIN OF t_vbap,
vbeln TYPE vbeln,
posnr TYPE vbelp,
END OF t_vbap.
* Internal Tables
DATA:
i_ekpo TYPE STANDARD TABLE OF t_ekpo,
i_ekpo_op TYPE STANDARD TABLE OF t_ekpo,
i_vbap TYPE STANDARD TABLE OF t_vbap,
i_vbap_op TYPE STANDARD TABLE OF t_vbap,
i_fcat_ekpo TYPE lvc_t_fcat,
i_fcat_vbap TYPE lvc_t_fcat.
* Work Areas
DATA:
wa_ekpo TYPE t_ekpo,
wa_ekpo1 TYPE t_ekpo,
wa_vbap TYPE t_vbap,
wa_vbap1 TYPE t_vbap.
* Data Declarations
DATA:
g_ebeln TYPE ebeln,
g_vbeln TYPE vbeln_va.
DATA: g_variant TYPE disvariant,
g_hierarchy_header TYPE treev_hhdr,
g_handle_drag TYPE i,
g_handle_drop TYPE i.
* Class data
DATA:
splitter TYPE REF TO cl_gui_splitter_container,
container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
tree1 TYPE REF TO cl_gui_alv_tree,
tree2 TYPE REF TO cl_gui_alv_tree,
g_drag TYPE REF TO cl_dragdrop,
g_drop TYPE REF TO cl_dragdrop.
* Constants
CONSTANTS:
c_30(2) TYPE c VALUE '30'.
* Methods
METHODS:
get_data, " Data Fatch
build_display, " Display Container
display_ekpo, " Ekpo table display
display_vbap, " Vbap table display
add_node_ekpo " Add node to Ekpo
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
add_node_vbap " Add node to vbap
IMPORTING table TYPE t_vbap
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
dnd_behaviour, " Drag and drop behavour
register_events_ekpo, " Register Events Ekpo
register_events_vbap, " Register events vbap
handle_drag_multiple " Drag Multiple Values
FOR EVENT on_drag_multiple
OF cl_gui_alv_tree
IMPORTING sender node_key_table fieldname drag_drop_object,
handle_drop " Drop the values
FOR EVENT on_drop
OF cl_gui_alv_tree
IMPORTING sender node_key drag_drop_object,
add_node_drop " Add node to Drop Node
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
CHANGING i_key TYPE lvc_nkey.
ENDCLASS. " Lcl_main DEFINITION
* CLASS LCL_DRAGOBJ DEFINITION
* Drag And drop Structure
CLASS lcl_dragobj DEFINITION INHERITING FROM lcl_main FINAL.
PUBLIC SECTION.
* Types
TYPES: BEGIN OF t_node_info,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_key TYPE lvc_nkey,
END OF t_node_info.
* Data
DATA: i_node_info TYPE TABLE OF t_node_info,
wa_node_info TYPE t_node_info.
ENDCLASS. " LCL_DRAGOBJ DEFINITION
* Object Declarations
DATA obj_main TYPE REF TO lcl_main.
* Initialization *
INITIALIZATION.
CREATE OBJECT obj_main.
* Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS:
s_ebeln FOR obj_main->g_ebeln,
s_vbeln FOR obj_main->g_vbeln MATCHCODE OBJECT cs_vbeln.
SELECTION-SCREEN END OF BLOCK block1.
* Start of Selection *
START-OF-SELECTION.
* Call Screen
CALL SCREEN 100.
* CLASS lcl_main IMPLEMENTATION
* Local class Implementation
CLASS lcl_main IMPLEMENTATION.
* Get Data *
METHOD get_data.
* Data from Ekpo
SELECT ebeln
ebelp
FROM ekpo
UP TO 100 ROWS
INTO TABLE i_ekpo
WHERE ebeln IN s_ebeln.
* Data from Vbap
SELECT vbeln
posnr
FROM vbap
UP TO 100 ROWS
INTO TABLE i_vbap
WHERE vbeln IN s_vbeln.
ENDMETHOD. " Get_data
* Build Display *
METHOD build_display.
* Create Container
CREATE OBJECT container
EXPORTING
container_name = 'CUST_CONT'.
* Split the container
CREATE OBJECT splitter
EXPORTING
parent = container
rows = 1
columns = 2.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = container_1.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = container_2.
* create tree control
CREATE OBJECT tree1
EXPORTING
parent = container_1
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
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 NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
CREATE OBJECT tree2
EXPORTING
parent = container_2
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
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 NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
g_variant-report = sy-repid.
g_variant-handle = space.
g_variant-log_group = space.
g_variant-username = space.
g_variant-text = space.
g_variant-dependvars = space.
* Call method for get data
CALL METHOD get_data.
* Drap And Drop behaviour method
CALL METHOD dnd_behaviour.
* Display the Ekpo table
CALL METHOD obj_main->display_ekpo.
* Diaplay the vbap table
CALL METHOD obj_main->display_vbap.
CALL METHOD tree1->frontend_update.
CALL METHOD tree2->frontend_update.
ENDMETHOD. " Build_display
* Display EKPO *
METHOD display_ekpo.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'EKPO'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_ekpo
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_ekpo FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Purchase Order Details'(001).
g_hierarchy_header-tooltip = 'Purchase Order'(002).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Diaply
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_ekpo_op
it_fieldcatalog = i_fcat_ekpo.
LOOP AT i_ekpo INTO wa_ekpo1.
MOVE wa_ekpo1 TO wa_ekpo.
l_key1 = ''.
AT NEW ebeln.
MOVE wa_ekpo-ebeln TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key1
text = l_node_text
flag = space
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_ekpo-ebelp TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key2
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_ekpo INTO wa_ekpo1.
* Call method For Register events
CALL METHOD register_events_ekpo.
ENDMETHOD. " Display_ekpo
* Display VBAP *
METHOD display_vbap.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
REFRESH i_fcat_vbap.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'VBAP'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_vbap
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_vbap FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Sales Order Details'(003).
g_hierarchy_header-tooltip = 'Sales Order'(004).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Display
CALL METHOD tree2->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_vbap_op
it_fieldcatalog = i_fcat_vbap.
LOOP AT i_vbap INTO wa_vbap1.
MOVE wa_vbap1 TO wa_vbap.
l_key1 = ''.
AT NEW vbeln.
MOVE wa_vbap-vbeln TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key1
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_vbap-posnr TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key2
text = l_node_text
flag = space
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_vbap INTO wa_vbap1.
* Call method For Register events
CALL METHOD register_events_vbap.
ENDMETHOD. " Display_vbap
* Add Node to Ekko *
METHOD add_node_ekpo.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drag.
ENDIF. " IF flag = 'X'.
* Add node to tree1
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_ekpo
* Add Node to Vbap *
METHOD add_node_vbap.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drop.
ENDIF. " IF flag = 'X'.
* Add node for tree2
CALL METHOD tree2->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_vbap
* Dnd behaviour *
METHOD dnd_behaviour.
* Data
DATA: effect TYPE i,
l_flavor TYPE c VALUE 'f'.
* For drag
CREATE OBJECT g_drag.
effect = cl_dragdrop=>copy.
CALL METHOD g_drag->add
EXPORTING
flavor = l_flavor
dragsrc = 'X'
droptarget = ' '
effect = effect
effect_in_ctrl = effect.
CALL METHOD g_drag->get_handle
IMPORTING
handle = g_handle_drag.
* For Drop
CREATE OBJECT g_drop.
effect = cl_dragdrop=>copy.
CALL METHOD g_drop->add
EXPORTING
flavor = l_flavor
dragsrc = ' '
droptarget = 'X'
effect = effect
effect_in_ctrl = effect.
CALL METHOD g_drop->get_handle
IMPORTING
handle = g_handle_drop.
ENDMETHOD. " Dnd_behaviour
* register events *
METHOD register_events_ekpo.
* Data
DATA: lt_events TYPE cntl_simple_events.
* Tree events registers ALV Tree
CALL METHOD tree1->get_registered_events
IMPORTING
events = lt_events.
* Register events on frontend
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 NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
* Event Handling
SET HANDLER obj_main->handle_drag_multiple FOR tree1.
ENDMETHOD. " Register_events_ekpo
* register events *
METHOD register_events_vbap.
* Data
DATA: lt_events TYPE cntl_simple_events.
* Tree events registers ALV Tree
CALL METHOD tree2->get_registered_events
IMPORTING
events = lt_events.
* Register events on frontend
CALL METHOD tree2->set_registered_events
EXPORTING
events = lt_events
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
illegal_event_combination = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
* Event
SET HANDLER obj_main->handle_drop FOR tree2.
ENDMETHOD. " Register_events_vbap
* Handle drag multiple Values *
METHOD handle_drag_multiple.
* Data
DATA: dataobj TYPE REF TO lcl_dragobj,
l_node_key TYPE lvc_nkey,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_layout TYPE lvc_s_layn.
* Create and fill dataobject for event ON_DROP.
CREATE OBJECT dataobj.
* Loop the Node key Table
LOOP AT node_key_table INTO l_node_key.
CALL METHOD sender->get_outtab_line
EXPORTING
i_node_key = l_node_key
IMPORTING
e_outtab_line = l_ekpo
e_node_text = l_node_text
es_node_layout = l_node_layout.
IF l_node_layout-isfolder NE 'X'.
dataobj->wa_node_info-l_node_key = l_node_key.
dataobj->wa_node_info-l_ekpo = l_ekpo.
dataobj->wa_node_info-l_node_text = l_node_text.
APPEND dataobj->wa_node_info TO dataobj->i_node_info.
ENDIF. " IF l_node_layout-isfolder NE 'X'.
ENDLOOP. " LOOP AT node_key_table INTO l_node_key
drag_drop_object->object = dataobj.
ENDMETHOD. " Handle_drag_multiple
* Handle drop multiple Values *
METHOD handle_drop.
DATA: dataobj TYPE REF TO lcl_dragobj,
l_new_key TYPE lvc_nkey,
l_node_text TYPE lvc_value.
CATCH SYSTEM-EXCEPTIONS move_cast_error = 1.
* ON_DROP
dataobj ?= drag_drop_object->object.
LOOP AT dataobj->i_node_info INTO dataobj->wa_node_info.
MOVE dataobj->wa_node_info-l_node_text TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_drop
EXPORTING
table = dataobj->wa_node_info-l_ekpo
key = node_key
text = l_node_text
CHANGING
i_key = l_new_key.
ENDLOOP. " LOOP AT dataobj->i_node_info INTO dataobj->wa_node_inf
* Expand the node
CALL METHOD sender->expand_node
EXPORTING
i_node_key = node_key
CALL METHOD sender->frontend_update.
ENDCATCH.
IF sy-subrc NE 0.
CALL METHOD drag_drop_object->abort.
ENDIF. " IF sy-subrc NE 0
ENDMETHOD. " Handle_drop
* Add Node to drop *
METHOD add_node_drop.
* Add node to drop tree
CALL METHOD tree2->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
* is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0
ENDMETHOD. " Add_node_drop
ENDCLASS. " lcl_main IMPLEMENTATION
*& Module STATUS_0100 OUTPUT
* Screen 100 Pbo
MODULE status_0100 OUTPUT.
SET PF-STATUS 'BACK'.
* SET TITLEBAR 'xxx'.
CALL METHOD obj_main->build_display.
ENDMODULE. " Status_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* Screen 100 Pai
MODULE user_command_0100 INPUT.
IF sy-ucomm EQ 'BACK'.
LEAVE TO SCREEN 0.
ENDIF. " IF sy-ucomm EQ 'BACK'
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Report ZBPS_TREE_DRAG_DROP
REPORT zbps_tree_drag_drop.
* CLASS lcl_main DEFINITION
CLASS lcl_main DEFINITION.
PUBLIC SECTION.
* Types
TYPES:
BEGIN OF t_ekpo,
ebeln TYPE ebeln,
ebelp TYPE ebelp,
END OF t_ekpo.
TYPES:
BEGIN OF t_vbap,
vbeln TYPE vbeln,
posnr TYPE vbelp,
END OF t_vbap.
* Internal Tables
DATA:
i_ekpo TYPE STANDARD TABLE OF t_ekpo,
i_ekpo_op TYPE STANDARD TABLE OF t_ekpo,
i_vbap TYPE STANDARD TABLE OF t_vbap,
i_vbap_op TYPE STANDARD TABLE OF t_vbap,
i_fcat_ekpo TYPE lvc_t_fcat,
i_fcat_vbap TYPE lvc_t_fcat.
* Work Areas
DATA:
wa_ekpo TYPE t_ekpo,
wa_ekpo1 TYPE t_ekpo,
wa_vbap TYPE t_vbap,
wa_vbap1 TYPE t_vbap.
* Data Declarations
DATA:
g_ebeln TYPE ebeln,
g_vbeln TYPE vbeln_va.
DATA: g_variant TYPE disvariant,
g_hierarchy_header TYPE treev_hhdr,
g_handle_drag TYPE i,
g_handle_drop TYPE i.
* Class data
DATA:
splitter TYPE REF TO cl_gui_splitter_container,
container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
tree1 TYPE REF TO cl_gui_alv_tree,
tree2 TYPE REF TO cl_gui_alv_tree,
g_drag TYPE REF TO cl_dragdrop,
g_drop TYPE REF TO cl_dragdrop.
* Constants
CONSTANTS:
c_30(2) TYPE c VALUE '30'.
* Methods
METHODS:
get_data, " Data Fatch
build_display, " Display Container
display_ekpo, " Ekpo table display
display_vbap, " Vbap table display
add_node_ekpo " Add node to Ekpo
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
add_node_vbap " Add node to vbap
IMPORTING table TYPE t_vbap
key TYPE lvc_nkey
text TYPE lvc_value
flag TYPE c
CHANGING i_key TYPE lvc_nkey,
dnd_behaviour, " Drag and drop behavour
register_events_ekpo, " Register Events Ekpo
register_events_vbap, " Register events vbap
handle_drag_multiple " Drag Multiple Values
FOR EVENT on_drag_multiple
OF cl_gui_alv_tree
IMPORTING sender node_key_table fieldname drag_drop_object,
handle_drop " Drop the values
FOR EVENT on_drop
OF cl_gui_alv_tree
IMPORTING sender node_key drag_drop_object,
add_node_drop " Add node to Drop Node
IMPORTING table TYPE t_ekpo
key TYPE lvc_nkey
text TYPE lvc_value
CHANGING i_key TYPE lvc_nkey.
ENDCLASS. " Lcl_main DEFINITION
* CLASS LCL_DRAGOBJ DEFINITION
* Drag And drop Structure
CLASS lcl_dragobj DEFINITION INHERITING FROM lcl_main FINAL.
PUBLIC SECTION.
* Types
TYPES: BEGIN OF t_node_info,
l_ekpo TYPE t_ekpo,
l_node_text TYPE lvc_value,
l_node_key TYPE lvc_nkey,
END OF t_node_info.
* Data
DATA: i_node_info TYPE TABLE OF t_node_info,
wa_node_info TYPE t_node_info.
ENDCLASS. " LCL_DRAGOBJ DEFINITION
* Object Declarations
DATA obj_main TYPE REF TO lcl_main.
* Initialization *
INITIALIZATION.
CREATE OBJECT obj_main.
* Selection Screen *
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME.
SELECT-OPTIONS:
s_ebeln FOR obj_main->g_ebeln,
s_vbeln FOR obj_main->g_vbeln MATCHCODE OBJECT cs_vbeln.
SELECTION-SCREEN END OF BLOCK block1.
* Start of Selection *
START-OF-SELECTION.
* Call Screen
CALL SCREEN 100.
* CLASS lcl_main IMPLEMENTATION
* Local class Implementation
CLASS lcl_main IMPLEMENTATION.
* Get Data *
METHOD get_data.
* Data from Ekpo
SELECT ebeln
ebelp
FROM ekpo
UP TO 100 ROWS
INTO TABLE i_ekpo
WHERE ebeln IN s_ebeln.
* Data from Vbap
SELECT vbeln
posnr
FROM vbap
UP TO 100 ROWS
INTO TABLE i_vbap
WHERE vbeln IN s_vbeln.
ENDMETHOD. " Get_data
* Build Display *
METHOD build_display.
* Create Container
CREATE OBJECT container
EXPORTING
container_name = 'CUST_CONT'.
* Split the container
CREATE OBJECT splitter
EXPORTING
parent = container
rows = 1
columns = 2.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = container_1.
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 2
RECEIVING
container = container_2.
* create tree control
CREATE OBJECT tree1
EXPORTING
parent = container_1
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
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 NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
CREATE OBJECT tree2
EXPORTING
parent = container_2
node_selection_mode = cl_gui_column_tree=>node_sel_mode_multiple
item_selection = 'X'
no_html_header = 'X'
no_toolbar = 'X'
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 NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
g_variant-report = sy-repid.
g_variant-handle = space.
g_variant-log_group = space.
g_variant-username = space.
g_variant-text = space.
g_variant-dependvars = space.
* Call method for get data
CALL METHOD get_data.
* Drap And Drop behaviour method
CALL METHOD dnd_behaviour.
* Display the Ekpo table
CALL METHOD obj_main->display_ekpo.
* Diaplay the vbap table
CALL METHOD obj_main->display_vbap.
CALL METHOD tree1->frontend_update.
CALL METHOD tree2->frontend_update.
ENDMETHOD. " Build_display
* Display EKPO *
METHOD display_ekpo.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'EKPO'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_ekpo
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_ekpo FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Purchase Order Details'(001).
g_hierarchy_header-tooltip = 'Purchase Order'(002).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Diaply
CALL METHOD tree1->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_ekpo_op
it_fieldcatalog = i_fcat_ekpo.
LOOP AT i_ekpo INTO wa_ekpo1.
MOVE wa_ekpo1 TO wa_ekpo.
l_key1 = ''.
AT NEW ebeln.
MOVE wa_ekpo-ebeln TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key1
text = l_node_text
flag = space
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_ekpo-ebelp TO l_node_text.
* Call method for Add Node to Ekpo
CALL METHOD add_node_ekpo
EXPORTING
table = wa_ekpo
key = l_key2
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_ekpo INTO wa_ekpo1.
* Call method For Register events
CALL METHOD register_events_ekpo.
ENDMETHOD. " Display_ekpo
* Display VBAP *
METHOD display_vbap.
* Data
DATA:
l_key1 TYPE lvc_nkey,
l_key2 TYPE lvc_nkey,
l_key3 TYPE lvc_nkey,
l_node_text TYPE lvc_value.
REFRESH i_fcat_vbap.
* ALV control service modules
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_buffer_active = 'X'
i_structure_name = 'VBAP'
i_client_never_display = 'X'
i_bypassing_buffer = space
CHANGING
ct_fieldcat = i_fcat_vbap
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
DELETE i_fcat_vbap FROM 4.
ENDIF. " IF sy-subrc EQ 0.
g_hierarchy_header-heading = 'Sales Order Details'(003).
g_hierarchy_header-tooltip = 'Sales Order'(004).
g_hierarchy_header-width = c_30.
g_hierarchy_header-width_pix = ' '.
* Display
CALL METHOD tree2->set_table_for_first_display
EXPORTING
is_hierarchy_header = g_hierarchy_header
is_variant = g_variant
CHANGING
it_outtab = obj_main->i_vbap_op
it_fieldcatalog = i_fcat_vbap.
LOOP AT i_vbap INTO wa_vbap1.
MOVE wa_vbap1 TO wa_vbap.
l_key1 = ''.
AT NEW vbeln.
MOVE wa_vbap-vbeln TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key1
text = l_node_text
flag = 'X'
CHANGING
i_key = l_key2.
ENDAT.
CLEAR l_node_text.
MOVE wa_vbap-posnr TO l_node_text.
* Call method for Add Node to vbap
CALL METHOD add_node_vbap
EXPORTING
table = wa_vbap
key = l_key2
text = l_node_text
flag = space
CHANGING
i_key = l_key3.
ENDLOOP. " LOOP AT i_vbap INTO wa_vbap1.
* Call method For Register events
CALL METHOD register_events_vbap.
ENDMETHOD. " Display_vbap
* Add Node to Ekko *
METHOD add_node_ekpo.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drag.
ENDIF. " IF flag = 'X'.
* Add node to tree1
CALL METHOD tree1->add_node
EXPORTING
i_relat_node_key = key
i_relationship = cl_gui_column_tree=>relat_last_child
is_outtab_line = table
i_node_text = text
is_node_layout = l_layout_node
IMPORTING
e_new_node_key = i_key
EXCEPTIONS
relat_node_not_found = 1
node_not_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
CLEAR sy-subrc.
ENDIF. " IF sy-subrc NE 0.
ENDMETHOD. " Add_node_ekpo
* Add Node to Vbap *
METHOD add_node_vbap.
* Data
DATA: l_layout_node TYPE lvc_s_layn.
IF flag = 'X'.
l_layout_node-dragdropid = g_handle_drop.
ENDIF. " IF flag = 'X'.
* Add node for tree2
CALL METHOD t -
Can anyone tell me how to Copy a node on an ALV Tree using context menu ?
Hello Vidya
The sample report ZUS_SDN_ALVTREE_CTXMENU demonstrates how to copy nodes on an ALV tree.
Before showing the entire coding I would like to point out a few crucial parts of the coding:
(1) Defintion of OUTTAB list
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
The OUTTAB list contains two additional fields holding the tree key (LVC_NKEY) and the node type.
(2) The main logic of the report is implemented in event handler method handle_node_ctxmenu_sel.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
" Note: similar logic like in routine CREATE_HIERARCHY
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
*& Report ZUS_SDN_ALVTREE_CTXMENU
*& Based on: BCALV_TREE_03
REPORT zus_sdn_alvtree_ctxmenu.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbak.
TYPES: nkey TYPE lvc_nkey.
TYPES: ntype TYPE lvc_value. " 'VKORG' / 'VTWEG' / 'SPART' / leaf
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA:
gd_repid TYPE syst-repid,
gd_okcode TYPE ui_func,
go_docking TYPE REF TO cl_gui_docking_container,
go_alvtree TYPE REF TO cl_gui_alv_tree.
DATA:
gt_outtab TYPE ty_t_outtab, " Sales Document
gt_fcat TYPE lvc_t_fcat.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
* §2. Define an event handler method to build up a context menu
* (postfix of event name: _CONTEXT_MENU_REQUEST).
* This event is fired each time the user klick with the right
* mouse button on a node.
CLASS-METHODS:
handle_node_ctxmenu_req
FOR EVENT node_context_menu_request OF cl_gui_alv_tree
IMPORTING
node_key
menu,
* §3. Define an event handler method to respond to a function code
* triggered by your menu (postfix: _CONTEXT_MENU_SELECTED).
* This event is fired when the user selects an entry of the
* build up context menu.
handle_node_ctxmenu_sel
FOR EVENT node_context_menu_selected OF cl_gui_alv_tree
IMPORTING
node_key
fcode
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. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
* §4. Implement your event handler methods.
METHOD handle_node_ctxmenu_req.
* Event parameter 'menu' holds a reference to the standard context
* menu of ALV Tree (functions 'Expand'/'Collapse' on nodes).
* You may either append your own functions (separated by a line)
* or clear the menu if you do not want to allow standard functions.
* In this case the standard menu is cleared.
CALL METHOD menu->clear.
* The next line defines one line of the context menu.
CALL METHOD menu->add_function
EXPORTING
fcode = 'DEL_SUBTREE'
text = 'Delete Subtree'(901). "Delete Subtree
CALL METHOD menu->add_function
EXPORTING
fcode = 'COPY_SUBTREE'
text = 'Copy Subtree'(902). "Copy Subtree
ENDMETHOD. "handle_node_ctxmenu_req
METHOD handle_node_ctxmenu_sel.
* At this point of execution, the user selected a menu entry of the
* menu build up in event handler method handle_node_cm_req.
* Query your own function codes and react accordingly.
DATA:
l_rc TYPE c,
ld_ntype TYPE lvc_value,
ld_parent_key TYPE lvc_nkey,
ld_node_key TYPE lvc_nkey,
lt_subtree TYPE lvc_t_nkey,
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
CASE fcode.
WHEN 'DEL_SUBTREE'.
CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
EXPORTING
textline1 = 'Do you really want to delete'(902)
textline2 = 'this node and all its subnodes?'(903)
titel = 'Confirmation'(904)
cancel_display = ' '
IMPORTING
answer = l_rc.
IF l_rc EQ 'J'.
CALL METHOD sender->delete_subtree
EXPORTING
i_node_key = node_key.
* Do not forget to refresh the display when you change the contents
* of your list.
CALL METHOD sender->frontend_update.
ENDIF.
WHEN 'COPY_SUBTREE'.
CALL METHOD go_alvtree->get_subtree
EXPORTING
i_node_key = node_key
IMPORTING
et_subtree_nodes = lt_subtree.
CALL METHOD go_alvtree->get_parent
EXPORTING
i_node_key = node_key
IMPORTING
e_parent_node_key = ld_parent_key.
LOOP AT lt_subtree INTO ld_node_key.
READ TABLE gt_outtab INTO ls_outtab
WITH KEY nkey = ld_node_key.
APPEND ls_outtab TO lt_outtab.
ENDLOOP.
READ TABLE lt_outtab INTO ls_outtab INDEX 1.
ld_ntype = ls_outtab-ntype.
DELETE lt_outtab WHERE ( vbeln IS INITIAL ). " hierarchy nodes
CASE ld_ntype.
WHEN 'VKORG'.
ld_top_key = ld_parent_key.
WHEN 'VTWEG'.
ld_vkorg_key = ld_parent_key.
WHEN 'SPART'.
ld_vtweg_key = ld_parent_key.
WHEN 'LEAF'.
ld_spart_key = ld_parent_key.
ENDCASE.
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
LOOP AT lt_outtab INTO ls_outtab.
IF ( ld_ntype = 'VKORG' ).
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' ).
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
IF ( ld_ntype = 'VKORG' OR
ld_ntype = 'VTWEG' OR
ld_ntype = 'SPART' ).
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH_TREE'
* IMPORTING
* RC =
ENDCASE.
ENDMETHOD. "handle_node_ctxmenu_sel
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
START-OF-SELECTION.
PERFORM init_controls.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
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 screen elements, ok_code -> gd_okcode
** 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. " facilitate manual entries
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
when 'REFRESH_TREE'.
CALL METHOD go_alvtree->update_calculations
* EXPORTING
* NO_FRONTEND_UPDATE =
WHEN OTHERS.
ENDCASE.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
DATA:
ls_hierarchy_header TYPE treev_hhdr.
* 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.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999 " full-size screen
EXCEPTIONS
cntl_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.
* create tree control
CREATE OBJECT go_alvtree
EXPORTING
parent = go_docking
node_selection_mode = cl_gui_column_tree=>node_sel_mode_single
item_selection = ' '
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.
PERFORM build_hierarchy_header CHANGING ls_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 go_alvtree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hierarchy_header
CHANGING
it_fieldcatalog = gt_fcat
it_outtab = gt_outtab. "table must be empty !
PERFORM init_tree.
ENDFORM. " INIT_CONTROLS
*& Form INIT_TREE
* text
* --> p1 text
* <-- p2 text
FORM init_tree .
PERFORM create_hierarchy.
PERFORM register_events.
* Update calculations which were initially defined by field DO_SUM
* of the fieldcatalog. (see build_fieldcatalog).
CALL METHOD go_alvtree->update_calculations.
* Send data to frontend.
CALL METHOD go_alvtree->frontend_update.
ENDFORM. " INIT_TREE
*& Form build_hierarchy_header
* text
* <--P_LS_HIERARCHY_HEADER text
FORM build_hierarchy_header
CHANGING
cs_hierarchy_header TYPE treev_hhdr.
cs_hierarchy_header-heading =
'SalesOrg/DistChannel/Division'(300).
cs_hierarchy_header-tooltip = 'Customer: Master Sales Data'(400).
cs_hierarchy_header-width = 45.
cs_hierarchy_header-width_pix = ''.
ENDFORM. " build_hierarchy_header
*& Form build_fieldcatalog
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog .
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
REFRESH: gt_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAK'
* 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.
LOOP AT gt_fcat INTO ls_fcat.
CASE ls_fcat-fieldname.
WHEN 'VBELN' OR
'AUDAT' OR
'AUART' OR
'WAERK' OR
'VKORG' OR
'VTWEG' OR
'SPART' OR
'BSTNK' OR
'KUNNR'.
WHEN 'NETWR'.
ls_fcat-do_sum = 'X'.
ls_fcat-h_ftype = 'SUM'. " or: 'MAX' / 'AVG'
WHEN OTHERS.
ls_fcat-tech = 'X'.
ENDCASE.
MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
ENDLOOP.
ENDFORM. " build_fieldcatalog
*& Form create_hierarchy
* text
* --> p1 text
* <-- p2 text
FORM create_hierarchy .
* define local data
DATA:
ls_outtab TYPE ty_s_outtab,
ls_last TYPE ty_s_outtab,
lt_outtab TYPE ty_t_outtab.
DATA:
ld_vkorg_key TYPE lvc_nkey,
ld_vtweg_key TYPE lvc_nkey,
ld_spart_key TYPE lvc_nkey,
ld_last_key TYPE lvc_nkey,
ld_top_key TYPE lvc_nkey.
" Select data
SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE lt_outtab
UP TO 1550 ROWS.
" sort table according to conceived hierarchy
SORT lt_outtab BY vkorg vtweg spart kunnr audat.
* Define one top node. In this way it is possible to calculate
* values for the whole hierarchy.
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ''
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = 'Sales Documents'
IMPORTING
e_new_node_key = ld_top_key.
CLEAR: ls_outtab.
ls_outtab-nkey = ld_top_key.
ls_outtab-ntype = 'ROOT'.
MODIFY gt_outtab FROM ls_outtab INDEX 1
TRANSPORTING nkey ntype.
LOOP AT lt_outtab INTO ls_outtab.
" new sales organisation
IF ( ls_outtab-vkorg = ls_last-vkorg ).
ELSE.
PERFORM add_sales_org
USING
ls_outtab
ld_top_key
CHANGING
ld_vkorg_key.
ls_outtab-nkey = ld_vkorg_key.
ls_outtab-ntype = 'VKORG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new distribution channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg ).
ELSE.
PERFORM add_distrib_chan
USING
ls_outtab
ld_vkorg_key
CHANGING
ld_vtweg_key.
ls_outtab-nkey = ld_vtweg_key.
ls_outtab-ntype = 'VTWEG'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
" new channel
IF ( ls_outtab-vkorg = ls_last-vkorg AND
ls_outtab-vtweg = ls_last-vtweg AND
ls_outtab-spart = ls_last-spart ).
ELSE.
PERFORM add_division
USING
ls_outtab
ld_vtweg_key
CHANGING
ld_spart_key.
ls_outtab-nkey = ld_spart_key.
ls_outtab-ntype = 'SPART'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ENDIF.
* Leaf:
PERFORM add_complete_line
USING
ls_outtab
ld_spart_key
CHANGING
ld_last_key.
ls_outtab-nkey = ld_last_key.
ls_outtab-ntype = 'LEAF'.
DESCRIBE TABLE gt_outtab. " fill sy-tfill
MODIFY gt_outtab FROM ls_outtab INDEX syst-tfill
TRANSPORTING nkey ntype.
ls_last = ls_outtab.
ENDLOOP.
ENDFORM. " create_hierarchy
*& Form ADD_SALES_ORG
* text
* -->P_LS_OUTTAB text
* -->P_LD_TOP_KEY text
* <--P_LD_VKORG_KEY text
FORM add_sales_org
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vkorg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " ADD_SALES_ORG
*& Form add_DISTRIB_CHAN
* text
* -->P_LS_OUTTAB text
* -->P_LD_VKORG_KEY text
* <--P_LD_VTWEG_KEY text
FORM add_distrib_chan
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-vtweg.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_DISTRIB_CHAN
*& Form add_division
* text
* -->P_LS_OUTTAB text
* -->P_LD_VTWEG_KEY text
* <--P_LD_SPART_KEY text
FORM add_division
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
ld_nodetext = us_outtab-spart.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = ls_outtab
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_division
*& Form add_complete_line
* text
* -->P_LS_OUTTAB text
* -->P_LD_SPART_KEY text
* <--P_LD_LAST_KEY text
FORM add_complete_line
USING
value(us_outtab) TYPE ty_s_outtab
value(ud_relat_key) TYPE lvc_nkey
CHANGING
cd_node_key TYPE lvc_nkey.
* define local data
DATA:
ld_nodetext TYPE lvc_value,
ls_outtab TYPE ty_s_outtab.
WRITE us_outtab-kunnr TO ld_nodetext+0 NO-ZERO.
WRITE us_outtab-audat TO ld_nodetext+20 DD/MM/YYYY.
CONDENSE ld_nodetext.
" add node
CALL METHOD go_alvtree->add_node
EXPORTING
i_relat_node_key = ud_relat_key
i_relationship = cl_gui_column_tree=>relat_last_child
i_node_text = ld_nodetext
is_outtab_line = us_outtab " !!!
IMPORTING
e_new_node_key = cd_node_key.
ENDFORM. " add_complete_line
*& Form register_events
* text
* --> p1 text
* <-- p2 text
FORM register_events .
DATA:
lt_events TYPE cntl_simple_events,
ls_event TYPE cntl_simple_event.
* 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 go_alvtree->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.
* Register additional events for your own purposes:
* §5. Register first context menu event on frontend (with postfix
* (_REQUEST). The second is registered automatically.
ls_event-eventid = cl_gui_column_tree=>eventid_node_context_menu_req.
APPEND ls_event TO lt_events.
* register events on frontend
CALL METHOD go_alvtree->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.
* §6. Register both context menu events on backend (ABAP Objects
* event handling).
SET HANDLER:
lcl_eventhandler=>handle_node_ctxmenu_req FOR go_alvtree,
lcl_eventhandler=>handle_node_ctxmenu_sel FOR go_alvtree.
ENDFORM. " register_events
Regards,
Uwe -
Hi friends,
I am working in alv tree. It is working fine. In click event , if i click one item it should call another one tcode (it is also an another one tree strucutre ). i called that tcode using call transaction. it is working .
now my question how to place cursor in the corresponding item of the second tree.
Thanks
Senthil Kumar.rHi Senthil,
When you have builded the tree you will have filled node table with node key and text or fieldname .
I mean something like this .
node-node_key = ls_vbak-vbeln.
node-relatkey = 'Orders'.
node-relatship = cl_gui_simple_tree=>relat_last_child.
node-text = ls_vbak-vbeln.
node-isfolder = ' '.
node-expander = ''.
APPEND node TO node_table.
now call methode cl_gui_alv_tree->set_selected_item
exporting I_NODE_KEY = ls_vbak-vbeln. ( child node_key)
In the above the example the first node item would be selected. but before this you should expand the node to select the item
cl_gui_alv_tree->EXPAND_NODE
exporting I_NODE_KEY = ( parent node_key ).
Please reward if useful. -
Hi all,
Please help,
I have created ALV tree, with the help of standard program bcalv_tree_01. now i want to create it interative like DOUBLE CLICK on any ITEM or NODE. so i have define class and implement it with two method for event NODE_DOUBLE_CLICK and ITEM_DOUBLE_CLICK. and i have register it. when i display the tree it doesn't expand, but i comments the CALL METHOD gd_tree->set_registered_events it works fine. should i have to implement the event EXPAND_NO_CHILDREN also?
and what should be the code, becoz i am new in alv tree and oops. for sytex please refer BCALV_TREE_01.
please help as soon as possible.
Thanks in advance.Hi!
Ya you have to code for the method EXPAND_NO_CHILDREN
Where you will be defining the childs to the particular node.
the better example for it you can refer to SAPSIMPLE_TREE_CONTROL_DEMO
where
HANDLE_EXPAND_NO_CHILDREN method implemented shows the childs added and METHOD HANDLE_NODE_DOUBLE_CLICK
implemented to handle the doulbe click.
Regards. -
Runtime Error in ALV Tree Output
Dear All, I am trying to create a ALV Tree using Class cl_gui_alv_tree. The Report Shows the Output with the first Node but when i try to expand it is dumping with a runtime error GETWA_NOT_ASSIGNED in class CL_ALV_TREE_BASE and method SET_ITEMS_FOR_COLUMN. The Reason being the data which was copied in the initial node display to mt_outtab is getting refreshed.
Can any one of you help me the reason for the table getting refreshed. Do i need to pass any data.
I am doing the following steps.
1. Create Container,
2. Create Tree Class object
3. Generate the Field Catalog.
4. Set table for first display " With empty internal table
5. Generate the Hierarchy
6. Call the Method Frontend Update.
Let me know if i had missed any steps in the process.
Thank you,
Regards,
Swaroop PatriOne reason for getting this error is using local defined tables for it_outtab parameter in the below code:
To get rid of the dump, define two distinct output tables globally: one is an empty table which you will pass to the below method, other one is your real output table whose size increases dependently.
CALL METHOD go_tree->set_table_for_first_display
EXPORTING
is_hierarchy_header = ls_hier_header
CHANGING
it_outtab = gt_data_e "Empty table
it_fieldcatalog = gt_fcat_tree.
Maybe you are looking for
-
How to use add-on in dreamweaver cc
How to use add-on in Dreamweaver cc. This is my first time using Dreamweaver cc, so I know little about using the add-on feature.
-
How to add a function field into the existing matrix report
Hi, I have a matrix report , now i wanted to add one moe field into the matrix which is getting the value from a function , this function is a part of the ref cursor query(group) , i'm able to get the value from the function but it cannot display on
-
Mimicking Smugmug features in iWeb
I'm trying to add the ability to upload pictures to my website by dragging them onto an icon on my webpage like smugmug does. Is there any way to do this? My website is hosted by godaddy.com and I upload it using Yummy FTP.
-
The columns must be marked with a * in the columnsin Planning layout
hi , Doeas anyone please tell me how to add ' * ' next to characetristic name in the Header of the planning Layout in only some columns headers. i am not able to just add * and save. is there any VBA code we have to use ? or any changes in the BSP ap
-
When I turn my mac book pro on the screen goes blue
Hi when I have had my mac book pro for well almost a year now and for some odd reason twice now when I turn on the computer the screen goes blue and will not go to the desk top....please advice