P_WorkCenterAvailableCapacity

DDL: P_WORKCENTERAVAILABLECAPACITY SQL: PWRKCTRAVAILCAP Type: view COMPOSITE

P_WorkCenterAvailableCapacity is a Composite CDS View in SAP S/4HANA. It reads from 2 data sources (P_CapacityDefinition, P_WrkCtrWorkDayTableFunction) and exposes 33 fields with key fields WorkCenterInternalID, WorkCenterTypeCode, CapacityCategoryAllocation, CapacityInternalID, ValidityEndDate.

Data Sources (2)

SourceAliasJoin Type
P_CapacityDefinition CapacityPerShift inner
P_WrkCtrWorkDayTableFunction P_WrkCtrWorkDayTableFunction inner

Annotations (6)

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

Fields (33)

KeyFieldSource TableSource FieldDescription
KEY WorkCenterInternalID WorkCenterCapacity WorkCenterInternalID
KEY WorkCenterTypeCode WorkCenterCapacity WorkCenterTypeCode
KEY CapacityCategoryAllocation WorkCenterCapacity CapacityCategoryAllocation
KEY CapacityInternalID WorkCenterCapacity CapacityInternalID
KEY ValidityEndDate P_CapacityDefinition ValidityEndDate
KEY WeekDay
KEY AvailableCapacityShift P_CapacityDefinition AvailableCapacityShift
KEY CalendarDate WorkDays CalendarDate
ShiftStartDate P_CapacityDefinition ShiftStartDate
ShiftStartTime P_CapacityDefinition ShiftStartTime
ShiftEndDate P_CapacityDefinition ShiftEndDate
ShiftEndTime P_CapacityDefinition ShiftEndTime
CapacityBreakDuration
WorkCenterCapacityUnit
WorkCenterUtilizationUnit
ValidityBeginDate P_CapacityDefinition ValidityBeginDate
CalendarMonth WorkDays CalendarMonth
CalendarYear WorkDays CalendarYear
CalendarWeek WorkDays CalendarWeek
WorkDays WorkDays WorkDays
WorkCenterPlant P_CapacityDefinition Plant
CapacityCategoryCode P_CapacityDefinition CapacityCategoryCode
ShiftNameendasShiftName
ShiftDefinition P_CapacityDefinition ShiftDefinition
ShiftGrouping P_CapacityDefinition ShiftGrouping
WorkDayRule P_CapacityDefinition WorkDayRule
FactoryCalendar P_CapacityDefinition FactoryCalendar
CapacityStartTime P_CapacityDefinition CapacityStartTime
CapacityEndTime P_CapacityDefinition CapacityEndTime
CapacityNumberOfCapacities P_CapacityDefinition CapacityNumberOfCapacities
CapacityPlanUtilizationPercent P_CapacityDefinition CapacityPlanUtilizationPercent
fltpendasTotOperatingDurationInHours
fltpendasCapacityOperatingDuration
@ClientHandling.algorithm: #SESSION_VARIABLE
@AbapCatalog.sqlViewName: 'PWRKCTRAVAILCAP'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck:#NOT_REQUIRED
@VDM.viewType: #COMPOSITE
@VDM.private: true

define view P_WorkCenterAvailableCapacity
  as select distinct from I_WorkCenterCapacity                                        as WorkCenterCapacity
    inner join            P_CapacityDefinition                                        as CapacityPerShift on WorkCenterCapacity.CapacityInternalID = CapacityPerShift.CapacityInternalID
    inner join            P_WrkCtrWorkDayTableFunction(p_sapclient : $session.client) as WorkDays         on
                                                                                                              //                           WorkDays.WorkCenterInternalID = CapacityPerShift.WorkCenterInternalID

                                                                                                              //                           and WorkDays.WorkCenterTypeCode = CapacityPerShift.WorkCenterTypeCode

                                                                                                              //                           and WorkDays.CapacityInternalID = CapacityPerShift.CapacityInternalID

                                                                                                              //                           and WorkDays.CapacityCategoryAllocation = CapacityPerShift.CapacityCategoryAllocation and

                                                                                                              WorkDays.factoryCalendar                        =  CapacityPerShift.FactoryCalendar
                                                                                                          and WorkDays.CalendarDate                           <= CapacityPerShift.ValidityEndDate
    //                              and CapacityPerShift.ValidityBeginDate <> '00000000'

    //                              and CapacityPerShift.ValidityEndDate <> '00000000'

                                                                                                          and WorkDays.CalendarDate                           >= CapacityPerShift.ValidityBeginDate
                                                                                                          and (
                                                                                                             (
                                                                                                               CapacityPerShift.WorkDayRule                   =  ''
                                                                                                               and // we are only interested in workdays

                                                                                                               WorkDays.WorkDays                              =  1
                                                                                                             )
                                                                                                             or(
                                                                                                               CapacityPerShift.WorkDayRule                   =  '1'
                                                                                                             )
                                                                                                           )
                                                                                                          and (
                                                                                                             (
                                                                                                               CapacityPerShift.AvailableCapacityIntervalDurn =  '01'
                                                                                                             )     // 1 day shift interval duration

                                                                                                             or(
                                                                                                               CapacityPerShift.AvailableCapacityIntervalDurn =  '07'
                                                                                                               and // 7 day shift interval duration

                                                                                                               WorkDays.Weekday                               =  CapacityPerShift.WeekDay
                                                                                                             )
                                                                                                           )
{
  key WorkCenterCapacity.WorkCenterInternalID                                             as WorkCenterInternalID,
  key WorkCenterCapacity.WorkCenterTypeCode                                               as WorkCenterTypeCode,
  key WorkCenterCapacity.CapacityCategoryAllocation,
  key WorkCenterCapacity.CapacityInternalID,
      //key coalesce( CapacityPerShift.CapacityActiveVersion, '00')                             as CapacityActiveVersion,

  key case when CapacityPerShift.CapacityActiveVersion is not null
            then CapacityPerShift.CapacityActiveVersion
           when CapacityPerShift.CapacityActiveVersion is null
            then '00'
           end                                                                            as CapacityActiveVersion,
  key CapacityPerShift.ValidityEndDate,

  key cast( WorkDays.Weekday as char1)                                                    as WeekDay,

  key CapacityPerShift.AvailableCapacityShift,
  key WorkDays.CalendarDate,
      CapacityPerShift.ShiftStartDate,
      CapacityPerShift.ShiftStartTime,
      CapacityPerShift.ShiftEndDate,
      CapacityPerShift.ShiftEndTime,

      cast(CapacityPerShift.CapacityBreakDuration as abap.fltp) / cast(3600 as abap.fltp) as CapacityBreakDuration,
      cast('H' as unit)                                                                   as WorkCenterCapacityUnit,
      cast('%' as unit)                                                                   as WorkCenterUtilizationUnit,
      CapacityPerShift.ValidityBeginDate,
      WorkDays.CalendarMonth,
      WorkDays.CalendarYear,
      WorkDays.CalendarWeek,

      //     key WorkDays.CalendarDate,

      WorkDays.WorkDays,
      //     WorkDays.WorkCenter,

      CapacityPerShift.Plant                                                              as WorkCenterPlant,
      CapacityPerShift.CapacityCategoryCode,

      //     case when (CapacityPerShift.ShiftName = '' and CapacityPerShift.AvailableCapacityShift <> '') then

      //      concat('SH ', CapacityPerShift.AvailableCapacityShift)

      //      else

      //      CapacityPerShift.ShiftName

      //     end

      //     as ShiftName,


      case when (CapacityPerShift.ShiftName = '' and CapacityPerShift.AvailableCapacityShift <> '')
            then concat('SH ', CapacityPerShift.AvailableCapacityShift)
        when ((CapacityPerShift.ShiftName <> '')
              or (CapacityPerShift.ShiftName = '' and CapacityPerShift.AvailableCapacityShift = ''))
            then CapacityPerShift.ShiftName
        end                                                                               as ShiftName,

      CapacityPerShift.ShiftDefinition,
      CapacityPerShift.ShiftGrouping,
      CapacityPerShift.WorkDayRule,
      CapacityPerShift.FactoryCalendar,
      //     case

      //          when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or

      //               CapacityPerShift.WorkDayRule = '0' or

      //               CapacityPerShift.CapacityEndTime = CapacityPerShift.CapacityStartTime or

      //               CapacityPerShift.OperatingDurationInSeconds = 0

      //          then 0

      //          else

      //           CapacityPerShift.OperatingDurationInSeconds

      //          end

      //           as OperatingDurationInSeconds,

      //

      //     case

      //      when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or

      //              CapacityPerShift.WorkDayRule = '0' or

      //              CapacityPerShift.CapacityEndTime = CapacityPerShift.CapacityStartTime or

      //              CapacityPerShift.OperatingDurationInSeconds = 0

      //         then 0

      //         else

      //       CapacityPerShift.TotOperatingDurationInSeconds

      //      end  as TotOperatingDurationInSeconds,

      CapacityPerShift.CapacityStartTime,
      CapacityPerShift.CapacityEndTime,
      CapacityPerShift.CapacityNumberOfCapacities,
      CapacityPerShift.CapacityPlanUtilizationPercent,
      //          case

      //                when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or

      //                     CapacityPerShift.WorkDayRule = '0' or

      //                     CapacityPerShift.CapacityEndTime = CapacityPerShift.CapacityStartTime or

      //                     CapacityPerShift.OperatingDurationInSeconds = 0

      //                then 0

      //                else

      //                 CapacityPerShift.OperatingDurationInSeconds / cast ( 3600 as abap.fltp )

      //                end

      //                 as OperatingDurationInHours,


      case
         when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or
               CapacityPerShift.WorkDayRule = '0' or
      //               CapacityPerShift.CapacityEndTime = CapacityPerShift.CapacityStartTime or

               CapacityPerShift.OperatingDurationInSeconds = 0
          then 0
          else
          CapacityPerShift.TotOperatingDurationInSeconds / cast ( 3600 as abap.fltp )
         end                                                                              as TotOperatingDurationInHours,

      //      case

      //         when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or

      //               CapacityPerShift.WorkDayRule = '0' or

      //      //               CapacityPerShift.CapacityEndTime = CapacityPerShift.CapacityStartTime or

      //               CapacityPerShift.OperatingDurationInSeconds = 0

      //          then 0

      //          when WorkDays.WorkDays <> 0 and CapacityPerShift.WorkDayRule <> '' or

      //               CapacityPerShift.WorkDayRule <> '0' or CapacityPerShift.OperatingDurationInSeconds <> 0

      //          then CapacityPerShift.TotOperatingDurationInSeconds / cast ( 3600 as abap.fltp )

      //         end                                                                              as TotOperatingDurationInHours,


      case
         when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or
               CapacityPerShift.WorkDayRule = '0' or
               CapacityPerShift.CapacityOperatingDuration = 0
          then 0
          else
          CapacityPerShift.CapacityOperatingDuration / cast ( 3600 as abap.fltp )
      end                                                                                 as CapacityOperatingDuration

      //      case

      //         when WorkDays.WorkDays = 0 and CapacityPerShift.WorkDayRule = '' or

      //               CapacityPerShift.WorkDayRule = '0' or

      //               CapacityPerShift.CapacityOperatingDuration = 0

      //          then 0

      //            when WorkDays.WorkDays <> 0 and CapacityPerShift.WorkDayRule <> '' or

      //               CapacityPerShift.WorkDayRule <> '0' or

      //               CapacityPerShift.CapacityOperatingDuration <> 0

      //          then

      //          CapacityPerShift.CapacityOperatingDuration / cast ( 3600 as abap.fltp )

      //      end                                                                                 as CapacityOperatingDuration

}