人法地,地法天,天法道,道法自然
分类:
2009-04-30 15:39:16
创建动态树形菜单——ALV
创建的合同越多,使用树形菜单能比较直观的地显示,而且展开下阶也能明确的知识相关的信息,比如合同中的出口成品有哪些。
设计要点:
第一、 Node_key一定要区分,不能重复,否则出错;
第二、 每一级别,其node_key编制有规律性;这样才能处理复杂的事件响应;
第三、 四层级别,下一级别包括上一级别的相关信息,在创建内表时可能包括;比如子类可以拥有父类的一些信息,孙类级别则包含子类以上的相关信息。这些信息为后续数据处理更直接更方便的提供了需要的信息。
代码设计:
*编制树节点及项目
data: begin of root occurs 0 ,
rkey type string,
rtext type string,
rname type char1,
rcount type string,
rhname like zsd19cont-hname,
end of root.
data: begin of child occurs 0.
include structure root.
data:ckey type string,
ctext type string,
cname type char1,
ccount type string.
data: end of child.
data: begin of grandson occurs 0.
include structure child.
data:gkey type string,
gtext type string,
gname type char1,
gcount type string.
data: end of grandson.
data: begin of nitem occurs 0.
include structure grandson.
data:nkey type string,
ntext type string,
nname type char1,
ncount type string.
data: end of nitem.
form set_root_info.
clear t_cont[].
clear root[].
select * from zsd19cont into corresponding fields of table t_cont where hname in s_hname and lvorm <> 'X'.
loop at t_cont.
count = sy-tabix.
concatenate 'r' count into root-rkey.
concatenate '合同' t_cont-sname into root-rtext.
condense root-rkey no-gaps.
root-rname = '1'.
root-rcount = count.
root-rhname = t_cont-hname.
append root.
clear root.
endloop.
* root-rkey = 'r2'.
* root-rtext = '合同-2009-138'.
* root-rname = '1'.
* root-rcount = 2.
* append root.
* clear root.
endform.
form set_child_info.
clear child[].
loop at root.
move-corresponding root to child .
concatenate root-rcount '1' into count.
condense count no-gaps.
concatenate 'c' count into child-ckey.
condense child-ckey no-gaps.
child-ctext = '商品信息'.
child-cname = '1'.
child-ccount = count .
append child.
clear child.
move-corresponding root to child .
concatenate root-rcount '2' into count.
condense count no-gaps.
concatenate 'c' count into child-ckey.
condense child-ckey no-gaps.
child-ctext = '报关信息'.
child-cname = '1'.
child-ccount = count .
append child.
clear child.
endloop.
endform.
form set_grandson_info.
clear grandson[].
loop at child.
if child-ctext = '商品信息'.
move-corresponding child to grandson .
concatenate child-ccount '1' into count.
condense count no-gaps.
concatenate 'g' count into grandson-gkey.
condense grandson-gkey no-gaps.
grandson-gtext = '出口成品→维护'.
grandson-gname = '1'.
grandson-gcount = count .
append grandson.
clear grandson.
move-corresponding child to grandson .
concatenate child-ccount '2' into count.
condense count no-gaps.
concatenate 'g' count into grandson-gkey.
condense grandson-gkey no-gaps.
grandson-gtext = '进口料件→汇总'.
grandson-gname = '1'.
grandson-gcount = count .
append grandson.
clear grandson.
else.
move-corresponding child to grandson .
concatenate child-ccount '1' into count.
condense count no-gaps.
concatenate 'g' count into grandson-gkey.
condense grandson-gkey no-gaps.
grandson-gtext = '出口成品→报关'.
grandson-gname = '1'.
grandson-gcount = count .
append grandson.
clear grandson.
move-corresponding child to grandson .
concatenate child-ccount '2' into count.
condense count no-gaps.
concatenate 'g' count into grandson-gkey.
condense grandson-gkey no-gaps.
grandson-gtext = '进口料件→报关'.
grandson-gname = '1'.
grandson-gcount = count .
append grandson.
clear grandson.
move-corresponding child to grandson .
concatenate child-ccount '3' into count.
condense count no-gaps.
concatenate 'g' count into grandson-gkey.
condense grandson-gkey no-gaps.
grandson-gtext = '进料结转数→报关'.
grandson-gname = '1'.
grandson-gcount = count .
append grandson.
clear grandson.
endif.
endloop.
endform.
form set_item_info."曾孙处理
clear nitem[].
data : tnum type i ,
tcount type string.
select * from zsd19chuk into corresponding fields of table i_chuk for all entries in grandson where hname = grandson-rhname.
* loop at grandson.
* select * from zsd19chuk into zsd19chuk where hname = grandson-rhname.
* if sy-subrc = 0 .
* move-corresponding zsd19chuk to i_chuk.
* append i_chuk.
* clear i_chuk.
* endif.
* endselect.
*
* clear zsd19chuk.
* endloop.
loop at grandson.
if grandson-gtext = '出口成品→维护' and grandson-ctext = '商品信息'.
loop at i_chuk where hname = grandson-rhname.
tnum = tnum + 1 .
tcount = tnum.
move-corresponding grandson to nitem.
concatenate grandson-gcount tcount into count.
concatenate 'n' count into nitem-nkey.
condense nitem-nkey no-gaps.
nitem-ntext = i_chuk-extwo.
nitem-nname = '1'.
nitem-ncount = count.
append nitem.
clear nitem.
endloop.
tnum = 0 .
endif.
endloop.
endform.
*&---------------------------------------------------------------------*
*& Form build_node_and_item_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_node_and_item_table
using
node_table type treev_ntab
item_table type item_table_type.
data: node type treev_node,
item type mtreeitm.
perform set_root_info.
perform set_child_info.
perform set_grandson_info.
perform set_item_info.
loop at root.
node-node_key = root-rkey.
clear node-relatkey.
clear node-relatship.
node-hidden = ' '.
node-disabled = ' '.
node-isfolder = 'X'.
clear node-n_image.
clear node-exp_image.
clear node-expander.
append node to node_table.
clear node.
clear item.
item-node_key = root-rkey.
item-item_name = '1'. " Item with name '1'
item-class = cl_gui_list_tree=>item_class_text. " Text Item
" the with of the item is adjusted to its content (text)
item-alignment = cl_gui_list_tree=>align_auto.
" use proportional font for the item
item-font = cl_gui_list_tree=>item_font_prop.
item-text = root-rtext. "#EC NOTEXT
append item to item_table.
endloop.
*----------------------------------------------------------------------------------
loop at child.
clear node.
node-node_key = child-ckey.
node-relatkey = child-rkey..
node-relatship = cl_gui_list_tree=>relat_last_child.
node-isfolder = 'X'.
append node to node_table.
clear item.
item-node_key = child-ckey.
item-item_name = '1'.
item-class = cl_gui_list_tree=>item_class_text.
item-alignment = cl_gui_list_tree=>align_auto.
item-font = cl_gui_list_tree=>item_font_prop.
item-text = child-ctext. "#EC NOTEXT
append item to item_table.
endloop.
*----------------------------------------------------------------------------------
loop at grandson.
clear node.
node-node_key = grandson-gkey.
node-relatkey = grandson-ckey.
node-relatship = cl_gui_list_tree=>relat_last_child.
node-isfolder = 'X'.
append node to node_table.
clear item.
item-node_key = grandson-gkey.
item-item_name = '1'.
item-class = cl_gui_list_tree=>item_class_text.
item-alignment = cl_gui_list_tree=>align_auto.
item-font = cl_gui_list_tree=>item_font_prop.
item-text = grandson-gtext. "#EC NOTEXT
append item to item_table.
endloop.
loop at nitem.
clear node.
node-node_key = nitem-nkey. "#ec notext
node-relatkey = nitem-gkey.
node-relatship = cl_gui_list_tree=>relat_last_child.
append node to node_table.
clear item.
item-node_key = nitem-nkey.
item-item_name = '1'.
item-class = cl_gui_list_tree=>item_class_text.
item-length = 15.
item-usebgcolor = 'x'.
item-text = nitem-ntext.
append item to item_table.
endloop.
*----------------------------------------------------------------------------------
* CLEAR NODE.
* NODE-NODE_KEY = 'New2'. "#EC NOTEXT
* NODE-RELATKEY = 'Child1'.
* NODE-RELATSHIP = CL_GUI_LIST_TREE=>RELAT_LAST_CHILD.
* APPEND NODE TO NODE_TABLE.
*
* CLEAR ITEM.
* ITEM-NODE_KEY = 'New2'.
* ITEM-ITEM_NAME = '2'.
* ITEM-CLASS = CL_GUI_LIST_TREE=>ITEM_CLASS_TEXT.
* ITEM-LENGTH = 4.
* ITEM-USEBGCOLOR = 'X'.
* ITEM-TEXT = '0200'.
* APPEND ITEM TO ITEM_TABLE.
endform. " build_node_and_item_table