您的位置:首页 > 其它

web dynpro for abap基础知识(四)

2009-12-29 17:39 344 查看
访问一个node element
获得一个指向node的引用后就可以使用get_element( )方法来获得指向element at selection的引用,类型为IF_WD_CONTEXT_ELEMENT。

DATA: lo_nd_flights TYPE REF TO lf_wd_context_node.
DATA: lo_el_flights TYPE REF TO if_wd_context_element.

lo_wd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).

*get element at lead selection
lo_el_flight = lo_flight_flights->get_element( ).

*if lead selection is not set, ELEM_FLIGHTS will be initial
IF ( lo_el_flights IS INITIAL ).
...
ENDIF.

要获得索引为n的element,使用方法get_element( index = n )。get_element_count( ) 方法返回一个collection中的element的数目。

访问单个node的attribute
一旦获得了指向一个node element的引用,就可以使用下面两个方法来访问这个node的attribute。get_attribute( )可以访问任意一个attribute,所需的参数是要访问的attribute的名字。另一个方法是get_static_attributes( ),用于访问static defined attributes(此处不明白)。

DATA: lo_nd_flights TYPE REF TO lf_wd_context_node.
DATA: lo_el_flights TYPE REF TO if_wd_context_element.
DATA: lv_connid TYPE wd_this->element_flights-connid.

lo_wd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).
lo_el_flight = lo_flight_flights->get_element( ).

*get single attribute
lo_el_flights->get_attribute(
EXPORTING
name = 'CONNID'
IMPORTING
value = lv_connid ).

controller context中的每个node在interface IF_<ctrl_name>中都有一个隐含的名为element_<node_name>structure和名为elements_<node_name>的standard internal table,其line type是element_<node_name>。这个internal table用于存放multiple node elements的attributes。(此处不明白,既然每个node都有一个这样对应的internal table,为什么还说存放multiple node elements的attributes??)

一个使用get_static_attributes( )访问一个node 的static attributes的例子:
DATA: lo_nd_flights TYPE REF TO lf_wd_context_node.
DATA: lo_el_flights TYPE REF TO if_wd_context_element.
DATA: ls_flights TYPE wd_this->element_flights.

lo_nd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).
lo_el_flights = lo_nd_flights->get_elements

*get all static declared attributes
lo_el_flights->get_static_attributes(
IMPORTING
static_attributes = ls_flights ).

获取所有node elements的static attribues:

DATA: lo_nd_flights TYPE REF TO lf_wd_context_node.
DATA: lt_flights TYPE wd_this->element_flights.

lo_nd_flights = wd_context->get_child_node( name = wd_this->wdctx_flights ).

*get all static declared attributes for all node element
lo_nd_flights->get_static_attributes_table(
IMPORTING
table = lt_flights ).

(完成)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: