P_MaterialStockAggrMvt

DDL: P_MATERIALSTOCKAGGRMVT SQL: PMATSTOCKAGGRMVT Type: view COMPOSITE

P_MaterialStockAggrMvt is a Composite CDS View in SAP S/4HANA. It reads from 1 data source (I_MaterialDocumentRecord) and exposes 25 fields with key fields Material, Plant, StorageLocation, Batch, Supplier. It has 1 association to related views.

Data Sources (1)

SourceAliasJoin Type
I_MaterialDocumentRecord I_MaterialDocumentRecord from

Parameters (1)

NameTypeDefault
P_InventoryConsumptionGroup inventory_consumption_group

Associations (1)

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

Annotations (10)

NameValueLevelField
AbapCatalog.preserveKey true view
AbapCatalog.sqlViewName PMATSTOCKAGGRMVT view
AbapCatalog.compiler.compareFilter true view
AccessControl.authorizationCheck #CHECK view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.dataClass #TRANSACTIONAL view
ClientHandling.algorithm #SESSION_VARIABLE view
VDM.viewType #COMPOSITE view
VDM.private true view

Fields (25)

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
KEY GoodsMovementType GoodsMovementType
InventoryConsumptionGroup
CompanyCode CompanyCode
Currency CompanyCodeCurrency
MatlWrhsStkQtyInMatlBaseUnit
MatlCnsmpnQtyInMatlBaseUnit
MatlStkIncrQtyInMatlBaseUnit
MatlStkDecrQtyInMatlBaseUnit
_UnitOfMeasure _UnitOfMeasure
@AbapCatalog.preserveKey: true
@AbapCatalog.sqlViewName: 'PMATSTOCKAGGRMVT'

@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #CHECK
@ObjectModel.usageType.sizeCategory: #XXL
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.dataClass:#TRANSACTIONAL
@ClientHandling.algorithm: #SESSION_VARIABLE

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

define view P_MaterialStockAggrMvt 
       with parameters P_InventoryConsumptionGroup : inventory_consumption_group
       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

      @Semantics.unitOfMeasure
  key MaterialBaseUnit                                                                                                                as MaterialBaseUnit,
  key CostEstimate,
  key GoodsMovementType,

      $parameters.P_InventoryConsumptionGroup                                                                                         as InventoryConsumptionGroup,
      
      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 0 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 0 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,
  GoodsMovementType

/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_MATERIALDOCUMENTRECORD"
],
"ASSOCIATED":
[
"I_UNITOFMEASURE"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/