1

我创建了一个 CDS 视图,如下所示:

define view YGAC_I_REQUEST_ROLE
  with parameters
    pm_req_id    : grfn_guid,
    @Consumption.defaultValue: 'ROL'
    pm_item_type : grac_prov_item_type,
    @Consumption.defaultValue: 'AP'
    pm_approval  : grac_approval_status
  as select from YGAC_I_REQ_PROVISION_ITEM as provitem

  association [1..1] to YGAC_I_ROLE as _Role on _Role.RoleId = provitem.ProvisionItemId

  association [1..*] to YGAC_I_ROLE_RS as _Relation on _Relation.RoleId1 = provitem.ProvisionItemId

{
  key ReqId,
  key ReqIdItem,
      Connector,
      ProvisionItemId,
      ActionType,
      ValidFrom,
      ValidTo,

      _Role.RoleId,
      _Role.RoleName,
      _Role.RoleType,


      _Role,
      _Relation
}
where
      ReqId             = $parameters.pm_req_id
  and ProvisionItemType = $parameters.pm_item_type
  and ApprovalStatus    = $parameters.pm_approval

然后我在ABAP中消费了:

  SELECT
    FROM ygac_i_request_role( pm_req_id = @lv_test,
                              pm_item_type = @lv_item_type,
                              pm_approval = @lv_approval
                            )
    FIELDS reqid,
           connector,
           provisionitemid
  INTO TABLE @DATA(lt_result).

如何_Relation根据上面的选择获取列表。

4

1 回答 1

1

这在 ABAP SQL 查询中通常是不可能的:

SELECT m~*, kt~*
  FROM mara AS m
  JOIN makt AS kt
... 

这与 CDS 关联的整个想法相矛盾,因为它们的创建是为了按需加入并减少对数据库的冗余调用。获取所有字段否定了“惰性连接”的整个想法。

但是,FROM 子句中还有另一种语法,它由路径表达式启用,允许完全查询下划线关联,也可以通过单独的元素查询。这是如何

SELECT *
  FROM ygac_i_request_role( pm_req_id = @lv_test )
       \_Role AS role
  INTO TABLE @DATA(lt_result).

这会将所有关联字段提取_Role到内部表中。

注意:请记住,不可能同时获取当前视图的所有已发布关联,每个查询只能获取一个路径。

可能的解决方法是使用 JOIN

SELECT *
  FROM ygac_i_request_role AS main
  JOIN ygac_i_request_role
       \_Role AS role
    ON main~ProvisionItemId = role~RoleId
  JOIN ygac_i_request_role
       \_Relation AS relation
    ON main~ProvisionItemId = relation~RoleId1
  INTO TABLE @DATA(lt_table).

这会为每个连接关联创建具有专用结构的深层结构类型,如下所示:

在此处输入图像描述

如果您对任务的这种结构不满意,lt_table应静态声明以将所有字段以平坦的方式放置

TYPES BEGIN OF ty_table.
        INCLUDE TYPE ygac_i_request_role.
        INCLUDE TYPE ygac_i_role.
        INCLUDE TYPE ygac_i_role_rs.
TYPES END OF ty_table.
于 2020-06-01T08:45:04.977 回答