@AbapCatalog.sqlViewName: 'PRSHSMLTDOPCAP'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.private: true
@VDM.viewType: #CONSUMPTION
@ClientHandling.algorithm: #SESSION_VARIABLE
/*
CONTRACT**********************************************************************************************************************
Name: Read Simulated Operation duration and distributes the work
Specification: This view reads the simulated operation duration and distributes it between the simulated dates
- First leg of the union is to read multiday operations with simulated dates set
- Second leg of the union reads single day operations and operations with due status.
Requires: NA
Ensures: Work Distributed per day is calculated
Owners: AN
Contributors: CF
Unit Test required Y/N: Yes
Additional comments
END OF CONTRACT***************************************************************************************************************
*/
define view P_RSHSmltdOpCapacity
as select from P_RSHSmltdOpInSeconds as SimulatedOperations
inner join P_RSHWCCapacityPerWorkDay as WorkCenterCapacity on WorkCenterCapacity.WorkCenterInternalID = SimulatedOperations.WorkCenterInternalID
and WorkCenterCapacity.CalendarDate <= SimulatedOperations.ConsumingEndDate
and WorkCenterCapacity.CalendarDate >= SimulatedOperations.ConsumingStartDate
{
key SimulatedOperations.MaintSchedSimlnUUID,
key SimulatedOperations.MaintenanceOrder,
key SimulatedOperations.MaintenanceOrderOperation,
key SimulatedOperations.MaintenanceOrderSubOperation,
key WorkCenterCapacity.CalendarDate,
key WorkCenterCapacity.CapacityStartTime,
SimulatedOperations.WorkCenterInternalID as WorkCenterInternalId,
WorkCenterCapacity.CapacityInternalID,
WorkCenterCapacity.WorkCenter,
WorkCenterCapacity.WorkCenterCategoryCode,
WorkCenterCapacity.WorkCenterTypeCode,
WorkCenterCapacity.Plant,
OperationPlannedWork,
OperationDuration,
MaintOrdOpSimulatedStartDate,
MaintOrdOpSimulatedEndDate,
ProcessingStatus,
MaintPriority,
MaintPriorityType,
MaintPriorityColorCode,
OrderType,
ActivityType,
SimulatedOperations.OperationControlKey,
MaintOrdOpSimulationStatus,
SimulatedOperations.NumberOfCapacities as NumberOfCapacities,
// for utilization calculation, we need the entire weeks capacity
WorkCenterCapacity.TotOperatingDurationInSeconds,
-- if the capacity date is not on the start date and not on the end date of the operation, it must be between these dates
-- on these days, the operation fully spans the shift and hence always consumes te entire shift capacity
(case
when ( CalendarDate > ConsumingStartDate and
CalendarDate < ConsumingEndDate ) -- capacity on fully covered days
then WorkCenterCapacity.OperatingDurationInSeconds
else
-- If the operation ends after the capacity starts, we calculate the available capacity
-- Example:
-- Capacity 09:00 to 17:00 with 1 hour break duration. Operation end 16:00, start on another day
-- OperatingDurationInHours is 17 - 9 - 1 = 7 hours (in seconds)
-- This calculation determines the capacity in this shift available for the operation by
-- ( 57.600 (OperationEndTime) - 32.400 (CapacityStartTime) ) / ( 61.200 (CapacityEndTime) - 32.400 (CapacityStartTime) ) * 25.200 (OperatingDurationInHours)
-- = 25.200 (Opening Hours in parallel to operation in this shift) / 28.800 (total opening hours of this shift) * 25.200 (Single resource capacity of the shift)
-- = 22.050 (Single resource capacity of the shift available to the operation)
case
when CalendarDate = ConsumingStartDate
then
case -- check if Capacity is already been ended before Operation start date then there is no capacity consider 0
when ConsumingStartTimeInSeconds >= WorkCenterCapacity.CapacityEndTime
then 0
else -- in case Capacity falls under Operation start date
case
when ( ConsumingStartTimeInSeconds > WorkCenterCapacity.CapacityStartTime )
then -- in case Capacity start time is before Operation planned start time, then calaculate the use subtract the PlannedStartTimeInSeconds
cast( WorkCenterCapacity.CapacityEndTime - ConsumingStartTimeInSeconds as abap.fltp) /
cast( WorkCenterCapacity.CapacityEndTime - WorkCenterCapacity.CapacityStartTime as abap.fltp) * WorkCenterCapacity.OperatingDurationInSeconds
else -- in case Operation start time is before Capacity start time then no need to calculate
WorkCenterCapacity.OperatingDurationInSeconds
end
end
-- In case Capacity Calendar Date is same as Operation End date.
else
case
when CalendarDate = ConsumingEndDate
then
case
when (ConsumingEndTimeInSeconds <= WorkCenterCapacity.CapacityStartTime)
then 0
else
case
when ConsumingEndTimeInSeconds < WorkCenterCapacity.CapacityEndTime
then -- in case Capacity end time is after Operation planned end time, then subtract from PlannedEndTime
cast ( ConsumingEndTimeInSeconds - WorkCenterCapacity.CapacityStartTime as abap.fltp) /
cast ( WorkCenterCapacity.CapacityEndTime - WorkCenterCapacity.CapacityStartTime as abap.fltp) * WorkCenterCapacity.OperatingDurationInSeconds
else -- in case Operation end time is after Capacity end time then no need to calculate
WorkCenterCapacity.OperatingDurationInSeconds
end
end
else 0
end
end
end ) as CalCapacityInParallel
}
where
//Only select multiday operations with simulated dates set
ConsumingStartDate < ConsumingEndDate
and ProcessingStatus = 25
union all select from P_RSHSmltdOpInSeconds as OperationDetails
inner join I_RSHAssignedWorkCenters as WorkCenterDetails on WorkCenterDetails.WorkCenterInternalID = OperationDetails.WorkCenterInternalID
{
key OperationDetails.MaintSchedSimlnUUID,
key OperationDetails.MaintenanceOrder,
key OperationDetails.MaintenanceOrderOperation,
key OperationDetails.MaintenanceOrderSubOperation as MaintenanceOrderSubOperation,
key OperationDetails.ConsumingStartDate as CalendarDate,
key 0 as CapacityStartTime,
OperationDetails.WorkCenterInternalID as WorkCenterInternalId,
WorkCenterDetails.CapacityInternalID,
WorkCenterDetails.WorkCenter,
WorkCenterDetails.WorkCenterCategoryCode,
WorkCenterDetails.WorkCenterTypeCode,
WorkCenterDetails.Plant,
OperationPlannedWork,
OperationDuration,
MaintOrdOpSimulatedStartDate,
MaintOrdOpSimulatedEndDate,
ProcessingStatus,
MaintPriority,
MaintPriorityType,
MaintPriorityColorCode,
OrderType,
ActivityType,
OperationControlKey,
MaintOrdOpSimulationStatus,
// key SimulatedOperations.OperationDayCount as OperationDayCount,
OperationDetails.NumberOfCapacities as NumberOfCapacities,
// for utilization calculation, we need the entire weeks capacity
0 as TotOperatingDurationInSeconds,
OperationPlannedWork as CalCapacityInParallel
}
where
//Select all single day operations with simulated dates set and due operations
ConsumingStartDate = ConsumingEndDate
or ProcessingStatus = 20
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_RSHASSIGNEDWORKCENTERS",
"P_RSHSMLTDOPINSECONDS",
"P_RSHWCCAPACITYPERWORKDAY"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/