P_CapacityWithNightShift

DDL: P_CAPACITYWITHNIGHTSHIFT Type: view_entity COMPOSITE Package: PPH_VDM_CAP_EVAL

Work Center Capacity With Night Shift

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.

Data Sources (1)

SourceAliasJoin Type
P_CapacityDefinition CapaDef from

Annotations (3)

NameValueLevelField
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.viewType #COMPOSITE view
VDM.private true view

Fields (20)

KeyFieldSource TableSource FieldDescription
KEY CapacityInternalID P_CapacityDefinition CapacityInternalID
KEY ValidityEndDateendasValidityEndDate
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
CapacityStartTimeendasCapacityStartTime
ValidityBeginDateendasValidityBeginDate
NightSplitDateendasNightSplitDate
WorkDayRule P_CapacityDefinition WorkDayRule
CapacityEndTimeendasCapacityEndTime
CapacityBreakDuration P_CapacityDefinition CapacityBreakDuration
CapacityNumberOfCapacities P_CapacityDefinition CapacityNumberOfCapacities
CapacityPlanUtilizationPercent P_CapacityDefinition CapacityPlanUtilizationPercent
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #COMPOSITE
@VDM: {
  private: true
}
define view entity 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 NightSplit.NightSplitDate = 2 and CapaDef.ValidityEndDate < '99991231'
          then dats_add_days(CapaDef.ValidityEndDate, 1, 'FAIL')
          else CapaDef.ValidityEndDate
     end                                 as ValidityEndDate,
      //  key ValidityEndDate,


  key case
      when NightSplit.NightSplitDate = 2 and CapaDef.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 NightSplit.NightSplitDate = 2
       then 0
       else CapaDef.CapacityStartTime
      end                                as CapacityStartTime,


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


      case when NightSplit.NightSplitDate is null
          then 1
      else NightSplit.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 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
      end                                as CapacityEndTime,


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

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

             then 0
              else
              case
              when NightSplit.NightSplitDate is null
                      then CapaDef.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 - CapaDef.CapacityStartTime as abap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) as abap.fltp) ) * (CapaDef.OperatingDurationInSeconds)  * cast(CapaDef.CapacityNumberOfCapacities as abap.fltp) * cast ( CapaDef.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(CapaDef.CapacityEndTime as abap.fltp)            / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) as abap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast(CapaDef.CapacityNumberOfCapacities as abap.fltp) * cast ( CapaDef.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 NightSplit.NightSplitDate = 1
                               then cast( 86400 - CapaDef.CapacityStartTime as abap.fltp) / (  ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration as abap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast(CapaDef.CapacityNumberOfCapacities as abap.fltp) * cast ( CapaDef.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(CapaDef.CapacityEndTime as abap.fltp)            / (  ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration as abap.fltp) ) * (CapaDef.OperatingDurationInSeconds) * cast (CapaDef.CapacityNumberOfCapacities as abap.fltp) * cast ( CapaDef.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 CapaDef.OperatingDurationInSeconds = 0 or NightSplit.NightSplitDate is null
           then CapaDef.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 - CapaDef.CapacityStartTime as abap.fltp) / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) as abap.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 as abap.fltp)            / ( cast( 86400 - (CapaDef.CapacityStartTime - CapaDef.CapacityEndTime) as abap.fltp) ) * (CapaDef.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 - CapaDef.CapacityStartTime as abap.fltp) / (  ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration as abap.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 as abap.fltp)            / ( ( CapaDef.OperatingDurationInSeconds ) + cast(CapaDef.CapacityBreakDuration as abap.fltp) ) * (CapaDef.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
}