我需要显示一个弹出窗口,其中包含来自数据库表字段(Tab1-camp_type
(的数据。
目前我创建了一个UI组件(ZUIC_TYPES
(,一个表视图(VWTYPES
(并添加了必要的表字段。
在我的上下文节点的DO_PREPARE_OUTPUT
方法中,我编写了代码,它应该为我提供camp_type
字段中的所有值,但我只得到一个值重复 37 次(我的表中有 37 行(。
如何在弹出窗口中获取所有数据?
这是我的代码:
DATA:lr_table TYPE REF TO crmc_mktpl_ctype,
lr_struct TYPE crmc_mktpl_ctype,
lt_tabledata TYPE TABLE OF crmc_mktpl_ctype,
ls_tabledata LIKE LINE OF lt_tabledata,
lr_camptype TYPE REF TO cl_bsp_wd_value_node,
lr_col TYPE REF TO cl_crm_bol_bo_col.
"fetch the data.
SELECT DISTINCT camp_type FROM crmc_mktpl_ctype INTO CORRESPONDING FIELDS OF TABLE lt_tabledata.
CHECK sy-subrc = 0.
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype
EXPORTING
iv_data_ref = lr_table.
"create value node for each record foound.
LOOP AT lt_tabledata INTO ls_tabledata.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( lr_camptype ).
ENDLOOP.
"all records are processed. set the collection to the collection wrapper of
" context node to make it visible on web ui
me->typed_context->camptype->collection_wrapper->set_collection( lr_col ).
在循环之前只创建了一个节点(lr_camptype
(,因此要多次添加相同的节点。请记住,在每个循环中,您都会添加对同一对象的引用,因此在以后处理该对象时,该对象将仅包含最新值。
通过在 LOOP 中移动节点的创建,应每行创建一个节点,如下所示:
...
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create value node for each record found.
LOOP AT lt_tabledata INTO ls_tabledata.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype " <=== must be inside the loop !
EXPORTING
iv_data_ref = lr_table.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( lr_camptype ).
ENDLOOP.
...
- 创建 Z-UI 组件。
- 通过向导创建视图(类型:表((创建视图时(选择必要的表和字段(。
- 将视图绑定到窗口。
- 为 Z 窗口创建组件界面。
- 在
DO_PREPARE_OUTPUT
方法中编写以下代码:
TYPES: BEGIN OF ltype_attr_struct,
camp_type TYPE crm_mktpl_camptype,
description TYPE crm_mktpl_camptypetx, "Added by wizard
END OF ltype_attr_struct.
DATA: lr_table TYPE REF TO crmc_mktpl_ctype,
lr_struct TYPE crmc_mktpl_ctype,
lt_tabledata TYPE TABLE OF ltype_attr_struct,
ls_tabledata LIKE LINE OF lt_tabledata,
lr_camptype TYPE REF TO cl_bsp_wd_value_node,
lr_col TYPE REF TO cl_crm_bol_bo_col.
"fetch the data.
SELECT DISTINCT
A~camp_type,
B~description
FROM TabA AS A INNER JOIN
TabB AS B ON A~camp_type = B~camp_type AND B~langu = 'EN'
INTO TABLE @lt_tabledata.
CHECK sy-subrc = 0.
"create collection object.
CREATE OBJECT lr_col.
CREATE DATA lr_table.
"create one empty value node with the required structure.
CREATE OBJECT lr_camptype
EXPORTING
iv_data_ref = lr_table.
"create value node for each record foound.
LOOP AT lt_tabledata INTO ls_tabledata.
"set the data into the value node.
lr_camptype->if_bol_bo_property_access~set_properties( is_attributes = ls_tabledata ).
"add node to the collection.
lr_col->if_bol_bo_col~add( NEW cl_bsp_wd_value_node( iv_data_ref = REF ltype_attr_struct( ls_tabledata ) ) ).
ENDLOOP.
"all records are processed. set the collection to the collection wrapper of context node to make it visible on web ui
me->typed_context->camptype->set_collection( lr_col ).
me->typed_context->camptype->build_table( ).
- 在标准组件(要从要调用弹出窗口的位置(中,为InterfaceView创建组件用法,并在按钮事件中输入代码:
gr_popup = me->comp_controller->window_manager->create_popup( iv_interface_view_name = 'ZUIC_CAMP_TYPES/MainWindow'
iv_usage_name = 'ZCUTypes'
iv_title = 'Title' ).
gr_popup->set_window_width( iv_width = 400 ).
gr_popup->set_window_height( iv_height = 600 ).
gr_popup->set_on_close_event( iv_event_name = 'PP_CTYPE_CLOSED'
iv_view = me ).
gr_popup->set_display_mode( if_bsp_wd_popup=>c_display_mode_surrounded ).
gr_popup->open( ).
附言:GR_POPUP Instance Attribute
Public
Type
Ref To
IF_BSP_WD_POPUP
。gr_popup这是类的属性。