1.在组件控制器的Context页签中,在传出参数中新建子节点,将子查询需要的字段建立起来,并将属性改为0…n(内表形式),以及添加Supply Function(取数时调用的方法)
2.保存后会自动创建一个Supply Function方法,在方法中添加取数及赋值的逻辑。
大部分代码将注释取消掉即可。
METHOD get_mard .
* General Notes
* =============
* A common scenario for a supply method is to aquire key
* informations from the parameter <parent_element> and then
* to invoke a data provider.
* A free navigation thru the context, especially to nodes on
* the same or deeper hierachical level is strongly discouraged,
* because such a strategy may easily lead to unresolvable
* situations!!
* if necessary, get static attributes of parent element
DATA ls_parent_attributes TYPE wd_this->element_sales_orders.
parent_element->get_static_attributes(
IMPORTING
static_attributes = ls_parent_attributes ).
*
** data declaration
DATA lt_mard TYPE wd_this->elements_mard.
DATA ls_mard LIKE LINE OF lt_mard.
** @TODO compute values
** e.g. call a data providing FuBa
* 向内表添加数据
SELECT * FROM mard INTO CORRESPONDING FIELDS OF TABLE lt_mard
WHERE matnr = ls_parent_attributes-material
AND labst > 0.
** bind all the elements
node->bind_table(
new_items = lt_mard
set_initial_elements = abap_true ).
*
ENDMETHOD.
3.在视图中更新Context页签的数据,并新建一个表格,用于存放子查询的数据。
4.(可选)在视图中标准默认的方法WDDOINIT(用于初始化数据)使用向导set添加默认值的代码。
METHOD wddoinit .
DATA lo_nd_importing TYPE REF TO if_wd_context_node.
DATA lo_el_importing TYPE REF TO if_wd_context_element.
DATA ls_importing TYPE wd_this->element_importing.
DATA lv_customer_number TYPE wd_this->element_importing-customer_number.
* navigate from <CONTEXT> to <IMPORTING> via lead selection
lo_nd_importing = wd_context->path_get_node( path = `BAPI_SALESORDER_GETL.IMPORTING` ).
* @TODO handle non existant child
* IF lo_nd_importing IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_importing = lo_nd_importing->get_element( ).
* @TODO handle not set lead selection
IF lo_el_importing IS INITIAL.
ENDIF.
* @TODO fill attribute
lv_customer_number = 6000881.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_customer_number
IMPORTING
output = lv_customer_number.
* set single attribute
lo_el_importing->set_attribute(
name = `CUSTOMER_NUMBER`
value = lv_customer_number ).
DATA lv_sales_organization TYPE wd_this->element_importing-sales_organization.
* navigate from <CONTEXT> to <IMPORTING> via lead selection
lo_nd_importing = wd_context->path_get_node( path = `BAPI_SALESORDER_GETL.IMPORTING` ).
* @TODO handle non existant child
* IF lo_nd_importing IS INITIAL.
* ENDIF.
* get element via lead selection
lo_el_importing = lo_nd_importing->get_element( ).
* @TODO handle not set lead selection
IF lo_el_importing IS INITIAL.
ENDIF.
* @TODO fill attribute
lv_sales_organization = 1000.
* set single attribute
lo_el_importing->set_attribute(
name = `SALES_ORGANIZATION`
value = lv_sales_organization ).
ENDMETHOD.
5.效果如下,选择不同的行会查询该行物料的库存数据。