P_MatStkQtyValByKeyDateBaseHdr is a Composite CDS View in SAP S/4HANA. It reads from 1 data source (I_MaterialStock_2) and exposes 18 fields with key fields Material, Plant, StorageLocation, Batch, Supplier.
@AbapCatalog.preserveKey: true@AbapCatalog.sqlViewName: 'PMATSTKQTYVALBHR'
@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #NOT_REQUIRED@ObjectModel.usageType.sizeCategory: #XXL@ObjectModel.usageType.serviceQuality: #D@ObjectModel.usageType.dataClass:#TRANSACTIONAL@ClientHandling.algorithm: #SESSION_VARIABLE@VDM.viewType: #COMPOSITE@VDM.private: true/*
Calculate the stock for a given date (summing up to that date) on storage location level
and provide the link to the material prices
Important: because for a set of stock identifiying fields a dedicated CostEstimate does exist (ornot if the movement is non-valuated)
and because there might be a mapping of various stock identifiying fields to the same CostEstimate
(e.g. all stock types with special stock type = blank do map to the same CostEstimate for a material/plant combination)
it is sufficient to work with CostEstimate askey below for cases where quantities and values on storage location level
(andnot beyond e.g. splitted up to special stock identifier or below likeon dedicated customers (consignments) are required
*/defineview P_MatStkQtyValByKeyDateBaseHdr
withparameters
P_KeyDate : calendardate
asselectfrom I_MaterialStock_2
{
key Material,
key Plant,
key StorageLocation,
key Batch,
key Supplier,
key SDDocument,
key SDDocumentItem,
key WBSElementInternalID,
key Customer,
key SpecialStockIdfgStockOwner,
key InventoryStockType,
key InventorySpecialStockType,
@Semantics.unitOfMeasure: truekey MaterialBaseUnit,
CostEstimate,
CompanyCode,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
@DefaultAggregation : #SUM
sum(MatlWrhsStkQtyInMatlBaseUnit) as MatlWrhsStkQtyInMatlBaseUnit,
_CurrentInvtryPrice,
_CompanyCode
}
where
MatlDocLatestPostgDate <= $parameters.P_KeyDate
groupby
Material,
Plant,
StorageLocation,
Batch,
Supplier,
SDDocument,
SDDocumentItem,
WBSElementInternalID,
Customer,
SpecialStockIdfgStockOwner,
InventoryStockType,
InventorySpecialStockType,
MaterialBaseUnit,
CostEstimate,
CompanyCode
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_MATERIALSTOCK_2"
],
"ASSOCIATED":
[
"I_COMPANYCODE",
"I_CURRENTMATLPRICEBYCOSTEST"
],
"BASE":
[
"I_MATERIALSTOCK_2"
],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/