@AbapCatalog.sqlViewName: 'PEBORDHAIPC1V2'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.algorithm: #SESSION_VARIABLE
@Metadata.ignorePropagatedAnnotations: true
@VDM.private: true
@VDM.viewType: #COMPOSITE
define view P_EBOrderHdrItmProdnCost1v2
with parameters
P_Ledger : fins_ledger,
P_FromFiscalYearPeriod : fins_fyearperiod,
P_ToFiscalYearPeriod : fins_fyearperiod,
P_CurrencyRole : fis_curtp
as select from P_RealTmeWrkInProcOrdHdAndItem as EvtBsdOrderAndItem
//Order Key Statuses - REL, PREL, CNF, DLV, CLSD, TECO, DLFL
inner join P_CoEvtBsdOrderKeyStatus as _OrderKeyStatus on EvtBsdOrderAndItem.OrderInternalID = _OrderKeyStatus.ControllingObject
inner join I_LedgerCompanyCodeCrcyRolesVH as _LdgrCompCodeCrcy on _LdgrCompCodeCrcy.Ledger = :P_Ledger
and _LdgrCompCodeCrcy.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _LdgrCompCodeCrcy.CurrencyRole = :P_CurrencyRole
// Order Planned Costs
left outer to one join P_EBOrderPlanCost3( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderPlanCost on _OrderPlanCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _OrderPlanCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderPlanCost.OrderItem = EvtBsdOrderAndItem.OrderItem
// Order Actual Costs
left outer to one join P_EBOrderActualCost3( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderActualCost on _OrderActualCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _OrderActualCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderActualCost.OrderItem = EvtBsdOrderAndItem.OrderItem
// Order Target Costs
left outer to one join P_EBOrderTargetCostHdrAndItem( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderTargetCost on _OrderTargetCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderTargetCost.OrderItem = EvtBsdOrderAndItem.OrderItem
and _OrderTargetCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
// Order WIP Costs
left outer to one join P_EBOrderWIPCost3( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderWIPCost on _OrderWIPCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _OrderWIPCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderWIPCost.OrderItem = EvtBsdOrderAndItem.OrderItem
// Order Variances Costs
left outer to one join P_EBOrderVarianceCost2( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderVarianceCost on _OrderVarianceCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _OrderVarianceCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderVarianceCost.OrderItem = EvtBsdOrderAndItem.OrderItem
left outer to one join P_EBOrderSplitVarianceCost3( P_Ledger : :P_Ledger,
P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod,
P_CurrencyRole : :P_CurrencyRole ) as _OrderSplitVarianceCost on _OrderSplitVarianceCost.CompanyCode = EvtBsdOrderAndItem.CompanyCode
and _OrderSplitVarianceCost.OrderID = EvtBsdOrderAndItem.OrderID
and _OrderSplitVarianceCost.OrderItem = EvtBsdOrderAndItem.OrderItem
// Order Quantities
left outer to one join P_EBPC_MfgOutputQuantity( P_FromFiscalYearPeriod: :P_FromFiscalYearPeriod,
P_ToFiscalYearPeriod : :P_ToFiscalYearPeriod ) as _OrderOutpQty on _OrderOutpQty.ControllingObject = EvtBsdOrderAndItem.ObjectInternalID
{
key EvtBsdOrderAndItem.OrderID,
key EvtBsdOrderAndItem.OrderItem,
OrderInternalID, //Object number of order header
ObjectInternalID, //Object number of order item
// Order Header /////////////////////////////////////////////////
EvtBsdOrderAndItem.OrderType,
EvtBsdOrderAndItem.OrderCategory,
ExternalOrder,
OrderDescription,
EvtBsdOrderAndItem.Plant,
EvtBsdOrderAndItem.CompanyCode,
@Semantics.unitOfMeasure:true
cast(BaseUnit as fis_meinh) as BaseUnit,
@Semantics.unitOfMeasure:true
cast('%' as msehi) as RatioUnit,
// Assignment ///////////////////////////////////////////////////
:P_Ledger as Ledger,
ControllingArea,
BusinessArea,
ProfitCenter,
ResponsibleCostCenter,
WBSElementInternalID,
//Production Version
ProductionVersion,
// Sales Order
SalesOrder,
// Sales Order Item
EvtBsdOrderAndItem.SalesOrderItem,
Material,
MRPPlant,
StorageLocation,
@Semantics.unitOfMeasure:true
ProductionUnit,
EvtBsdOrderAndItem.ValuationType,
IsMarkedForDeletion,
MfgOrderHasMultipleItems,
ActualCostsCostingVariant,
PlannedCostsCostingVariant,
// Process //////////////////////////////////////////////////////
PlannedReleaseDate,
PlannedCompletionDate,
CreatedByUser,
CreationDate,
LastChangedByUser,
LastChangeDate,
TechnicalCompletionDate,
// Order Header PPS Orders //////////////////////////////////////
ScheduledBasicEndDate,
ScheduledReleaseDate,
ActualStartDate,
ConfirmedEndDate,
ActualReleasedDate,
// Order Status /////////////////////////////////////////////////
cast(_OrderKeyStatus.ControllingObjectStatus as fco_current_order_status) as ControllingObjectStatus,
// Order Key Status /////////////////////////////////////////////////
cast(_OrderKeyStatus.StatusCode as fco_current_order_key_status) as OrderKeyStatus,
// Currency /////////////////////////////////////////////////////
@Semantics.currencyCode: true
_LdgrCompCodeCrcy.Currency as DisplayCurrency,
// Order Planned Costs //////////////////////////////////////////
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderPlanCost.CreditPlanCostInDspCrcy, 0) as CreditPlanCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderPlanCost.DebitPlanCostInDspCrcy, 0) as DebitPlanCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderPlanCost.CreditPlanFxdCostInDspCrcy, 0) as CreditPlanFxdCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderPlanCost.DebitPlanFxdCostInDspCrcy, 0) as DebitPlanFxdCostInDspCrcy,
// Order Actual Costs ///////////////////////////////////////////
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderActualCost.CreditActlCostInDspCrcy, 0) as CreditActlCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderActualCost.DebitActlCostInDspCrcy, 0) as DebitActlCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderActualCost.CrdtActlFxdCostInDspCrcy, 0) as CrdtActlFxdCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderActualCost.DebitActlFixedCostInDspCrcy, 0) as DebitActlFixedCostInDspCrcy,
// Order Target Costs ///////////////////////////////////////////
@Semantics.amount.currencyCode: 'DisplayCurrency'
case
when EvtBsdOrderAndItem.OrderItem is initial or EvtBsdOrderAndItem.IsFixedPriceCoProduct = '' // NOT Fix Price Co-Product
then coalesce(_OrderTargetCost.CrdtTargetCostInDspCrcy, 0)
else coalesce(_OrderActualCost.CreditActlCostInDspCrcy, 0)
end as CrdtTargetCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
case
when EvtBsdOrderAndItem.OrderItem is initial or EvtBsdOrderAndItem.IsFixedPriceCoProduct = '' // NOT Fix Price Co-Product
then coalesce(_OrderTargetCost.DebitTargetCostInDspCrcy, 0)
else coalesce(_OrderActualCost.DebitActlCostInDspCrcy, 0)
end as DebitTargetCostInDspCrcy,
// Order WIP Costs //////////////////////////////////////////////
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderWIPCost.WIPCostInDspCrcy, 0) as WIPCostInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderWIPCost.UnrlzdCostRsrvAmtInDspCrcy, 0) as UnrlzdCostRsrvAmtInDspCrcy,
// Order Variances Costs ////////////////////////////////////////
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderVarianceCost.AmountInDisplayCurrency, 0) as CostVarianceInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderSplitVarianceCost.InptPrVarcAmtInDspCrcy, 0) as InptPrVarcAmtInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderSplitVarianceCost.InptQtyVarcAmtInDspCrcy, 0) as InptQtyVarcAmtInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderSplitVarianceCost.RsceUsgeVarcAmtInDspCrcy, 0) as RsceUsgeVarcAmtInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderSplitVarianceCost.LotSizeVarcAmtInDspCrcy, 0) as LotSizeVarcAmtInDspCrcy,
@Semantics.amount.currencyCode: 'DisplayCurrency'
coalesce(_OrderSplitVarianceCost.RmngVarcAmtInDspCrcy, 0) as RmngVarcAmtInDspCrcy,
// Output Quantities ////////////////////////////////////////////
@Semantics: { quantity : {unitOfMeasure: 'BaseUnit'} }
coalesce(_OrderOutpQty.PlanOutputQuantity, 0) as PlanOutputQuantity,
@Semantics: { quantity : {unitOfMeasure: 'BaseUnit'} }
coalesce(_OrderOutpQty.ActualOutputQuantity, 0) as ActualOutputQuantity
}
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_LEDGERCOMPANYCODECRCYROLESVH",
"P_COEVTBSDORDERKEYSTATUS",
"P_EBORDERACTUALCOST3",
"P_EBORDERPLANCOST3",
"P_EBORDERSPLITVARIANCECOST3",
"P_EBORDERTARGETCOSTHDRANDITEM",
"P_EBORDERVARIANCECOST2",
"P_EBORDERWIPCOST3",
"P_EBPC_MFGOUTPUTQUANTITY",
"P_REALTMEWRKINPROCORDHDANDITEM"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/