如何用ABAP读取CDS view association的数据

AG3, view name Zorder_Sys_Status.
This view has an association named _statushelp:

如何用ABAP读取CDS view association的数据

Requirement

I would like to read the guid from host view Zorder_Sys_Status together with its associated data via association _statushelp.

(1) Since there is no existing data type which holds both host view field and associated view fields, you have to create one on your own:

如何用ABAP读取CDS view association的数据

(2) Use the following syntax in ABAP code:

DATA: lt_data TYPE tt_Data.

SELECT
   guid,
   \_STATUSHELP-STATUS_KEY AS STATUS_KEY ,
   \_STATUSHELP-STATUS_TEXT AS STATUS_TEXT
 FROM
  ZORDER_SYS_STATUS
 WHERE
  ZORDER_SYS_STATUS~GUID = 'FA163E8EAB031EE6A99F824537D112A4' AND ZORDER_SYS_STATUS~STAT = 'I1002' AND \_STATUSHELP-STATUS_KEY IS NOT NULL

  INTO TABLE @lt_data.

如何用ABAP读取CDS view association的数据

By the way, when the association defined in CDS view is consumed via OPEN SQL, it will be converted to LEFT OUTER JOIN, as could be observed in SQL trace:

如何用ABAP读取CDS view association的数据
如何用ABAP读取CDS view association的数据

In ST05, select your trace record, and click this button in toolbar:

如何用ABAP读取CDS view association的数据

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
如何用ABAP读取CDS view association的数据

如何用ABAP读取CDS view association的数据如何用ABAP读取CDS view association的数据 汪子熙 博客专家 发布了6460 篇原创文章 · 获赞 623 · 访问量 103万+ 他的留言板 关注
上一篇:ABAP应用服务器的HTTP响应状态码(Status Code)


下一篇:《全栈性能Jmeter》-7JMeter常用脚本开发