@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Stock on interval boundry quantity basic view branch 2'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #D,
sizeCategory: #XXL,
dataClass: #MIXED
}
@VDM:
{
viewType: #COMPOSITE,
private: true
}
define view entity P_STKONINTERVALBOUNDARYBASIC12
with parameters
@Environment.systemField: #SYSTEM_DATE
P_StartDate : sydate,
@Environment.systemField: #SYSTEM_DATE
P_EndDate : sydate,
P_GroupByField : nsdm_groupby_fields
as select from I_MaterialDocumentRecord
{
key StockIdentifyingMaterial,
key Plant,
key StockIdfgStorageLocation,
key StockIdentifyingBatch,
key SpecialStockIdfgSupplier,
key SpecialStockIdfgSalesOrder,
key SpecialStockIdfgSalesOrderItem,
key SpecialStockIdfgWBSElement,
key SpecialStockIdfgCustomer,
key InventorySpecialStockType,
key InventoryStockType,
key SpecialStockIdfgStockOwner,
key ResourceID,
// Further Stock Groups
key CompanyCode,
key CostEstimate,
// fields for derivation of stock values
key InventoryValuationType,
key IsSupplierStockValuation,
key InventorySpecialStockValnType,
// unit
key MaterialBaseUnit,
key CompanyCodeCurrency as Currency,
// Quantities
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
cast (0 as nsdm_stock_qty) as MatlWrhsStkQtyOnStartDate,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
MatlStkChangeQtyInBaseUnit as MatlWrhsStkQtyOnEndDate,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
case when MatlStkChangeQtyInBaseUnit > 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as MatlStkIncrQtyInMatlBaseUnit,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
case when MatlStkChangeQtyInBaseUnit < 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as MatlStkDecrQtyInMatlBaseUnit,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
case when MatlStkChangeQtyInBaseUnit > 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as NetGoodsRcptQtyInBaseUnit,
@Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
case when MatlStkChangeQtyInBaseUnit < 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as NetGoodsIssueQtyInBaseUnit
}
where
MaterialBaseUnit <> '' // value only material does not have meins
// no transfer posting in any cases
and InventoryStockType <> ''
and IssuingOrReceivingStockType = ''
and PostingDate <= $parameters.P_EndDate
and PostingDate > $parameters.P_StartDate
union all
select from I_MaterialDocumentRecord
{
key StockIdentifyingMaterial,
key Plant,
key StockIdfgStorageLocation,
key StockIdentifyingBatch,
key SpecialStockIdfgSupplier,
key SpecialStockIdfgSalesOrder,
key SpecialStockIdfgSalesOrderItem,
key SpecialStockIdfgWBSElement,
key SpecialStockIdfgCustomer,
key InventorySpecialStockType,
key InventoryStockType,
key SpecialStockIdfgStockOwner,
key ResourceID,
// Further Stock Groups
key CompanyCode,
key CostEstimate,
// fields for derivation of stock values
key InventoryValuationType,
key IsSupplierStockValuation,
key InventorySpecialStockValnType,
// unit
key MaterialBaseUnit,
key CompanyCodeCurrency as Currency,
// Quantities
cast (0 as nsdm_stock_qty) as MatlWrhsStkQtyOnStartDate,
MatlStkChangeQtyInBaseUnit as MatlWrhsStkQtyOnEndDate,
case when MatlStkChangeQtyInBaseUnit > 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as MatlStkIncrQtyInMatlBaseUnit,
case when MatlStkChangeQtyInBaseUnit < 0
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty) end as MatlStkDecrQtyInMatlBaseUnit,
case when MatlStkChangeQtyInBaseUnit > 0
and
(
((instr($parameters.P_GroupByField, 'Material') > 0 ) and (StockIdentifyingMaterial <> IssgOrRcvgStkIdfgMaterial))
or ((instr($parameters.P_GroupByField, 'Plant') > 0 ) and (Plant <> IssgOrRcvgStkIdfgPlant))
or ((instr($parameters.P_GroupByField, 'StorageLocation') > 0 ) and (StockIdfgStorageLocation <> IssgOrRcvgStkIdfgStorLoc))
or ((instr($parameters.P_GroupByField, 'Batch') > 0 ) and (StockIdentifyingBatch <> IssgOrRcvgStkIdfgBatch))
or ((instr($parameters.P_GroupByField, 'Supplier') > 0 ) and (SpecialStockIdfgSupplier <> IssgOrRcvgSpclStkIdfgSupplier))
or ((instr($parameters.P_GroupByField, 'SalesOrder') > 0 ) and (SpecialStockIdfgSalesOrder <> IssgOrRcvgSalesOrder))
or ((instr($parameters.P_GroupByField, 'SlsOrdItm') > 0 ) and ( SpecialStockIdfgSalesOrderItem <> IssgOrRcvgSalesOrderItem ))
or ((instr($parameters.P_GroupByField, 'WBSElementInternalID') > 0 ) and ( SpecialStockIdfgWBSElement <> IssgOrRcvgWBSElement ))
or ((instr($parameters.P_GroupByField, 'Customer') > 0 ) and ( SpecialStockIdfgCustomer <> IssgOrRcvgSpclStkIdfgCustomer ))
or ((instr($parameters.P_GroupByField, 'SpclStkType') > 0 ) and ( InventorySpecialStockType <> IssgOrRcvgStkIdfgSpclStkType ))
or ((instr($parameters.P_GroupByField, 'InventoryStockType') > 0 ) and ( InventoryStockType <> IssuingOrReceivingStockType ))
or ((instr($parameters.P_GroupByField, 'SpclStkOwnr') > 0 ) and ( SpecialStockIdfgStockOwner <> IssgOrRcvgSpclStkIdfgStkOwner ))
or ((instr($parameters.P_GroupByField, 'ResourceID') > 0 ) and ( ResourceID <> IssgOrRcvgResourceID ))
or ((instr($parameters.P_GroupByField, 'InventoryValuationType') > 0 ) and ( InventoryValuationType <> IssuingOrReceivingValType ))
)
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty)
end as NetGoodsRcptQtyInBaseUnit,
case when MatlStkChangeQtyInBaseUnit < 0
and
(
((instr($parameters.P_GroupByField, 'Material') > 0 ) and (StockIdentifyingMaterial <> IssgOrRcvgStkIdfgMaterial))
or ((instr($parameters.P_GroupByField, 'Plant') > 0 ) and (Plant <> IssgOrRcvgStkIdfgPlant))
or ((instr($parameters.P_GroupByField, 'StorageLocation') > 0 ) and (StockIdfgStorageLocation <> IssgOrRcvgStkIdfgStorLoc))
or ((instr($parameters.P_GroupByField, 'Batch') > 0 ) and (StockIdentifyingBatch <> IssgOrRcvgStkIdfgBatch))
or ((instr($parameters.P_GroupByField, 'Supplier') > 0 ) and (SpecialStockIdfgSupplier <> IssgOrRcvgSpclStkIdfgSupplier))
or ((instr($parameters.P_GroupByField, 'SalesOrder') > 0 ) and (SpecialStockIdfgSalesOrder <> IssgOrRcvgSalesOrder))
or ((instr($parameters.P_GroupByField, 'SlsOrdItm') > 0 ) and ( SpecialStockIdfgSalesOrderItem <> IssgOrRcvgSalesOrderItem ))
or ((instr($parameters.P_GroupByField, 'WBSElementInternalID') > 0 ) and ( SpecialStockIdfgWBSElement <> IssgOrRcvgWBSElement ))
or ((instr($parameters.P_GroupByField, 'Customer') > 0 ) and ( SpecialStockIdfgCustomer <> IssgOrRcvgSpclStkIdfgCustomer ))
or ((instr($parameters.P_GroupByField, 'SpclStkType') > 0 ) and ( InventorySpecialStockType <> IssgOrRcvgStkIdfgSpclStkType ))
or ((instr($parameters.P_GroupByField, 'InventoryStockType') > 0 ) and ( InventoryStockType <> IssuingOrReceivingStockType ))
or ((instr($parameters.P_GroupByField, 'SpclStkOwnr') > 0 ) and ( SpecialStockIdfgStockOwner <> IssgOrRcvgSpclStkIdfgStkOwner ))
or ((instr($parameters.P_GroupByField, 'ResourceID') > 0 ) and ( ResourceID <> IssgOrRcvgResourceID ))
or ((instr($parameters.P_GroupByField, 'InventoryValuationType') > 0 ) and ( InventoryValuationType <> IssuingOrReceivingValType ))
)
then MatlStkChangeQtyInBaseUnit
else cast( 0 as nsdm_stock_qty)
end as NetGoodsIssueQtyInBaseUnit
}
where
MaterialBaseUnit <> '' // value only material does not have meins
and InventoryStockType <> ''
and IssuingOrReceivingStockType <> ''
and PostingDate <= $parameters.P_EndDate
and PostingDate > $parameters.P_StartDate