zl程序教程

您现在的位置是:首页 >  工具

当前栏目

How to resolve ASSERTION_FAILED error when you register the odata service expose

Failed Error to The Service How when you
2023-09-14 09:02:52 时间

Description

When you try to register an Odata service exposed by a CDS view in tcode /IWFND/MAINT_SERVICE, you meet with runtime error ASSERTION_FAILED as displayed in picture below.

Keywords

ASSERTION_FAILED, @OData.publish

Root cause

If you debug in the backend, you can find the exception is raised in line 9.

The field causing this exception, “STAT”, does not come from the consumption view itself but from the foreign view zorder_sys_status.
When we comment out line 22~24, the service registration could successfully be done.

Solution

在当前view上重新创建一个新的consumption view.

这样做的目的是确保最后用于生成odata service的consumption view A, 其字段全部来自 view B.
比较correction之前的实现: consumption view A,其字段部分来自view B, 部分来自view C, 这种scenario并不被SADL 框架支持。
original view:

@AbapCatalog.sqlViewName: 'ziorder'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'order consumption view'

define view Z_i_Order_View as select from Z_C_Order_Item
inner join Zorder_Sys_Status as _sys_status
on Z_C_Order_Item.guid = _sys_status.guid
{
   key Z_C_Order_Item.guid as order_guid,
   Z_C_Order_Item.object_id,
   Z_C_Order_Item.description,
   _sys_status.stat,
   _sys_status.txt04,
   _sys_status.txt30,
   @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
   Z_C_Order_Item._Item
}

new created consumption view:

@AbapCatalog.sqlViewName: 'zcorderview'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'service order consumption view'

@OData.publish: true
@ObjectModel: {
   type: #CONSUMPTION,
   compositionRoot,
   createEnabled,  
   deleteEnabled,
   updateEnabled
}

define view Z_C_Service_Order_View as select from Z_i_Order_View {
  key Z_i_Order_View.order_guid as order_guid,
  Z_i_Order_View.object_id,
  Z_i_Order_View.description,
  Z_i_Order_View.stat,
  Z_i_Order_View.txt04,
  Z_i_Order_View.txt30,
  @ObjectModel.association.type: [#TO_COMPOSITION_CHILD]
  Z_i_Order_View._Item

}

After correction it works with the following url:
https://jerry:44354/sap/opu/odata/sap/Z_C_SERVICE_ORDER_VIEW_CDS/Z_C_Service_Order_View(order_guid=guid’00163EA7-2000-1ED2-85EF-EFADF195A1B2’)

要获取更多Jerry的原创文章,请关注公众号"汪子熙":