P_CapacityWithNightShift is a Composite CDS View that provides data about "Work Center Capacity With Night Shift" in SAP S/4HANA. It reads from 1 data source (P_CapacityDefinition) and exposes 20 fields with key fields CapacityInternalID, ValidityEndDateendasValidityEndDate, WeekDayendasWeekDay, AvailableCapacityShift, CapacityActiveVersion. Part of development package PPH_VDM_CAP_EVAL.
@AccessControl.authorizationCheck: #NOT_REQUIRED@VDM.viewType: #COMPOSITE@VDM: {
private: true
}defineviewentity P_CapacityWithNightShift
asselectfrom P_CapacityDefinition as CapaDef
leftouter to many join P_NightSplitForShift as NightSplit on CapaDef.CapacityEndTime <= CapaDef.CapacityStartTime
and CapaDef.CapacityStartTime <> 0
{
// key CapaDef.WorkCenterInternalID as WorkCenterInternalID,
// key CapaDef.WorkCenterTypeCode as WorkCenterTypeCode,
// key CapaDef.CapacityCategoryAllocation as CapacityCategoryAllocation,
key CapaDef.CapacityInternalID as CapacityInternalID,
keycasewhen NightSplit.NightSplitDate = 2 and CapaDef.ValidityEndDate < '99991231'
then dats_add_days(CapaDef.ValidityEndDate, 1, 'FAIL')
else CapaDef.ValidityEndDate
endas ValidityEndDate,
// key ValidityEndDate,
keycasewhen NightSplit.NightSplitDate = 2 and CapaDef.AvailableCapacityIntervalDurn = '07'
thencase CapaDef.WeekDay
when '7' then '1'
when '6' then '7'
when '5' then '6'
when '4' then '5'
when '3' then '4'
when '2' then '3'
when '1' then '2'
else
CapaDef.WeekDay
endelse
CapaDef.WeekDay
endas WeekDay,
key CapaDef.AvailableCapacityShift as AvailableCapacityShift,
key CapaDef.CapacityActiveVersion as CapacityActiveVersion,
CapaDef.ShiftName as ShiftName,
// CapaDef.WorkCenter as WorkCenter,
CapaDef.Plant as Plant,
CapaDef.FactoryCalendar as FactoryCalendar,
// CapaDef.WorkCenterResponsible as WorkCenterResponsible,
// CapaDef.WorkCenterDesc as WorkCenterDesc,
// CapaDef.WorkCenterCategoryCode as WorkCenterCategoryCode,
CapaDef.CapacityCategoryCode as CapacityCategoryCode,
CapaDef.CapacityCategoryName as CapacityCategoryName,
CapaDef.Capacity as Capacity,
// CapaDef.CapacityText as CapacityText,
CapaDef.CapacityResponsiblePlanner as CapacityResponsiblePlanner,
// the start time is 0 (midnight) incase of the part after midnight
// This is an additional key to identify night shifts
casewhen NightSplit.NightSplitDate = 2
then 0
else CapaDef.CapacityStartTime
endas CapacityStartTime,
casewhen NightSplit.NightSplitDate = 2
then dats_add_days(CapaDef.ValidityBeginDate, 1, 'FAIL')
else CapaDef.ValidityBeginDate
endas ValidityBeginDate,
casewhen NightSplit.NightSplitDate isnullthen 1
else NightSplit.NightSplitDate
endas NightSplitDate,
// Interval cycle 07 is only required incase of working day
casewhen CapaDef.WorkDayRule <> '0' then
CapaDef.AvailableCapacityIntervalDurn
else '01'
endas AvailableCapacityIntervalDurn,
CapaDef.WorkDayRule,
// // the end time is 24*3600 (24:00:00 is seconds format) incase of the part before midnight
casewhen NightSplit.NightSplitDate = 1
// if we are on the first day of the shift, the end of the shift is midnight
then 86400 --24 * 3600
else CapaDef.CapacityEndTime
endas CapacityEndTime,
// the total capacity is distributed according to the length of the part before and after midnight
casewhen CapaDef.OperatingDurationInSeconds = 0 or CapaDef.CapacityNumberOfCapacities = 0 // or CapacityPlanUtilizationPercent = 0
then 0
elsecasewhen NightSplit.NightSplitDate isnullthen CapaDef.TotOperatingDurationInSeconds
when CapaDef.ShiftName isnotnullthencasewhen NightSplit.NightSplitDate = 1
then// in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
( cast( 86400 - CapaDef.CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast(CapaDef.CapacityNumberOfCapacities asabap.fltp) * cast ( CapaDef.CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp))
else// in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
( cast(CapaDef.CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast(CapaDef.CapacityNumberOfCapacities asabap.fltp) * cast ( CapaDef.CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp))
end// in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the total capacity
elsecasewhen NightSplit.NightSplitDate = 1
thencast( 86400 - CapaDef.CapacityStartTime asabap.fltp) / ( ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast(CapaDef.CapacityNumberOfCapacities asabap.fltp) * cast ( CapaDef.CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp)
else// in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the total capacity
cast(CapaDef.CapacityEndTime asabap.fltp) / ( ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast (CapaDef.CapacityNumberOfCapacities asabap.fltp) * cast ( CapaDef.CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp)
endendendas TotOperatingDurationInSeconds,
// the total capacity is distributed according to the length of the part before and after midnight
// casewhen OperatingDurationInSeconds = 0 or CapacityNumberOfCapacities = 0
// then 0
// when NightSplitDate isnull// then TotOperatingDurationInSeconds
// // in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
// when CapaDef.ShiftName isnotnulland NightSplit.NightSplitDate = 1
// then ( cast( 86400 - CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities asabap.fltp) * cast ( CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp))
// // in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
// when CapaDef.ShiftName isnotnulland NightSplit.NightSplitDate <> 1
// then ( cast(CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities asabap.fltp) * cast ( CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp))
// // in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the total capacity
// when (OperatingDurationInSeconds <> 0 or CapacityNumberOfCapacities <> 0) and CapaDef.ShiftName isnulland NightSplit.NightSplitDate = 1
// thencast( 86400 - CapacityStartTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities asabap.fltp) * cast ( CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp)
// // in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the total capacity
// when (OperatingDurationInSeconds <> 0 or CapacityNumberOfCapacities <> 0) and CapaDef.ShiftName isnulland NightSplit.NightSplitDate <> 1
// thencast(CapacityEndTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (OperatingDurationInSeconds) * cast (CapacityNumberOfCapacities asabap.fltp) * cast ( CapacityPlanUtilizationPercent asabap.fltp ) / cast(100 asabap.fltp)
// endas TotOperatingDurationInSeconds,
// the opening hours are distributed according to the length of the part before and after midnight
casewhen CapaDef.OperatingDurationInSeconds = 0 or NightSplit.NightSplitDate isnullthen CapaDef.OperatingDurationInSeconds
elsecasewhen CapaDef.ShiftName isnotnullthencasewhen NightSplit.NightSplitDate = 1
then// in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
( cast( 86400 - CapaDef.CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds) )
else// in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
( cast(CapaDef.CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds))
endwhen NightSplit.NightSplitDate = 1 then// in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
cast( 86400 - CapaDef.CapacityStartTime asabap.fltp) / ( ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds)
else// in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
cast(CapaDef.CapacityEndTime asabap.fltp) / ( ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration asabap.fltp) ) * (CapaDef.OperatingDurationInSeconds)
endendas OperatingDurationInSeconds,
// the opening hours are distributed according to the length of the part before and after midnight
// casewhen OperatingDurationInSeconds = 0 or NightSplitDate isnull// then OperatingDurationInSeconds
// // in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
// when (OperatingDurationInSeconds <> 0 or NightSplitDate isnotnull) and CapaDef.ShiftName isnotnulland NightSplit.NightSplitDate = 1
// then ( cast( 86400 - CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds) )
// // in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
// when (OperatingDurationInSeconds <> 0 or NightSplitDate isnotnull) and CapaDef.ShiftName isnotnulland NightSplit.NightSplitDate <> 1
// then ( cast(CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds))
// // in the case before midnight, the single capacity is the share of the hours before midnight in the total hours (including break) of the OperatingDurationInSeconds
// when (OperatingDurationInSeconds <> 0 or NightSplitDate isnotnull) and CapaDef.ShiftName isnulland NightSplit.NightSplitDate = 1
// thencast( 86400 - CapacityStartTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (OperatingDurationInSeconds)
// // in the case after midnight, the single capacity is the share of the hours after midnight in the total hours (including break) of the OperatingDurationInSeconds
// when (OperatingDurationInSeconds <> 0 or NightSplitDate isnotnull) and CapaDef.ShiftName isnulland NightSplit.NightSplitDate <> 1
// thencast(CapacityEndTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (OperatingDurationInSeconds)
// endas OperatingDurationInSeconds,
CapaDef.CapacityBreakDuration,
CapaDef.CapacityNumberOfCapacities,
CapaDef.CapacityPlanUtilizationPercent
}