P_StkPostgHistBasic

DDL: P_STKPOSTGHISTBASIC Type: view_entity COMPOSITE

Stock posting history basic view

P_StkPostgHistBasic is a Composite CDS View that provides data about "Stock posting history basic view" in SAP S/4HANA. It reads from 5 data sources (I_MaterialDocumentRecord, P_StkPostgHistAcctgNoStkQty, I_GLAccountLineItemRawData, finsc_ledger, I_MaterialDocumentRecord) and exposes 113 fields.

Data Sources (5)

SourceAliasJoin Type
I_MaterialDocumentRecord _matdoc inner
P_StkPostgHistAcctgNoStkQty acdoca union_all
I_GLAccountLineItemRawData acdoca union_all
finsc_ledger finsc_ledger inner
I_MaterialDocumentRecord matdoc from

Parameters (2)

NameTypeDefault
P_StartDate sydate
P_EndDate sydate

Annotations (8)

NameValueLevelField
AccessControl.authorizationCheck #NOT_REQUIRED view
EndUserText.label Stock posting history basic view view
Metadata.ignorePropagatedAnnotations true view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.dataClass #MIXED view
VDM.viewType #COMPOSITE view
VDM.private true view

Fields (113)

KeyFieldSource TableSource FieldDescription
StockLevelIsValuated
MaterialDocument I_MaterialDocumentRecord MaterialDocument
MaterialDocumentYear I_MaterialDocumentRecord MaterialDocumentYear
MaterialDocumentItem I_MaterialDocumentRecord MaterialDocumentItem
FiscalYearendasFiscalYear
CostEstimate I_MaterialDocumentRecord CostEstimate
CompanyCode I_MaterialDocumentRecord CompanyCode
Material I_MaterialDocumentRecord StockIdentifyingMaterial
Plant I_MaterialDocumentRecord Plant
StorageLocation I_MaterialDocumentRecord StockIdfgStorageLocation
Batch I_MaterialDocumentRecord StockIdentifyingBatch
Supplier I_MaterialDocumentRecord SpecialStockIdfgSupplier
SalesOrder I_MaterialDocumentRecord SpecialStockIdfgSalesOrder
SalesOrderItem I_MaterialDocumentRecord SpecialStockIdfgSalesOrderItem
WBSElementInternalID I_MaterialDocumentRecord SpecialStockIdfgWBSElement
Customer I_MaterialDocumentRecord SpecialStockIdfgCustomer
InventoryStockType I_MaterialDocumentRecord InventoryStockType
InventorySpecialStockType I_MaterialDocumentRecord InventorySpecialStockType
SpecialStockIdfgStockOwner I_MaterialDocumentRecord SpecialStockIdfgStockOwner
ResourceID I_MaterialDocumentRecord ResourceID
InventoryValuationType I_MaterialDocumentRecord InventoryValuationType
MaterialBaseUnit I_MaterialDocumentRecord MaterialBaseUnit
MatlStkChangeQtyInBaseUnit I_MaterialDocumentRecord MatlStkChangeQtyInBaseUnit
CompanyCodeCurrency I_MaterialDocumentRecord CompanyCodeCurrency
PurchaseOrder I_MaterialDocumentRecord PurchaseOrder
PurchaseOrderItem I_MaterialDocumentRecord PurchaseOrderItem
ManufacturingOrder I_MaterialDocumentRecord ManufacturingOrder
ManufacturingOrderItem I_MaterialDocumentRecord ManufacturingOrderItem
DeliveryDocument I_MaterialDocumentRecord DeliveryDocument
DeliveryDocumentItem I_MaterialDocumentRecord DeliveryDocumentItem
Reservation I_MaterialDocumentRecord Reservation
ReservationItem I_MaterialDocumentRecord ReservationItem
GoodsMovementType I_MaterialDocumentRecord GoodsMovementType
GoodsMovementRefDocType I_MaterialDocumentRecord GoodsMovementRefDocType
GoodsReceiptType I_MaterialDocumentRecord GoodsReceiptType
ConsumptionPosting I_MaterialDocumentRecord ConsumptionPosting
CompanyCode0asStockLevelIsValuated
MaterialDocument I_GLAccountLineItemRawData MaterialDocument
MaterialDocumentYear I_GLAccountLineItemRawData MaterialDocumentYear
MaterialDocumentItem I_GLAccountLineItemRawData MaterialDocumentItem
AccountingDocument I_GLAccountLineItemRawData AccountingDocument
FiscalYear I_GLAccountLineItemRawData FiscalYear
CostEstimate I_GLAccountLineItemRawData CostEstimate
CompanyCode I_GLAccountLineItemRawData CompanyCode
Material I_MaterialDocumentRecord StockIdentifyingMaterial
Plant I_MaterialDocumentRecord Plant
StorageLocation I_MaterialDocumentRecord StockIdfgStorageLocation
Batch I_MaterialDocumentRecord StockIdentifyingBatch
Supplier I_MaterialDocumentRecord SpecialStockIdfgSupplier
SalesOrder I_MaterialDocumentRecord SpecialStockIdfgSalesOrder
SalesOrderItem I_MaterialDocumentRecord SpecialStockIdfgSalesOrderItem
WBSElementInternalID I_MaterialDocumentRecord SpecialStockIdfgWBSElement
Customer I_MaterialDocumentRecord SpecialStockIdfgCustomer
InventoryStockType I_MaterialDocumentRecord InventoryStockType
InventorySpecialStockType I_MaterialDocumentRecord InventorySpecialStockType
SpecialStockIdfgStockOwner I_MaterialDocumentRecord SpecialStockIdfgStockOwner
ResourceID I_MaterialDocumentRecord ResourceID
InventoryValuationType I_MaterialDocumentRecord InventoryValuationType
MaterialBaseUnit I_GLAccountLineItemRawData MaterialBaseUnit
MatlStkChangeQtyInBaseUnit I_GLAccountLineItemRawData MatlStkChangeQtyInBaseUnit
CompanyCodeCurrency I_GLAccountLineItemRawData CompanyCodeCurrency
AmountInCompanyCodeCurrency I_GLAccountLineItemRawData AmountInCompanyCodeCurrency
PurchaseOrder I_MaterialDocumentRecord PurchaseOrder
PurchaseOrderItem I_MaterialDocumentRecord PurchaseOrderItem
ManufacturingOrder I_MaterialDocumentRecord ManufacturingOrder
ManufacturingOrderItem I_MaterialDocumentRecord ManufacturingOrderItem
DeliveryDocument I_MaterialDocumentRecord DeliveryDocument
DeliveryDocumentItem I_MaterialDocumentRecord DeliveryDocumentItem
Reservation I_MaterialDocumentRecord Reservation
ReservationItem I_MaterialDocumentRecord ReservationItem
GoodsMovementType I_MaterialDocumentRecord GoodsMovementType
GoodsMovementRefDocType I_MaterialDocumentRecord GoodsMovementRefDocType
GoodsReceiptType I_MaterialDocumentRecord GoodsReceiptType
ConsumptionPosting I_MaterialDocumentRecord ConsumptionPosting
xleadingX1asStockLevelIsValuated
MaterialDocument
MaterialDocumentYear
MaterialDocumentItem
AccountingDocument I_GLAccountLineItemRawData AccountingDocument
FiscalYear I_GLAccountLineItemRawData FiscalYear
CostEstimate I_GLAccountLineItemRawData CostEstimate
CompanyCode I_GLAccountLineItemRawData CompanyCode
Material I_GLAccountLineItemRawData Product
Plant I_GLAccountLineItemRawData Plant
StorageLocation
Batch
Supplier
SalesOrder
SalesOrderItem
WBSElementInternalID
Customer
InventoryStockType
InventorySpecialStockType
SpecialStockIdfgStockOwner
ResourceID
InventoryValuationType I_GLAccountLineItemRawData InventoryValuationType
MaterialBaseUnit I_GLAccountLineItemRawData CostSourceUnit
MatlStkChangeQtyInBaseUnit I_GLAccountLineItemRawData ValuationQuantity
CompanyCodeCurrency I_GLAccountLineItemRawData CompanyCodeCurrency
AmountInCompanyCodeCurrency I_GLAccountLineItemRawData AmountInCompanyCodeCurrency
PurchaseOrder I_GLAccountLineItemRawData PurchasingDocument
PurchaseOrderItem I_GLAccountLineItemRawData PurchasingDocumentItem
ManufacturingOrder I_GLAccountLineItemRawData OrderID
ManufacturingOrderItem I_GLAccountLineItemRawData OrderItem
DeliveryDocument
DeliveryDocumentItem
Reservation
ReservationItem
GoodsMovementType
GoodsMovementRefDocType
GoodsReceiptType
ConsumptionPosting
PostingDate I_GLAccountLineItemRawData PostingDate
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Stock posting history basic view'
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
  serviceQuality: #D,
  sizeCategory: #XXL,
  dataClass: #MIXED
}
@VDM:
      {
        viewType: #COMPOSITE,
        private: true
      }
define view entity P_StkPostgHistBasic
  with parameters
    @Environment.systemField: #SYSTEM_DATE
    P_StartDate : sydate,
    @Environment.systemField: #SYSTEM_DATE
    P_EndDate   : sydate

  as select from           I_MaterialDocumentRecord as matdoc

    left outer to one join P_StkPostgHistAcctg      as _MatDocAccounting on  matdoc.MaterialDocument         =  _MatDocAccounting.MaterialDocument
                                                                         and matdoc.MaterialDocumentYear     =  _MatDocAccounting.MaterialDocumentYear
                                                                         and matdoc.MaterialDocumentItem     =  _MatDocAccounting.MaterialDocumentItem
                                                                         and matdoc.StockIdentifyingMaterial =  _MatDocAccounting.Product
                                                                         and matdoc.CostEstimate             <> '000000000000'
{

  '0'                                                                        as StockLevelIsValuated,
  matdoc.MaterialDocument,
  matdoc.MaterialDocumentYear,
  matdoc.MaterialDocumentItem,

  // Accounting document

  case when _MatDocAccounting.AccountingDocument is null
        then cast('' as farp_belnr_d)
       else
        _MatDocAccounting.AccountingDocument                                       
       end                                                                   as AccountingDocument,
 
  case when _MatDocAccounting.FiscalYear  is null
         then cast('0000' as gjahr)
       else
         _MatDocAccounting.FiscalYear
       end                                                                   as FiscalYear,

  matdoc.CostEstimate,
  matdoc.CompanyCode                                                         as CompanyCode,

  // stock fields for filter

  matdoc.StockIdentifyingMaterial                                            as Material,
  matdoc.Plant,
  matdoc.StockIdfgStorageLocation                                            as StorageLocation,
  matdoc.StockIdentifyingBatch                                               as Batch,
  matdoc.SpecialStockIdfgSupplier                                            as Supplier,
  matdoc.SpecialStockIdfgSalesOrder                                          as SalesOrder,
  matdoc.SpecialStockIdfgSalesOrderItem                                      as SalesOrderItem,
  matdoc.SpecialStockIdfgWBSElement                                          as WBSElementInternalID,
  matdoc.SpecialStockIdfgCustomer                                            as Customer,
  matdoc.InventoryStockType,
  matdoc.InventorySpecialStockType,
  matdoc.SpecialStockIdfgStockOwner,
  matdoc.ResourceID,
  matdoc.InventoryValuationType,

  // stock quantity

  matdoc.MaterialBaseUnit,
  @Semantics.quantity.unitOfMeasure: 'MaterialBaseUnit'
  matdoc.MatlStkChangeQtyInBaseUnit,

  matdoc.CompanyCodeCurrency,
  @Semantics.amount.currencyCode: 'CompanyCodeCurrency'
  case
    when matdoc.CostEstimate = '000000000000' // when cost estimate is initial, value is 0

     then cast (0 as nsdm_stk_val_cccrcy)
    else cast(matdoc.GoodsMovementStkAmtInCCCrcy as nsdm_stk_val_cccrcy) end as AmountInCompanyCodeCurrency, // dmbtr_stock


  // reference documents

  matdoc.PurchaseOrder,
  matdoc.PurchaseOrderItem,
  matdoc.ManufacturingOrder,
  matdoc.ManufacturingOrderItem,
  matdoc.DeliveryDocument,
  matdoc.DeliveryDocumentItem,
  matdoc.Reservation,
  matdoc.ReservationItem,

  // other fields

  matdoc.GoodsMovementType,
  matdoc.GoodsMovementRefDocType,
  matdoc.GoodsReceiptType,
  matdoc.ConsumptionPosting,

  matdoc.PostingDate
}
where
       matdoc.PostingDate                >= $parameters.P_StartDate
  and  matdoc.PostingDate                <= $parameters.P_EndDate
  and(
       matdoc.MatlStkChangeQtyInBaseUnit <> 0
    or matdoc.TotalGoodsMvtAmtInCCCrcy   =  0 // dmbtr

  ) // stock_qty <> 0                                 => matdoc case

    // stock_qty = 0 and dmbtr = 0                    => matdoc case, no FI document

    // stock_qty = 0 and dmbtr <> 0 (dmbtr_stock = 0) => acdoca case, because costestimate is initial in matdoc but FI document is created


union all

// FI document with reference to Material Document which has stock quantity posting 0, but value change is not 0, e.g. movement 121

select from  P_StkPostgHistAcctgNoStkQty as acdoca

  inner join I_MaterialDocumentRecord    as _matdoc on  acdoca.MaterialDocument            = _matdoc.MaterialDocument
                                                    and acdoca.MaterialDocumentYear        = _matdoc.MaterialDocumentYear
                                                    and acdoca.MaterialDocumentItem        = _matdoc.MaterialDocumentItem
                                                    and acdoca.Material                    = _matdoc.StockIdentifyingMaterial
                                                    and acdoca.InventoryValuationType      = _matdoc.InventoryValuationType
                                                    and acdoca.CompanyCode                 = _matdoc.CompanyCode
{

  '0'                                    as StockLevelIsValuated,
  acdoca.MaterialDocument,
  acdoca.MaterialDocumentYear,
  acdoca.MaterialDocumentItem,

  acdoca.AccountingDocument,
  acdoca.FiscalYear,

  acdoca.CostEstimate,
  acdoca.CompanyCode,

  // stock fields

  _matdoc.StockIdentifyingMaterial       as Material,
  _matdoc.Plant,
  _matdoc.StockIdfgStorageLocation       as StorageLocation,
  _matdoc.StockIdentifyingBatch          as Batch,
  _matdoc.SpecialStockIdfgSupplier       as Supplier,
  _matdoc.SpecialStockIdfgSalesOrder     as SalesOrder,
  _matdoc.SpecialStockIdfgSalesOrderItem as SalesOrderItem,
  _matdoc.SpecialStockIdfgWBSElement     as WBSElementInternalID,
  _matdoc.SpecialStockIdfgCustomer       as Customer,
  _matdoc.InventoryStockType,
  _matdoc.InventorySpecialStockType,
  _matdoc.SpecialStockIdfgStockOwner,
  _matdoc.ResourceID,
  _matdoc.InventoryValuationType,

  // stock quantity

  acdoca.MaterialBaseUnit,
  acdoca.MatlStkChangeQtyInBaseUnit,

  acdoca.CompanyCodeCurrency,
  acdoca.AmountInCompanyCodeCurrency,

  // reference documents

  _matdoc.PurchaseOrder,
  _matdoc.PurchaseOrderItem,
  _matdoc.ManufacturingOrder,
  _matdoc.ManufacturingOrderItem,
  _matdoc.DeliveryDocument,
  _matdoc.DeliveryDocumentItem,
  _matdoc.Reservation,
  _matdoc.ReservationItem,

  // other fields

  _matdoc.GoodsMovementType,
  _matdoc.GoodsMovementRefDocType,
  _matdoc.GoodsReceiptType,
  _matdoc.ConsumptionPosting,
  acdoca.PostingDate

}
where
      acdoca.PostingDate >= $parameters.P_StartDate
  and acdoca.PostingDate <= $parameters.P_EndDate

union all

// FI document without reference to Material Document, e.g. Price change

select from  I_GLAccountLineItemRawData as acdoca
  inner join finsc_ledger on  acdoca.SourceLedger   = finsc_ledger.rldnr
                          and finsc_ledger.xleading = 'X'
{

  '1'                                           as StockLevelIsValuated,
  cast('' as mblnr)                             as MaterialDocument,
  cast('0000' as mjahr)                         as MaterialDocumentYear,
  cast('0000' as mblpo)                         as MaterialDocumentItem,

  acdoca.AccountingDocument                     as AccountingDocument,
  acdoca.FiscalYear                             as FiscalYear,

  acdoca.CostEstimate                           as CostEstimate,
  acdoca.CompanyCode                            as CompanyCode,

  // stock fields

  acdoca.Product                                as Material,
  acdoca.Plant                                  as Plant,
  ''                                            as StorageLocation,
  ''                                            as Batch,
  ''                                            as Supplier,
  ''                                            as SalesOrder,
  cast('000000' as mat_kdpos)                   as SalesOrderItem,
  cast('00000000' as mat_pspnr)                 as WBSElementInternalID,
  ''                                            as Customer,
  ''                                            as InventoryStockType,
  ''                                            as InventorySpecialStockType,
  ''                                            as SpecialStockIdfgStockOwner,
  ''                                            as ResourceID,
  acdoca.InventoryValuationType                 as InventoryValuationType,

  // stock quantity

  acdoca.CostSourceUnit                         as MaterialBaseUnit,
  acdoca.ValuationQuantity                      as MatlStkChangeQtyInBaseUnit,

  acdoca.CompanyCodeCurrency                    as CompanyCodeCurrency,
  acdoca.AmountInCompanyCodeCurrency            as AmountInCompanyCodeCurrency,


  // reference documents

  acdoca.PurchasingDocument                     as PurchaseOrder,
  acdoca.PurchasingDocumentItem                 as PurchaseOrderItem,
  acdoca.OrderID                                as ManufacturingOrder,
  acdoca.OrderItem                              as ManufacturingOrderItem,
  ''                                            as DeliveryDocument,
  cast('000000' as nsdm_delivery_document_item) as DeliveryDocumentItem,
  cast('0000000000' as rsnum)                   as Reservation,
  cast('0000' as nsdm_rspos)                    as ReservationItem,

  // other fields

  ''                                            as GoodsMovementType,
  ''                                            as GoodsMovementRefDocType,
  ''                                            as GoodsReceiptType,
  ''                                            as ConsumptionPosting,
  acdoca.PostingDate                            as PostingDate

}
where
      acdoca.PostingDate                  >= $parameters.P_StartDate
  and acdoca.PostingDate                  <= $parameters.P_EndDate
  and acdoca.ReferenceDocumentType        <> 'MKPF'
  and acdoca.AccountingDocument           <> ''
  and acdoca.TransactionTypeDetermination =  'BSX'
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_GLACCOUNTLINEITEMRAWDATA",
"I_MATERIALDOCUMENTRECORD",
"P_STKPOSTGHISTACCTG",
"P_STKPOSTGHISTACCTGNOSTKQTY",
"FINSC_LEDGER"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/