P_InvtryTurnoverStockPerDay is a Consumption CDS View that provides data about "Inventory Turnover Stock Calculation" in SAP S/4HANA. It reads from 1 data source (I_MaterialDocumentRecord) and exposes 6 fields with key fields Material, Plant, MatlDocLatestPostgDate. It has 2 associations to related views.
@AbapCatalog.preserveKey: true@AbapCatalog.sqlViewName: 'PINVTOSTOCKPD'
@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #NOT_REQUIRED@ObjectModel.usageType.sizeCategory: #XXL@ObjectModel.usageType.serviceQuality: #D@ObjectModel.usageType.dataClass:#TRANSACTIONAL@ClientHandling.algorithm: #SESSION_VARIABLE@EndUserText.label: 'Inventory Turnover Stock Calculation'
@VDM.private: true@VDM.viewType: #CONSUMPTION@DataAging.noAgingRestriction: true// Copy of I_MATERIALSTOCK but this view filters also cancelled document items and also does not// consider intra plant stock transfers as stock increase / decrease. It has a reduced field set too.
// This view shall be replaced with I_MATERIALSTOCK VDM Viewas soon as this referenced
// viewis able to filter cancelled documents.
// For this reason, this viewisnot marked as VDM Viewas it is only used for Fiori.
defineview P_InvtryTurnoverStockPerDay
asselectfrom I_MaterialDocumentRecord as matdoc
association [1..1] to I_Material as _Material on $projection.Material = _Material.Material
association [1..1] to I_Plant as _Plant on $projection.Plant = _Plant.Plant
{
// All fields have to be defined askey field and quantity/value have to be summarized on this lowest level
// in addition to the annotation for aggregation (#SUM)
// This is especiall required for consumption views used by users with restricted authorization to get the right results
// (just because right now an INNERJOINis created which may multiply the result set and hence the aggregate is wrong)
//
// Stock Identifier
key StockIdentifyingMaterial as Material,
key Plant,
// Further Stock Groups
key PostingDate as MatlDocLatestPostgDate,
// Quantity and Value
@DefaultAggregation : #SUM
sum(MatlCnsmpnQtyInMatlBaseUnit) as MatlCnsmpnQtyInMatlBaseUnit,
@DefaultAggregation : #SUM
sum(
casewhen IssgOrRcvgStkIdfgPlant = '' //v2834623
or IssgOrRcvgStkIdfgPlant <> Plant
or IssgOrRcvgStkIdfgMaterial <> StockIdentifyingMaterial //^2834623
thencasewhen MatlStkChangeQtyInBaseUnit < 0 then abs(MatlStkChangeQtyInBaseUnit) else 0 end// do not consider intra-plant stock transfers here
else 0 end
) as MatlStkDecrQtyInMatlBaseUnit,
// Associations for names and descriptions
_Material,
_Plant
}
// filterall storno documents
where GoodsMovementIsCancelled <> 'X'
and GoodsMovementCancellationType <> '2'
and GoodsMovementCancellationType <> '3'
and MaterialBaseUnit <> ''
and MaterialDocumentRecordType <> 'AG_MDOC_CF'
and InventorySpecialStockType = ' '
groupby
StockIdentifyingMaterial,
Plant,
PostingDate
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_MATERIALDOCUMENTRECORD"
],
"ASSOCIATED":
[
"I_MATERIAL",
"I_PLANT"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/