I_MatlDocWeightedStock

DDL: I_MATLDOCWEIGHTEDSTOCK Type: view_entity COMPOSITE Package: MM_IM_VDM_STOCK

Weighted stock for average calc

I_MatlDocWeightedStock is a Composite CDS View that provides data about "Weighted stock for average calc" in SAP S/4HANA. It reads from 1 data source (I_MaterialDocumentRecord) and exposes 23 fields with key fields StockIdentifyingMaterial, Plant, MaterialDocumentYear, MaterialDocument, MaterialDocumentItem. It has 1 association to related views. Part of development package MM_IM_VDM_STOCK.

Data Sources (1)

SourceAliasJoin Type
I_MaterialDocumentRecord I_MaterialDocumentRecord from

Parameters (2)

NameTypeDefault
P_StartDate sydate
P_EndDate sydate

Associations (1)

CardinalityTargetAliasCondition
[0..1] I_Purreqvaluationarea _ValuationArea $projection.valuationarea = _ValuationArea.ValuationArea

Annotations (8)

NameValueLevelField
AccessControl.authorizationCheck #NOT_REQUIRED view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.serviceQuality #B view
ObjectModel.usageType.dataClass #TRANSACTIONAL view
EndUserText.label Weighted stock for average calc view
VDM.private false view
VDM.viewType #COMPOSITE view
VDM.lifecycle.contract.type #SAP_INTERNAL_API view

Fields (23)

KeyFieldSource TableSource FieldDescription
KEY StockIdentifyingMaterial StockIdentifyingMaterial
KEY Plant Plant
KEY MaterialDocumentYear MaterialDocumentYear
KEY MaterialDocument MaterialDocument
KEY MaterialDocumentItem MaterialDocumentItem
KEY InventorySpecialStockType InventorySpecialStockType
KEY InventoryStockType InventoryStockType
KEY CostEstimate CostEstimate
CompanyCode CompanyCode
InventoryValuationType InventoryValuationType
PostingDate PostingDate
GoodsMovementType GoodsMovementType
ReversedMaterialDocument ReversedMaterialDocument
GoodsMovementIsCancelled GoodsMovementIsCancelled
GoodsMovementCancellationType GoodsMovementCancellationType
ValuationArea
MaterialBaseUnit MaterialBaseUnit
5StartDateassumedatearlymorning
fltpendasWgtdPerdStkChgQtyInBaseUnit
_Plant _Plant
_ValuationArea _ValuationArea
_MaterialBaseUnit _MaterialBaseUnit
_CompanyCode _CompanyCode
@AccessControl.authorizationCheck: #NOT_REQUIRED

@ObjectModel.usageType.sizeCategory: #XXL
@ObjectModel.usageType.serviceQuality: #B
@ObjectModel.usageType.dataClass:#TRANSACTIONAL
@EndUserText.label: 'Weighted stock for average calc'
@VDM: {
        private: false,
        viewType: #COMPOSITE,
        lifecycle.contract.type: #SAP_INTERNAL_API
        }
define view entity I_MatlDocWeightedStock 
with parameters  
    P_StartDate: sydate, 
    @Environment.systemField: #SYSTEM_DATE
    P_EndDate: sydate
as select from I_MaterialDocumentRecord 

  association [0..1] to I_Purreqvaluationarea as _ValuationArea on $projection.valuationarea = _ValuationArea.ValuationArea

{
  key StockIdentifyingMaterial, 
  key Plant,
  key MaterialDocumentYear,
  key MaterialDocument,
  key MaterialDocumentItem,
  key InventorySpecialStockType,
  key InventoryStockType,
  key CostEstimate,
  CompanyCode,
  InventoryValuationType,
  PostingDate,
  GoodsMovementType,
  
  ReversedMaterialDocument,
  GoodsMovementIsCancelled,
  GoodsMovementCancellationType,
  
  I_MaterialDocumentRecord._Plant.ValuationArea,
  
  MaterialBaseUnit,
  
  -- how much weighted time has the posting be effective within the period?
  -- postings assumed at noon --> 0.5
  -- StartDate assumed at early morning, EndDate assumed at late evening --> 1
  -- Perform aggration on top of this view and calculate the SUM over the
  -- weighted property PeriodWeightedStockQuantity to get the average stock
  -- quantity for the aggregation level and the defined period.
  -- This allows HANA to calculate the Average Stock Quantity in linear time.
  @DefaultAggregation:#NONE
  @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
  case
    when PostingDate < $parameters.P_StartDate then cast(MatlStkChangeQtyInBaseUnit as abap.fltp)
    when PostingDate > $parameters.P_EndDate then cast(0 as abap.fltp)
    else cast(MatlStkChangeQtyInBaseUnit as abap.fltp)
        * (1.0 + cast(dats_days_between(PostingDate, $parameters.P_EndDate) as abap.fltp))
        / (1.0 + cast(dats_days_between($parameters.P_StartDate, $parameters.P_EndDate) as abap.fltp))
  end as WgtdPerdStkChgQtyInBaseUnit,
  
  _Plant,
  _ValuationArea,
  _MaterialBaseUnit,
  _CompanyCode
}