P_PHYSINVTRYPROPOSAL_L1

CDS View

Inventory proposal level 1

P_PHYSINVTRYPROPOSAL_L1 is a CDS View in S/4HANA. Inventory proposal level 1. It contains 21 fields. 1 CDS views read from this table.

CDS Views using this table (1)

ViewTypeJoinVDMDescription
P_PhysInvtryProposal_L2 view_entity from COMPOSITE Inventory proposal level 2

Fields (21)

KeyField CDS FieldsUsed in Views
KEY Batch Batch 1
KEY Customer Customer 1
KEY InventorySpecialStockType InventorySpecialStockType 1
KEY InventoryStockType InventoryStockType 1
KEY Material Material 1
KEY MaterialBaseUnit MaterialBaseUnit 1
KEY MaterialIsPostedToStock MaterialIsPostedToStock 1
KEY Plant Plant 1
KEY SalesOrder SalesOrder 1
KEY StockOwner StockOwner 1
KEY StorageLocation StorageLocation 1
KEY Supplier Supplier 1
CostEstimate CostEstimate 1
CurrentDate CurrentDate 1
CycleCountType CycleCountType 1
InventoryValuationType InventoryValuationType 1
MatlBatchIsInRstrcdUseStock MatlBatchIsInRstrcdUseStock 1
MatlWrhsStkQtyInMatlBaseUnit MatlWrhsStkQtyInMatlBaseUnit 1
RealProductBatch RealProductBatch 1
SerialIdentifierAssgmtProfile SerialIdentifierAssgmtProfile 1
WBSElementInternalID WBSElementInternalID 1
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl:{
  authorizationCheck: #NOT_REQUIRED,
  personalData.blocking: #BLOCKED_DATA_EXCLUDED
}
@EndUserText.label: 'Inventory proposal level 1'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
  serviceQuality: #D,
  sizeCategory: #XL,
  dataClass: #TRANSACTIONAL
}
@VDM:{
       private: true,
       viewType: #COMPOSITE
     }
define view entity P_PhysInvtryProposal_L1
as select from I_MaterialStock_2 as Stock
          inner join             P_ProductPlantBasic    as ProdPlant      on  Stock.Material                          = ProdPlant.Product
                                                                          and Stock.Plant                             = ProdPlant.Plant
          left outer to one join I_CompanyCodePeriod    as _CurrentPeriod on _CurrentPeriod.CompanyCode               = Stock.CompanyCode
          left outer to one join P_MappedPhysInvtryItem as PiItem         on  Stock.Material                          = PiItem.Material
                                                                          and Stock.Plant                             = PiItem.Plant
                                                                          and Stock.StorageLocation                   = PiItem.StorageLocation
                                                                          and Stock.Batch                             = PiItem.Batch
                                                                          and Stock.Supplier                          = PiItem.Supplier
                                                                          and Stock.SDDocument                        = PiItem.SalesOrder
                                                                          and Stock.SDDocumentItem                    = PiItem.SalesOrderItem
                                                                          and Stock.WBSElementInternalID              = PiItem.WBSElementInternalID
                                                                          and Stock.Customer                          = PiItem.Customer
                                                                          and (Stock.InventoryStockType               = PiItem.InventoryStockType or( Stock.InventoryStockType = '08' and PiItem.InventoryStockType = '01' ) )
                                                                          and Stock.InventorySpecialStockType         = PiItem.InventorySpecialStockType
                                                                          and Stock.MaterialBaseUnit                  = PiItem.MaterialBaseUnit
                                                                          and Stock.SpecialStockIdfgStockOwner        = PiItem.StockOwner
                                                                          and _CurrentPeriod.ProductCurrentFiscalYear = PiItem.FiscalYear
                                                                          and PiItem.PhysInvtryItemIsRecounted        = ''
                                                                          and PiItem.PhysInvtryDifferenceIsPosted     = ''
                                                                          and PiItem.PhysInvtryItemIsDeleted          = '' // Filtering out closed inventory counts

  association [0..1] to I_BatchPlant                    as _BatchPlant    on _BatchPlant.Material = Stock.Material
                                                                          and _BatchPlant.Plant    = Stock.Plant
                                                                          and _BatchPlant.Batch    = Stock.Batch
  association [0..1] to P_PhysInvtryKeyFiguresBase as _KeyFigures on  _KeyFigures.Material                  = $projection.Material
                                                                  and _KeyFigures.Plant                     = $projection.Plant
                                                                  and _KeyFigures.StorageLocation           = $projection.StorageLocation
                                                                  and _KeyFigures.Batch                     = $projection.Batch
                                                                  and _KeyFigures.Supplier                  = $projection.Supplier
                                                                  and _KeyFigures.SalesOrder                = $projection.SalesOrder
                                                                  and _KeyFigures.SalesOrderItem            = $projection.SalesOrderItem
                                                                  and _KeyFigures.WBSElementInternalID      = $projection.WBSElementInternalID
                                                                  and _KeyFigures.Customer                  = $projection.Customer
                                                                  and _KeyFigures.StockOwner                = $projection.StockOwner
                                                                  and _KeyFigures.InventoryStockType        = $projection.InventoryStockType
                                                                  and _KeyFigures.InventorySpecialStockType = $projection.InventorySpecialStockType
                                                                  and _KeyFigures.MaterialBaseUnit          = $projection.MaterialBaseUnit

{
      //===============================================================================================

      // Stock Separators

      //===============================================================================================

  key cast(Stock.Material as matnr preserving type)                                    as Material,
  key Stock.Plant,
  key cast(Stock.StorageLocation as lgort_d preserving type)                           as StorageLocation,
  key cast(Stock.Batch as charg_d preserving type)                                     as Batch,
  key cast(Stock.Supplier as elifn preserving type)                                    as Supplier,
  key cast(Stock.SDDocument as kdauf preserving type)                                  as SalesOrder,
  key cast(Stock.SDDocumentItem as pi_sales_order_item preserving type)                as SalesOrderItem,
  key cast(Stock.WBSElementInternalID as mat_pspnr preserving type)                    as WBSElementInternalID,
  key cast(Stock.Customer as ekunn preserving type)                                    as Customer,
  key cast(Stock.SpecialStockIdfgStockOwner as pi_owner_of_stock preserving type)      as StockOwner,
  key Stock.InventoryStockType,
  key Stock.InventorySpecialStockType,
  key Stock.MaterialBaseUnit,
  key cast( 'X' as materialispostedtostock preserving type )                              as MaterialIsPostedToStock,

      Stock.CostEstimate,
      cast(_BatchPlant.InventoryValuationType as bwtar_d preserving type )                as InventoryValuationType,
      cast( 
        case when ( ProdPlant.ValuationCategory <> '' and ProdPlant.IsBatchManagementRequired = '' )
             then ( '' )
        else ( Stock.Batch ) end
      as charg_d preserving type )                                                        as RealProductBatch, 

      cast(ProdPlant.InventoryForCycleCountInd as mmim_cycle_count_type preserving type ) as CycleCountType,
      ProdPlant.SerialNumberProfile                                                       as SerialIdentifierAssgmtProfile, //2974210

      _BatchPlant.MatlBatchIsInRstrcdUseStock,
      $session.system_date                                                                 as CurrentDate,
      //===============================================================================================

      // Key figures

      //===============================================================================================

      @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
      cast(sum(Stock.MatlWrhsStkQtyInMatlBaseUnit) as nsdm_stock_qty preserving type )  as MatlWrhsStkQtyInMatlBaseUnit,
      max(_KeyFigures.PhysicalInventoryLastCountDate)                                      as PhysicalInventoryLastCountDate,
      max(_KeyFigures.NumberOfPhysInventoryCounts)                                         as NumberOfPhysInventoryCounts
}
where   Stock.MaterialBaseUnit           <> ''
  and   Stock.InventorySpecialStockType  <> 'P'
  and   Stock.InventorySpecialStockType  <> 'T'
  and   Stock.Supplier   <> '$%§??§%$'
  and   Stock.Customer   <> '$%§??§%$'
  and   Stock.SpecialStockIdfgStockOwner <> '$%§??§%$'
  // with zero stock the batch indicator for a material can be changed

  and( ProdPlant.IsInternalBatchManaged =  '' and Stock.Batch =  '' ) or ( ProdPlant.IsInternalBatchManaged <> '' and Stock.Batch <> '' ) // 3098491

group by
  Stock.Material,
  Stock.Plant,
  Stock.StorageLocation,
  Stock.Batch,
  Stock.Supplier,
  Stock.SDDocument,
  Stock.SDDocumentItem,
  Stock.WBSElementInternalID,
  Stock.Customer,
  Stock.SpecialStockIdfgStockOwner,
  Stock.CostEstimate,
  _BatchPlant.InventoryValuationType,
  _BatchPlant.MatlBatchIsInRstrcdUseStock,
  ProdPlant.ValuationCategory,
  ProdPlant.IsBatchManagementRequired,
  ProdPlant.InventoryForCycleCountInd,
  ProdPlant.SerialNumberProfile,
  ProdPlant.IsInternalBatchManaged,
  Stock.InventoryStockType,
  Stock.InventorySpecialStockType,
  Stock.MaterialBaseUnit,
  PiItem.PhysicalInventoryDocument // Helper field to filter out stock separators that have open inventory counts

having
  PiItem.PhysicalInventoryDocument is null

union all
select from P_PhysInvtryNotPosted_L3 as _NotPostedMaterial
--select from P_PhysInvtrPropNotPostedMaster( P_Client : $session.client ) as _NotPostedMaterial
-- to get CosteEstimate for those records which are not posted to stock right now:
-- they can have only a record in MBEW but not in E/O/QBEW
  left outer to one join P_ProductValuationBasic as _ValuatedProductValuation on _ValuatedProductValuation.Product = _NotPostedMaterial.Material 
                                                           and _ValuatedProductValuation.ValuationArea = _NotPostedMaterial.Plant 
                                                           and _ValuatedProductValuation.ValuationType = _NotPostedMaterial.Batch
-- not a batch and not split valuated non-batch material:
  left outer to one join P_ProductValuationBasic as _NonValuatedProductValuation on _NonValuatedProductValuation.Product = _NotPostedMaterial.Material 
                                                              and _NonValuatedProductValuation.ValuationArea = _NotPostedMaterial.Plant
                                                              and _NonValuatedProductValuation.ValuationType = ''
-- batch master has an derivating valuation type then the batch itself
  left outer to one join P_ProductValuationBasic as _DerivatingBatchValuation on _DerivatingBatchValuation.Product = _NotPostedMaterial.Material
                                                           and _DerivatingBatchValuation.ValuationArea = _NotPostedMaterial.Plant
                                                           and _DerivatingBatchValuation.ValuationType = _NotPostedMaterial.InventoryValuationType
association [0..*] to P_PhysInvtryKeyFiguresBase as _KeyFigures on  _KeyFigures.Material                  = $projection.Material
                                                                and _KeyFigures.Plant                     = $projection.Plant
                                                                and _KeyFigures.StorageLocation           = $projection.StorageLocation
                                                                and ( _KeyFigures.Batch                   = $projection.Batch or $projection.Batch is null )
--Having all key fields creates a deviation to the C view stack
--                                                                and _KeyFigures.Supplier                  = $projection.Supplier
--                                                                and _KeyFigures.SalesOrder                = $projection.SalesOrder
--                                                                and _KeyFigures.SalesOrderItem            = $projection.SalesOrderItem
--                                                                and _KeyFigures.WBSElementInternalID      = $projection.WBSElementInternalID
--                                                                and _KeyFigures.Customer                  = $projection.Customer
--                                                                and _KeyFigures.StockOwner                = $projection.StockOwner
                                                                and _KeyFigures.InventoryStockType        = $projection.InventoryStockType
--                                                                and _KeyFigures.InventorySpecialStockType = $projection.InventorySpecialStockType
                                                                and _KeyFigures.MaterialBaseUnit          = $projection.MaterialBaseUnit
{
  key     _NotPostedMaterial.Material,
  key     _NotPostedMaterial.Plant,
  key     _NotPostedMaterial.StorageLocation,
  key     _NotPostedMaterial.Batch,
  key     _NotPostedMaterial.Supplier,
  key     _NotPostedMaterial.SalesOrder,
  key     cast(_NotPostedMaterial.SalesOrderItem as pi_sales_order_item preserving type)               as SalesOrderItem,
  key     _NotPostedMaterial.WBSElementInternalID,
  key     _NotPostedMaterial.Customer,
  key     _NotPostedMaterial.StockOwner,
  key     _NotPostedMaterial.InventoryStockType,
  key     _NotPostedMaterial.InventorySpecialStockType,
  key     _NotPostedMaterial.BaseUnit                                                                  as MaterialBaseUnit,
  key     cast( '' as materialispostedtostock preserving type )                                        as MaterialIsPostedToStock,
          case
            when ( _NotPostedMaterial.InventoryValuationType <> '' or _NotPostedMaterial.InventoryValuationType is not null ) then _DerivatingBatchValuation.ProdCostEstNumber
            when ( _NotPostedMaterial.ValuationCategory <> '' and _NotPostedMaterial.IsBatchManagementRequired = 'X' ) then _ValuatedProductValuation.ProdCostEstNumber
            else _NonValuatedProductValuation.ProdCostEstNumber
          end                                                                                          as CostEstimate,    
          _NotPostedMaterial.InventoryValuationType,
          cast( 
            case when ( _NotPostedMaterial.ValuationCategory <> '' and _NotPostedMaterial.IsBatchManagementRequired = '' )
                 then ( '' )
                 else ( _NotPostedMaterial.Batch )
             end as charg_d preserving type )                                                          as RealProductBatch, 
          cast(_NotPostedMaterial.InventoryForCycleCountInd as mmim_cycle_count_type preserving type ) as CycleCountType,
          _NotPostedMaterial.SerialNumberProfile                                                       as SerialIdentifierAssgmtProfile, //2974210

          _NotPostedMaterial.MatlBatchIsInRstrcdUseStock,
          $session.system_date                                                                         as CurrentDate,
          cast( 0 as nsdm_stock_qty )                                                                  as MatlWrhsStkQtyInMatlBaseUnit,
          max(_KeyFigures.PhysicalInventoryLastCountDate)       as PhysicalInventoryLastCountDate,
          max(_KeyFigures.NumberOfPhysInventoryCounts)          as NumberOfPhysInventoryCounts
/*
-- Basically there can not be any counted inventory documentbecause if counted and deviation did exist then also a material document does exit
-- and hence this material will appear in the upper branch of the UNION 
-- Hence there might be a problem for a counted inventory document w/o deviations
-- Adding P_PhysInvtryKeyFiguresBase in the assoziation above creates two additionalCYCLIC JOINs
          cast('00000000' as abap.dats)                                                                as PhysicalInventoryLastCountDate,
          cast(0 as int1 preserving type)                                                              as NumberOfPhysInventoryCounts
*/
}
group by
  _NotPostedMaterial.Material,
  _NotPostedMaterial.Plant,
  _NotPostedMaterial.StorageLocation,
  _NotPostedMaterial.Batch,
  _NotPostedMaterial.Supplier,
  _NotPostedMaterial.SalesOrder,
  _NotPostedMaterial.SalesOrderItem,
  _NotPostedMaterial.WBSElementInternalID,
  _NotPostedMaterial.Customer,
  _NotPostedMaterial.StockOwner,
  _NotPostedMaterial.InventoryStockType,
  _NotPostedMaterial.InventorySpecialStockType,
  _NotPostedMaterial.InventoryValuationType,
  _NotPostedMaterial.MatlBatchIsInRstrcdUseStock,
  _ValuatedProductValuation.ProdCostEstNumber,
  _NonValuatedProductValuation.ProdCostEstNumber,
  _DerivatingBatchValuation.ProdCostEstNumber,
  _ValuatedProductValuation.ValuationType,
  _NonValuatedProductValuation.ValuationType,
  _NotPostedMaterial.ValuationCategory,
  _NotPostedMaterial.IsBatchManagementRequired,
  _NotPostedMaterial.InventoryForCycleCountInd,
  _NotPostedMaterial.SerialNumberProfile,
  _NotPostedMaterial.BaseUnit