P_MaterialStock_Aggr

DDL: P_MATERIALSTOCK_AGGR Type: view_entity COMPOSITE Package: ODATA_MM_IM_KPITIMESERIES

Aggreg. of Material Stock for KPI Analysis

P_MaterialStock_Aggr is a Composite CDS View that provides data about "Aggreg. of Material Stock for KPI Analysis" in SAP S/4HANA. It reads from 1 data source (I_MaterialDocumentRecord) and exposes 21 fields with key fields Material, Plant, StorageLocation, Batch, Supplier. It has 1 association to related views. Part of development package ODATA_MM_IM_KPITIMESERIES.

Data Sources (1)

SourceAliasJoin Type
I_MaterialDocumentRecord I_MaterialDocumentRecord from

Associations (1)

CardinalityTargetAliasCondition
[1..1] I_UnitOfMeasure _UnitOfMeasure $projection.MaterialBaseUnit = _UnitOfMeasure.UnitOfMeasure

Annotations (6)

NameValueLevelField
AccessControl.authorizationCheck #CHECK view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.dataClass #TRANSACTIONAL view
VDM.viewType #COMPOSITE view
VDM.private true view

Fields (21)

KeyFieldSource TableSource FieldDescription
KEY Material StockIdentifyingMaterial
KEY Plant Plant
KEY StorageLocation
KEY Batch StockIdentifyingBatch
KEY Supplier SpecialStockIdfgSupplier
KEY SDDocument SpecialStockIdfgSalesOrder
KEY SDDocumentItem SpecialStockIdfgSalesOrderItem
KEY WBSElementInternalID SpecialStockIdfgWBSElement
KEY Customer SpecialStockIdfgCustomer
KEY SpecialStockIdfgStockOwner SpecialStockIdfgStockOwner
KEY InventoryStockType InventoryStockType
KEY InventorySpecialStockType InventorySpecialStockType
KEY FiscalYearVariant FiscalYearVariant
KEY MatlDocLatestPostgDate PostingDate
KEY MaterialBaseUnit MaterialBaseUnit
KEY CostEstimate CostEstimate
CompanyCode CompanyCode
Currency CompanyCodeCurrency
MatlWrhsStkQtyInMatlBaseUnit
MatlCnsmpnQtyInMatlBaseUnit
_UnitOfMeasure _UnitOfMeasure
@AccessControl.authorizationCheck: #CHECK
@ObjectModel.usageType.sizeCategory: #XXL
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.dataClass:#TRANSACTIONAL

@VDM: {
         viewType: #COMPOSITE,
         private: true
      }

define view entity P_MaterialStock_Aggr as select from I_MaterialDocumentRecord
  association [1..1] to I_UnitOfMeasure          as _UnitOfMeasure          on $projection.MaterialBaseUnit = _UnitOfMeasure.UnitOfMeasure
{
      // All fields have to be defined as key 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 INNER JOIN is created which may multiply the result set and hence the aggregate is wrong)


      // Stock Identifier

  key StockIdentifyingMaterial                                                                                                        as Material,
  key Plant                                                                                                                           as Plant,
  key cast(StockIdfgStorageLocation as lgort_d)                                                                                       as StorageLocation,
  key StockIdentifyingBatch                                                                                                           as Batch,
  key SpecialStockIdfgSupplier                                                                                                        as Supplier,
  key SpecialStockIdfgSalesOrder                                                                                                      as SDDocument,
  key SpecialStockIdfgSalesOrderItem                                                                                                  as SDDocumentItem,
  key SpecialStockIdfgWBSElement                                                                                                      as WBSElementInternalID,
  key SpecialStockIdfgCustomer                                                                                                        as Customer,
  key SpecialStockIdfgStockOwner, 
  key InventoryStockType                                                                                                              as InventoryStockType,
  key InventorySpecialStockType                                                                                                       as InventorySpecialStockType,
      // Further Stock Groups

      @Semantics.fiscal.yearVariant: true
  key FiscalYearVariant                                                                                                               as FiscalYearVariant,
      @Semantics.businessDate.at: true
  key PostingDate                                                                                                                     as MatlDocLatestPostgDate,
      // Units

  key MaterialBaseUnit                                                                                                                as MaterialBaseUnit,
  key CostEstimate,

      CompanyCode                                                                                                                     as CompanyCode,
      CompanyCodeCurrency as Currency,

      // Quantities

      @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
      @DefaultAggregation : #SUM
      cast(sum(MatlStkChangeQtyInBaseUnit) as nsdm_stock_qty preserving type)                                                                         as MatlWrhsStkQtyInMatlBaseUnit,
      @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
      @DefaultAggregation : #SUM
      cast(sum(MatlCnsmpnQtyInMatlBaseUnit) as nsdm_consumption_qty preserving type)                                                                  as MatlCnsmpnQtyInMatlBaseUnit,
      @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
      @DefaultAggregation : #SUM
      cast(sum(case when  MatlStkChangeQtyInBaseUnit > 0 
                    then MatlStkChangeQtyInBaseUnit 
                    else cast( 0 as nsdm_stock_increase_qty) end) as nsdm_stock_increase_qty preserving type)      as MatlStkIncrQtyInMatlBaseUnit,
      @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
      @DefaultAggregation : #SUM
      cast(sum(case when  MatlStkChangeQtyInBaseUnit < 0 
                    then abs(MatlStkChangeQtyInBaseUnit) 
                    else cast( 0 as nsdm_stock_decrease_qty) end) as nsdm_stock_decrease_qty preserving type) as MatlStkDecrQtyInMatlBaseUnit,

      _UnitOfMeasure
}
where
  MaterialBaseUnit <> ''
group by
  StockIdentifyingMaterial,
  Plant,
  StockIdfgStorageLocation,
  StockIdentifyingBatch,
  SpecialStockIdfgSupplier,
  SpecialStockIdfgSalesOrder,
  SpecialStockIdfgSalesOrderItem,
  SpecialStockIdfgWBSElement,
  SpecialStockIdfgCustomer,
  SpecialStockIdfgStockOwner,
  InventoryStockType,
  InventorySpecialStockType,
  CompanyCode,
  CompanyCodeCurrency,
  FiscalYearVariant,
  PostingDate,
  MaterialBaseUnit,
  CostEstimate