Enterprise Resource Planning Blog Posts by SAP
Get insights and updates about cloud ERP and RISE with SAP, SAP S/4HANA and SAP S/4HANA Cloud, and more enterprise management capabilities with SAP blog posts.
cancel
Showing results for 
Search instead for 
Did you mean: 
Zhehui_Xia
Product and Topic Expert
Product and Topic Expert
0 Kudos
757

我们将发布一系列在 SAP S/4HANA Cloud, public edition 的 ABAP 环境中的开发案例。本篇是该系列的第三个开发案例,使用 ADT 自定义 CDS 视图。在我们开始之前,您可以阅读这篇 Blog 来了解我们这一系列的全部案例,希望我们的 Blog 可以为您在公有云三系统的探索中带来一些有价值的洞察。接下来就让我们开始吧!

1     场景需求

为了将交付、定价、税收和成本信息整合到一个数据模型中,并在嵌入式SAC故事中以表格形式进行可视化,需要创建一个分层的数据模型。在3SL系统之前可以通过Key User Extension 来生成CDS,但是其灵活度远不如直接在ADT中使用Coding开发出来的CDS

1.1      数据来源I_DeliveryDocumentITEM

在ADT中打开 I_DeliveryDocumentITEM Delivery Document Item,当前CDS主要从Lips取值,并且关联到了许多其他的CDS。

           

 

Picture2.png

 

           Picture2.png

 

 

 

1.2      字段定义

直接从底层CDS引用的字段如下:

Output Field

Field Desc

FieldPath

DeliveryDocument

交货

I_DeliveryDocumentItem.DeliveryDocument

DeliveryDocumentItem

项目

I_DeliveryDocumentItem.DeliveryDocumentItem

ActualDeliveredQtyInBaseUnit

销售数量

I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit

BaseUnit

计量单位

I_DeliveryDocumentItem.BaseUnit

Product

物料编码

I_DeliveryDocumentItem.Product

ActualGoodsMovementDate

实际货物移动日期

I_DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate

SoldToParty

客户(外部)

I_DeliveryDocumentItem._DeliveryDocument.SoldToParty

DeliveryDocumentType

交货类型

I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType

ReferenceSDDocumentItem

参考项目

I_DeliveryDocumentItem.ReferenceSDDocumentItem

ReferenceSDDocument

参考凭证

I_DeliveryDocumentItem.ReferenceSDDocument

CustomerName_Sold

客户名称(外部)

I_DeliveryDocumentItem._DeliveryDocument._SoldToParty.CustomerName

ReferenceSDDocumentCategory

参考凭证类别

I_DeliveryDocumentItem.ReferenceSDDocumentCategory

SalesDocumentDate

凭证日期

I_DeliveryDocumentItem._ReferenceSDDocument.SalesDocumentDate

CompanyCode

公司代码

I_DeliveryDocumentItem._DeliveryDocument._SalesOrganization.CompanyCode

SalesOrganization

销售组织

I_DeliveryDocumentItem._DeliveryDocument.SalesOrganization

ValuationArea

评估范围

I_DeliveryDocumentItem._Plant.ValuationArea

Currency

公司代码货币

I_DeliveryDocumentItem._DeliveryDocument._SalesOrganization._CompanyCode.Currency

CustomerName_Ship

客户名称(公司间)

I_DeliveryDocumentItem._DeliveryDocument._ShipToParty.CustomerName

ShipToParty

客户(公司间)

I_DeliveryDocumentItem._DeliveryDocument.ShipToParty

TransactionCurrency

凭证货币

I_DeliveryDocumentItem._ReferenceSalesDocumentItem.TransactionCurrency

  新追加的计算字段如下:

Field

Field Desc

Formula

 Customer                    

 客户                        

 case when
   I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then I_DeliveryDocumentItem._DeliveryDocument.SoldToParty
else I_DeliveryDocumentItem._DeliveryDocument.ShipToParty
end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         

 CustomerName                

 客户名称                    

 case when
  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then I_DeliveryDocumentItem._DeliveryDocument._SoldToParty.CustomerName
else I_DeliveryDocumentItem._DeliveryDocument._ShipToParty.CustomerName
end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

 SO                          

销售订单                    

 case when
  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then I_DeliveryDocumentItem.ReferenceSDDocument
else ''
end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

 SOITEM                      

销售订单行项目              

 case when
  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then I_DeliveryDocumentItem.ReferenceSDDocumentItem
else ''
end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

 PO                           

采购订单                    

 case when
  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then ''
else I_DeliveryDocumentItem.ReferenceSDDocument
end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

 POITEM                      

采购订单行项目              

 case when `  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'`  OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'`then ''`else I_DeliveryDocumentItem.ReferenceSDDocumentItem`end                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

QuantitySold

销售数量(带符号)

case when

  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'

  or  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'

then

  -1 * I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit

else

  I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit

end

Sign

销售数量符号

case when

  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'

  or  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'

then -1

else 1

end

 

1.3      定义取值范围

Add a filter based on the following expression

I_DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate >= $parameters.P_MONTH_STARTDATE

 AND I_DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate <= $parameters.P_MONTH_ENDDATE

 AND(

    I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'

OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'

OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'NLCC'

OR  I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'

)

AND I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit > 0

2     功能实现

2.1      创建Data Definition

首先创建一个Package,右键选择ZLOCAL > New > ABAP Package

 

 

Picture3.png

 

 

填写好PackageNameDescription,勾选Add to favorite packages方便后续查找。点击Next

 

 

Picture4.png

 

 

点击Next > Finish完成Package的创建。

 

Picture5.png

 

 

右键创建好的Package,选择Other ABAP Repository Object

 

 

Picture6.png

 

 

输入并选中Data Definition,点击Next进入下一步。

 

 

Picture7.png

 

 

输入I_DELIVERYDOCUMENTITEM进行搜索并选中,点击OK点击Next > Next

 

 

Picture8.png

 

 

            选中Define View Entity,点击Finish完成CDS View的创建。

 

Picture9.png

 

2.2      实现Data Definition

按照字段定义实现CDS内容。

 

Picture10.png

 

 

 

            新追加的计算字段。

  

 

Picture11.png

 

 

            定义取值范围。

 

 

Picture12.png

 

 

            完成CDS View内容的填写后,保存点击上方菜单栏的🕯激活,使类生效。

 

Picture13.png

 

 

2.3      查看Data Definition

右键创建的Data Definition,选择Show In > Properties

 

 

Picture14.png

 

 

选中API State,再点击Add Release Contract

 

Picture15.png

 

 

 

选择Use System-Internally (Contract C1),点击Next

 

 

Picture16.png

 

 

确保Use in Cloud DevelopmentUse in Key User Apps都被勾选,点击Next

 

 

Picture17.png

 

 

 

再点击Next > Finish完成Add Release Contract

 

 

Picture18.png

 

 

ADT中可以使用Data Preview来查看当前CDS的内容。连接到客户端100,右键创建的CDS View,点击Open With > Data Preview

 

Picture14.png

 

 

 

            P_MONTH_STARTDATEP_MONTH_ENDDATE后方按照YYYYMMDD的格式输入8位数字作为日期参数,点击Open Data Preview查看数据。

 

 

Picture20.png

 

            根据输入的日期条件,会显示出符合条件的数据。

 

Picture21.png

 

 

 

点击Parameter可以修改输入的参数,重新进行数据的筛选。

 

Picture22.png

 

 

 

点击SQL Console可以查看进行查询的SQL语句,进行更改后点击Run会重新执行。

Picture23.png

 

3. 结语


以上就是本篇开发案例的全部内容。希望该案例能让你更了解如三系统开发拓展的流程,希望您有所收获!

如果您对本文有任何的建议和想法,欢迎在评论区提出,期待与您一起交流。如果本文对您有任何帮助,欢迎您关注我的个人账号,期待我们在下一篇博文再见!