P_CapacityWithNightShift is a Composite CDS View in SAP S/4HANA. It reads from 1 data source (P_CapacityDefinition) and exposes 15 fields with key fields CapacityInternalID, WeekDayendasWeekDay, AvailableCapacityShift, CapacityActiveVersion.
@AbapCatalog.sqlViewName: 'PCAPNIGHT'
@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #NOT_REQUIRED@VDM.viewType: #COMPOSITE@VDM: {
private: true
}@AbapCatalog.preserveKey:true@ClientHandling.algorithm: #SESSION_VARIABLE/*
@EndUserText.label: 'Work Center Capacity With Night Shift'
*/defineview 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 NightSplitDate = 2 and ValidityEndDate < '99991231'
then dats_add_days(ValidityEndDate, 1, 'FAIL')
else ValidityEndDate
endas ValidityEndDate,
// key ValidityEndDate,
keycasewhen NightSplitDate = 2 and 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 NightSplitDate = 2
then 0
else CapacityStartTime
endas CapacityStartTime,
casewhen NightSplitDate = 2
then dats_add_days(ValidityBeginDate, 1, 'FAIL')
else ValidityBeginDate
endas ValidityBeginDate,
casewhen NightSplitDate isnullthen 1
else 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 NightSplitDate = 1
// if we are on the first day of the shift, the end of the shift is midnight
then 86400 --24 * 3600
else CapacityEndTime
endas CapacityEndTime,
// the total capacity is distributed according to the length of the part before and after midnight
casewhen OperatingDurationInSeconds = 0 or CapacityNumberOfCapacities = 0 // or CapacityPlanUtilizationPercent = 0
then 0
elsecasewhen NightSplitDate isnullthen 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 - CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities asabap.fltp) * cast ( 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(CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities asabap.fltp) * cast ( 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 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)
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(CapacityEndTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (OperatingDurationInSeconds) * cast (CapacityNumberOfCapacities asabap.fltp) * cast ( 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 OperatingDurationInSeconds = 0 or NightSplitDate isnullthen 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 - CapacityStartTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (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(CapacityEndTime asabap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) asabap.fltp) ) * (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 - CapacityStartTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (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(CapacityEndTime asabap.fltp) / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration asabap.fltp) ) * (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
}
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"P_CAPACITYDEFINITION",
"P_NIGHTSPLITFORSHIFT"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/