Derived SQL interpretation, reconstructed from the parsed view metadata (data sources, associations, and field mappings). SAP annotations are omitted and the structure is reformulated as SQL — this is a functional approximation, not the verbatim SAP source.
-- Derived SQL interpretation of CDS view P_StockLevelMngCalcFields.
-- Reconstructed from parsed metadata (data sources, associations, fields).
-- SAP annotations are omitted and the structure is reformulated as SQL;
-- this is a functional approximation, not the verbatim SAP source. Some join
-- conditions may be unavailable and a few CDS constructs are kept as-is.
-- SQL view name: PSTKLVLMNGCF
CREATE VIEW P_StockLevelMngCalcFields AS
SELECT
_StockProposed.Material AS Material,
_StockProposed.Plant AS Plant,
_StockProposed.MRPArea AS MRPArea,
_StockProposed.ProposalStartDate AS ProposalStartDate,
_StockProposed.ProposalVersion AS ProposalVersion,
_StockActual.CurrentRedZone AS CurrentRedZone,
_StockActual.CurrentLeadTime AS CurrentLeadTime,
_StockActual.CurrentLeadTimeFactor AS CurrentLeadTimeFactor,
_StockActual.CurrentVariabilityFactor AS CurrentVariabilityFactor,
_StockActual.BufferLevelStartDate AS BufferLevelStartDate,
_StockActual.CurrentGreenZone AS CurrentGreenZone,
_StockActual.CurrentYellowZone AS CurrentYellowZone,
_StockActual.CurrentAvgDailyUsage AS CurrentAvgDailyUsage,
_StockProposed.BillOfMaterialUUID AS BillOfMaterialUUID,
_StockActual.BillOfMaterialUUID AS ProposedBOMUUID,
_StockProposed.ProposalEndDate AS ProposalEndDate,
_StockProposed.AverageDailyUsage AS ProposedAverageDailyUsage,
_StockProposed.ProposedGreenZone AS ProposedGreenZone,
_StockProposed.ProposedRedZone AS ProposedRedZone,
_StockProposed.ProposedYellowZone AS ProposedYellowZone,
_StockProposed.DecoupledLeadTime AS ProposedLeadTime,
_StockProposed.LeadTimeFactor AS ProposedLeadTimeFactor,
_StockProposed.VariabilityFactor AS ProposedVariabilityFactor,
_StockProposed.StockLevelProposalID AS StockLevelProposalID,
_StockProposed.StockLevelProposalStatus AS StockLevelProposalStatus,
_StockProposed.AvgDailyUsageUnit AS AvgDailyUsageUnit,
DATS_DAYS_BETWEEN(tstmp_to_dats( _StockProposed.ProposalStatusChangeDate, abap_system_timezone( $session.client,'NULL' ), $session.client, 'NULL' ), cast($session.system_date as sydatum)) as DifferenceInDays AS system_dateassydatumasDifferenceInDays,
_StockActual.VariabilityQuantity AS VariabilityQuantity,
_StockActual.VariabilityUnit AS VariabilityUnit,
_StockActual.ReplenishmentLeadTimeValue AS ReplenishmentLeadTimeValue,
_StockActual.ReplenishmentLeadTimeCode AS CurrentMatlLeadTimeCode,
_StockActual.VariabilityCode AS CurrentMatlVariabilityCode,
_StockProposed.VariabilityCode AS ProposedMatlVariabilityCode,
_StockProposed.VariabilityQuantity AS ProposedMatlVariabilityQty,
_StockProposed.VariabilityUnit AS ProposedMatlVariabilityUnit,
_StockProposed.ReplenishmentLeadTimeCode AS ProposedMatlLeadTimeCode,
_StockProposed.ReplenishmentLeadTimeValue AS ProposedMatlLeadTime,
cast( _Product.HorizonDaysInPast as abap.int4) + cast( _Product.HorizonDaysInFuture as abap.int4) AS TotalNoOfDays,
case when _StockActual.CurrentRedZone is null then _StockProposed.OriglProposedRedZone else _StockProposed.OriglProposedRedZone - _StockActual.CurrentRedZone end as RedZoneDifference AS CurrentRedZoneendasRedZoneDifference,
case when _StockActual.CurrentGreenZone is null then _StockProposed.OriglProposedGreenZone else _StockProposed.OriglProposedGreenZone - _StockActual.CurrentGreenZone end as GreenZoneDifference AS CurrentGreenZoneendasGreenZoneDifference,
case when _StockActual.CurrentAvgDailyUsage = 0.000 or _StockActual.CurrentAvgDailyUsage is null then case when _StockProposed.AverageDailyUsage <> 0.000 then fltp_to_dec(99999.99 as abap.dec(12,2)) else 0.00 end else cast((_StockProposed.AverageDailyUsage - _StockActual.CurrentAvgDailyUsage) as abap.fltp)/(cast((_StockActual.CurrentAvgDailyUsage) as abap.fltp))*100.00 end as AvgDailyUsageDeviationRate AS 00endasAvgDailyUsageDeviationRate,
case when _StockActual.CurrentLeadTimeFactor is null or _StockActual.CurrentLeadTimeFactor = 0.00 then case when _StockProposed.LeadTimeFactor <> 0.00 then fltp_to_dec(99999.99 as abap.dec(12,2)) else 0 end else cast((_StockProposed.LeadTimeFactor - _StockActual.CurrentLeadTimeFactor) as abap.fltp)/(cast((_StockActual.CurrentLeadTimeFactor) as abap.fltp))*100.00 end as LeadTimeFactorDeviationRate AS 00endasLeadTimeFactorDeviationRate,
case when _StockActual.CurrentLeadTime is null then _StockProposed.DecoupledLeadTime else _StockProposed.DecoupledLeadTime - _StockActual.CurrentLeadTime end as LeadTimeDifference AS CurrentLeadTimeendasLeadTimeDifference,
case when _StockActual.CurrentLeadTime = 0.00 or _StockActual.CurrentLeadTime is null then case when _StockProposed.DecoupledLeadTime <> 0.00 then fltp_to_dec(99999.99 as abap.dec(12,2)) else 0.00 end else cast((_StockProposed.DecoupledLeadTime - _StockActual.CurrentLeadTime) as abap.fltp)/(cast((_StockActual.CurrentLeadTime) as abap.fltp))*100.00 end as LeadTimeDeviationRate AS 00endasLeadTimeDeviationRate,
case when _StockActual.VariabilityQuantity = 0.00 or _StockActual.VariabilityQuantity is null then case when _StockProposed.VariabilityQuantity <> 0.00 then fltp_to_dec(99999.99 as abap.dec(12,2)) else 0.00 end else cast((_StockProposed.VariabilityQuantity - _StockActual.VariabilityQuantity ) as abap.fltp)/(cast((_StockActual.VariabilityQuantity ) as abap.fltp))*100.00 end as VariabilityFactorDeviationRate AS 00endasVariabilityFactorDeviationRate,
_StockProposed.ProposedGreenZone + _StockProposed.ProposedYellowZone + _StockProposed.ProposedRedZone AS MatlProposedMaxStock,
concat(_StockProposed.ProcurementType,concat('-',concat(concat(_StockProposed.VariabilityCode,'-'),_StockProposed.ReplenishmentLeadTimeCode))) AS ProposedMaterialBufferProfile,
concat(_StockProposed._ProcmtText.ProcurementTypeDescription,concat('-',concat(concat(_StockProposed._VarText.VariabilityDescription,'-'),_StockProposed._ReplnmtText.ReplenishmentLeadTimeDesc))) AS ProposedMatlBufferProfileText,
_ProcmtText.ProcurementTypeDescription AS ProcurementTypeDescription,
_VarText.VariabilityDescription AS VariabilityDescription,
_ReplnmtText.ReplenishmentLeadTimeDesc AS ReplenishmentLeadTimeDesc,
_StockProposed.IsMinOrderQtyConsidered AS IsMinOrderQtyConsidered,
cast(_Product.HorizonDaysInPast as abap.int2) AS HorizonDaysInPast
FROM I_StockLevelProposal AS _StockProposed
LEFT OUTER JOIN P_TimeDependentStockBuffer AS _StockActual ON Material = _StockActual.Material AND Plant = _StockActual.Plant AND MRPArea = _StockActual.MRPArea -- association [1..*]
LEFT OUTER JOIN I_DemandDrivenProduct1 AS _Product ON Material = _Product.Material AND Plant = _Product.Plant AND MRPArea = _Product.MRPArea -- association [1..1]
;