首页 > 解决方案 > 包含来自数据库表的数据的自定义弹出窗口

问题描述

我需要显示一个弹出窗口,其中包含来自我的数据库表字段 ( 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 ).

标签: abapsap-crm

解决方案


您在循环之前只创建了一个节点 ( 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.
...

推荐阅读