abap - 包含来自数据库表的数据的自定义弹出窗口
问题描述
我需要显示一个弹出窗口,其中包含来自我的数据库表字段 ( 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.
...
推荐阅读
- mysql - MariaDB MAX 排序失败
- java - 回收查看背景颜色不工作
- node.js - Cannot destructure property 'name' of 'node' as it is null
- containerd - 带有 containerd 的 Kubernetes:http:服务器向 HTTPS 客户端提供了 HTTP 响应
- .htaccess - .htaccess mod_rewrite 以匹配语言子域
- postgresql - PostgreSQL 9.3 慢查询
- google-apps-script - 如何使用 Google appscript 将 Doc/Word 文件附加为附件?
- flutter - flutter 如何在 SliverAppBar 中显示 `floating: true` 与 Widget 高度大小一样多?(在自定义滚动视图中)
- webpack - 我从 webpack 4 迁移到 webpack 5,但我的块比以前大
- mapping - 不能使用 Mapstruct ADDER_PREFERRED 来清除带有 @MappingTarget 的目标列表