P_CapacityWithNightShift

DDL: P_CAPACITYWITHNIGHTSHIFT SQL: PCAPNIGHT Type: view COMPOSITE

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.

Data Sources (1)

SourceAliasJoin Type
P_CapacityDefinition CapaDef from

Annotations (7)

NameValueLevelField
AbapCatalog.sqlViewName PCAPNIGHT view
AbapCatalog.compiler.compareFilter true view
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.viewType #COMPOSITE view
VDM.private true view
AbapCatalog.preserveKey true view
ClientHandling.algorithm #SESSION_VARIABLE view

Fields (15)

KeyFieldSource TableSource FieldDescription
KEY CapacityInternalID P_CapacityDefinition CapacityInternalID
KEY WeekDayendasWeekDay
KEY AvailableCapacityShift P_CapacityDefinition AvailableCapacityShift
KEY CapacityActiveVersion P_CapacityDefinition CapacityActiveVersion
ShiftName P_CapacityDefinition ShiftName
Plant P_CapacityDefinition Plant
FactoryCalendar P_CapacityDefinition FactoryCalendar
CapacityCategoryCode P_CapacityDefinition CapacityCategoryCode
CapacityCategoryName P_CapacityDefinition CapacityCategoryName
Capacity P_CapacityDefinition Capacity
CapacityResponsiblePlanner P_CapacityDefinition CapacityResponsiblePlanner
WorkDayRule P_CapacityDefinition WorkDayRule
CapacityBreakDuration P_CapacityDefinition CapacityBreakDuration
CapacityNumberOfCapacities P_CapacityDefinition CapacityNumberOfCapacities
CapacityPlanUtilizationPercent P_CapacityDefinition CapacityPlanUtilizationPercent
@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'
*/
define view P_CapacityWithNightShift
  as select from    P_CapacityDefinition as CapaDef
    left outer 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,
  key case when NightSplitDate = 2 and ValidityEndDate < '99991231'
          then dats_add_days(ValidityEndDate, 1, 'FAIL')
          else ValidityEndDate
     end                                 as ValidityEndDate,
      //  key ValidityEndDate,


  key case
      when NightSplitDate = 2 and AvailableCapacityIntervalDurn = '07'
       then case 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
            end
      else
           CapaDef.WeekDay
      end                                as 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) in case of the part after midnight

      // This is an additional key to identify night shifts

      case when NightSplitDate = 2
       then 0
       else CapacityStartTime
      end                                as CapacityStartTime,


      case when NightSplitDate = 2
           then dats_add_days(ValidityBeginDate, 1, 'FAIL')
           else ValidityBeginDate
      end                                as ValidityBeginDate,


      case when NightSplitDate is null
          then 1
      else NightSplitDate
      end                                as NightSplitDate,


      // Interval cycle 07 is only required in case of working day

      case when CapaDef.WorkDayRule <> '0' then
      CapaDef.AvailableCapacityIntervalDurn
      else '01'
      end                                              as AvailableCapacityIntervalDurn,
      CapaDef.WorkDayRule,

      //      // the end time is 24*3600 (24:00:00 is seconds format) in case of the part before midnight

      case when 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
      end                                as CapacityEndTime,


      // the total capacity is distributed according to the length of the part before and after midnight

      case when OperatingDurationInSeconds = 0 or CapacityNumberOfCapacities = 0 // or CapacityPlanUtilizationPercent = 0

             then 0
              else
              case
              when NightSplitDate is null
                      then TotOperatingDurationInSeconds
              when CapaDef.ShiftName is not null
                      then
                      case
                      when 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 as abap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.fltp) ) * (OperatingDurationInSeconds)  * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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 as abap.fltp)            / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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

                          else
                          case when NightSplitDate = 1
                               then cast( 86400 - CapacityStartTime as abap.fltp) / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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 as abap.fltp)            / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds) * cast (CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.fltp)
                          end
                 end
            end                          as TotOperatingDurationInSeconds,

      // the total capacity is distributed according to the length of the part before and after midnight

      //      case when OperatingDurationInSeconds = 0 or CapacityNumberOfCapacities = 0

      //                then 0

      //               when NightSplitDate is null

      //                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 is not null and NightSplit.NightSplitDate = 1

      //                then ( cast( 86400 - CapacityStartTime as abap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.fltp) ) * (OperatingDurationInSeconds)  * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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 is not null and NightSplit.NightSplitDate <> 1

      //                then ( cast(CapacityEndTime as abap.fltp)            / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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 is null and NightSplit.NightSplitDate = 1

      //                then cast( 86400 - CapacityStartTime as abap.fltp) / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds) * cast(CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.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 is null and NightSplit.NightSplitDate <> 1

      //                then  cast(CapacityEndTime as abap.fltp)            / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds) * cast (CapacityNumberOfCapacities as abap.fltp) * cast ( CapacityPlanUtilizationPercent as abap.fltp ) / cast(100 as abap.fltp)

      //               end                       as TotOperatingDurationInSeconds,


      // the opening hours are distributed according to the length of the part before and after midnight

      case when OperatingDurationInSeconds = 0 or NightSplitDate is null
           then OperatingDurationInSeconds
           else
                         case
              when CapaDef.ShiftName is not null
                      then
                      case when 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 as abap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.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 as abap.fltp)            / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.fltp) ) * (OperatingDurationInSeconds))
                       end

           when 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 as abap.fltp) / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.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 as abap.fltp)            / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds)
                 end
             end                         as OperatingDurationInSeconds,

      // the opening hours are distributed according to the length of the part before and after midnight

      //      case when OperatingDurationInSeconds = 0 or NightSplitDate is null

      //            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 is not null) and CapaDef.ShiftName is not null and NightSplit.NightSplitDate = 1

      //            then ( cast( 86400 - CapacityStartTime as abap.fltp) / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.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 is not null) and CapaDef.ShiftName is not null and NightSplit.NightSplitDate <> 1

      //            then ( cast(CapacityEndTime as abap.fltp)            / ( cast( 86400 - (CapacityStartTime - CapacityEndTime) as abap.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 is not null) and CapaDef.ShiftName is null and NightSplit.NightSplitDate = 1

      //            then cast( 86400 - CapacityStartTime as abap.fltp) / (  ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.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 is not null) and CapaDef.ShiftName is null and NightSplit.NightSplitDate <> 1

      //            then cast(CapacityEndTime as abap.fltp)            / ( ( OperatingDurationInSeconds ) + cast(CapacityBreakDuration as abap.fltp) ) * (OperatingDurationInSeconds)

      //           end                           as 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":""
}
}*/