As you can know from the title, this is the 3rd case of our series. Before we start this blog, I’d like to suggest that you can read other blogs in our series.
Case 1 – Enhanced Goods Receipt Process
Case 2 – Customizing Sales Order App
Fine, let’s start our journey!
1. Scenario Requirements
To consolidate delivery, pricing, tax, and cost information into one data model and visualize it in tabular form in an embedded SAC story, you need to create a hierarchical data model. CDS Views can be generated via the Key User Extension before the 3SL system, but it is much less flexible than those developed directly using Coding in ADT.
1.1 Data Source I_DeliveryDocumentITEM
Open I_DeliveryDocumentITEM (Delivery Document Item) in ADT, the current CDS View mainly gets values from Lips and is associated to many other CDS Views.
1.2 Field Definition
The fields referenced directly from the underlying CDS are as follows:
Output Field | Field Desc | FieldPath |
DeliveryDocument | Delivery | I_DeliveryDocumentItem.DeliveryDocument |
DeliveryDocumentItem | Item | I_DeliveryDocumentItem.DeliveryDocumentItem |
ActualDeliveredQtyInBaseUnit | Sales Quantity | I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit |
BaseUnit | Unit of Measure | I_DeliveryDocumentItem.BaseUnit |
Product | Material Number | I_DeliveryDocumentItem.Product |
ActualGoodsMovementDate | Actual Goods Movement Date | I_DeliveryDocumentItem._DeliveryDocument.ActualGoods
MovementDate |
SoldToParty | Customer (External) | I_DeliveryDocumentItem._DeliveryDocument.SoldToParty |
DeliveryDocumentType | Delivery Type | I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType |
ReferenceSDDocumentItem | Reference Item | I_DeliveryDocumentItem.ReferenceSDDocumentItem |
ReferenceSDDocument | Reference Document | I_DeliveryDocumentItem.ReferenceSDDocument |
CustomerName_Sold | Customer Name (External) | I_DeliveryDocumentItem._DeliveryDocument._SoldToParty.CustomerName |
ReferenceSDDocumentCategory | Reference Document Category | I_DeliveryDocumentItem.ReferenceSDDocumentCategory |
SalesDocumentDate | Document Date | I_DeliveryDocumentItem._ReferenceSDDocument.SalesDocumentDate |
CompanyCode | Company Code | I_DeliveryDocumentItem._DeliveryDocument._SalesOrganization.CompanyCode |
SalesOrganization | Sales Organization | I_DeliveryDocumentItem._DeliveryDocument.SalesOrganization |
ValuationArea | Valuation Area | I_DeliveryDocumentItem._Plant.ValuationArea |
Currency | Company Code Currency | I_DeliveryDocumentItem._DeliveryDocument._SalesOrganization._
CompanyCode.Currency |
CustomerName_Ship | Account Name (Intercompany) | I_DeliveryDocumentItem._DeliveryDocument._ShipToParty.CustomerName |
ShipToParty | Customer (Intercompany) | I_DeliveryDocumentItem._DeliveryDocument.ShipToParty |
TransactionCurrency | Document Currency | I_DeliveryDocumentItem._ReferenceSalesDocumentItem.TransactionCurrency |
The calculated fields for the new append are as follows:
Field | Field Desc | Formula |
Customer | 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 | Customer Name | 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 | Sales Order | case when I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LF’ OR I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’ then I_DeliveryDocumentItem.ReferenceSDDocument else ” end |
SOITEM | Sales Order Line Item | case when I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LF’ OR I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’ then I_DeliveryDocumentItem.ReferenceSDDocumentItem else ” end |
PO | Purchase Order | case when I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LF’ OR I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’ then ” else I_DeliveryDocumentItem.ReferenceSDDocument end |
POITEM | Purchase Order Line Item | case when ` I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LF’` OR I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’`
then ”`else I_DeliveryDocumentItem.ReferenceSDDocumentItem` end |
QuantitySold | Sales quantity (with sign) | case when
I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’ or I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LLR’ then -1 * I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit else I_DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit end |
Sign | Sales Quantity Sign | case when
I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LR’ or I_DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = ‘LLR’ then -1 else 1 end |
1.3 Define Value Ranges
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. Functional Realization
2.1 Create a Data Definition
First create a Package, right-click ZLOCAL > New > ABAP Package.
Fill in the Name and Description of the Package and check Add to favorite packages for easy follow-up. Click Next.
Click Next > Finish to complete the package creation.
Right click on the created Package and choose Other ABAP Repository Object.
Enter and select Data Definition and click Next to proceed to the next step.
Enter I_DELIVERYDOCUMENTITEM to search and select, click OK. Click Next > Next.
Select Define View Entity and click Finish to finish creating CDS View.
2.2 Implementing Data Definition
Implement CDS View content as per field definition.
define view entity ZZA3002620_BaseDelivDoc
with parameters
P_MONTH_STARTDATE : abap.dats,
P_MONTH_ENDDATE : abap.dats
as select from I_DeliveryDocumentItem as DeliveryDocumentItem
{
key DeliveryDocumentItem.DeliveryDocument,
key DeliveryDocumentItem.DeliveryDocumentItem,
@Semantics.quantity.unitOfMeasure: 'BaseUnit'
@Aggregation.default: #SUM
DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit,
DeliveryDocumentItem.BaseUnit as BaseUnit,
DeliveryDocumentItem.Product as Product,
DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate as ActualGoodsMovementDate,
DeliveryDocumentItem._DeliveryDocument.SoldToParty as SoldToParty,
DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType as DeliveryDocumentType,
DeliveryDocumentItem.ReferenceSDDocumentItem as ReferenceSDDocumentItem,
DeliveryDocumentItem.ReferenceSDDocument as ReferenceSDDocument,
@Semantics.text:true
DeliveryDocumentItem._DeliveryDocument._SoldToParty.CustomerName as CustomerName_Sold,
DeliveryDocumentItem.ReferenceSDDocumentCategory as ReferenceSDDocumentCategory,
DeliveryDocumentItem._ReferenceSDDocument.SalesDocumentDate as SalesDocumentDate,
DeliveryDocumentItem._DeliveryDocument._SalesOrganization.CompanyCode as CompanyCode,
DeliveryDocumentItem._DeliveryDocument.SalesOrganization as SalesOrganization,
DeliveryDocumentItem._Plant.ValuationArea as ValuationArea,
DeliveryDocumentItem._DeliveryDocument._SalesOrganization._CompanyCode.Currency as Currency,
@Semantics.text:true
DeliveryDocumentItem._DeliveryDocument._ShipToParty.CustomerName as CustomerName_Ship,
DeliveryDocumentItem._DeliveryDocument.ShipToParty as ShipToParty,
DeliveryDocumentItem._ReferenceSalesDocumentItem.TransactionCurrency as TransactionCurrency,
...
}
...
New appended calculated field.
/* Calcution */
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then DeliveryDocumentItem._DeliveryDocument.SoldToParty
else DeliveryDocumentItem._DeliveryDocument.ShipToParty
end as Customer,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then DeliveryDocumentItem._DeliveryDocument._SoldToParty.CustomerName
else DeliveryDocumentItem._DeliveryDocument._ShipToParty.CustomerName
end as CustomerName,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then DeliveryDocumentItem.ReferenceSDDocument
else ''
end as SO,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then DeliveryDocumentItem.ReferenceSDDocumentItem
else '000000'
end as SOITEM,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then ''
else DeliveryDocumentItem.ReferenceSDDocument
end as po,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
then '000000'
else DeliveryDocumentItem.ReferenceSDDocumentItem
end as poitem,
@Semantics.quantity.unitOfMeasure: 'BaseUnit'
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'
then -1 * DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit
else DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit
end as QuantitySold,
case when DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'
then -1
else 1
end as Sign,
Defines the range of values.
select from I_DeliveryDocumentItem as DeliveryDocumentItem
{
...
}
where
DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate >= $parameters.P_MONTH_STARTDATE
and DeliveryDocumentItem._DeliveryDocument.ActualGoodsMovementDate <= $parameters.P_MONTH_ENDDATE
and(
DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LF'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LR'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'NLCC'
or DeliveryDocumentItem._DeliveryDocument.DeliveryDocumentType = 'LLR'
)
and DeliveryDocumentItem.ActualDeliveredQtyInBaseUnit > 0
When you are finished filling out the CDS View content, save it and click 🕯 in the upper menu bar to activate the class.
2.3 View Data Definition
Right-click the created Data Definition and choose Show In > Properties.
Select API State and click Add Release Contract.
Select Use System-Internally (Contract C1) and click Next.
Make sure that Use in Cloud Development and Use in Key User Apps are both checked and click Next.
Then click Next > Finish to complete Add Release Contract.
You can use Data Preview in ADT to view the contents of the current CDS. Connect to client 100, right-click the CDS view you created, and click Open With > Data Preview.
After P_MONTH_STARTDATE and P_MONTH_ENDDATE, enter 8 digits as the date parameter in the format YYYYMMDD and click Open Data Preview to view the data.
Based on the entered date criteria, the eligible data is displayed.
Click Parameter to modify the parameters entered to filter the data again.
Click SQL Console to view SQL statements that are being queried, and click Run to re-execute them after making the changes.
3. More Information on SAP S/4HANA Cloud, Public Edition
- SAP S/4HANA Cloud, public edition, release info here
- Latest SAP S/4HANA Cloud, public edition, release blog posts here and previous release highlights here
- Product videos on our SAP S/4HANA Cloud, public edition and SAP S/4HANA YouTube playlist
- SAP S/4HANA PSCC Digital Enablement Wheel here
- Early Release Webinar Series here
- Inside SAP S/4HANA Podcast here
- openSAP Microlearnings for SAP S/4HANA here
- Best practices for SAP S/4HANA Cloud, public edition, here
- SAP S/4HANA Cloud, public edition, Community: here
- Feature Scope Description here
- What’s New here
- Help Portal Product Page here
- SAP S/4HANA Cloud ABAP Environment Community here
Follow us via @SAP and #S4HANA or follow Zhehui Xia