P_RSHOPERATIONWORKPERDAY

CDS View

Operation Work per Day

P_RSHOPERATIONWORKPERDAY is a CDS View in S/4HANA. Operation Work per Day. 1 CDS views read from this table.

CDS Views using this table (1)

ViewTypeJoinVDMDescription
P_RSHWCUtilization view union_all CONSUMPTION Operations
@AbapCatalog.sqlViewName: 'PRSHOPWORKPD'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.private: true
@VDM.viewType: #CONSUMPTION
@ClientHandling.algorithm: #SESSION_VARIABLE

/*
CONTRACT**********************************************************************************************************************

Name:                       Operation Work Per Day
Specification:              This View combines operations from various sources:
                            1) operations spanning multiple days (distributed capacitively to per parallel capacity)
                            2) single day operations (total work consumed at that day)
                            3) operations coming from maintenance plan task list (total work is consumed at single day)
Requires:                   NA
Ensures:                    ... that multiday operations are distributed to parallel days
                              -> if there is no parallel capacity, each day gets same amount of hours
                              -> if there is parallel capacity, each parallel shift gets the same capacitive consumption
Owners:                     PRP
Contributors:               AN
Unit Test required Y/N:     Yes
Additional comments         No aggregation happens in that view.

END OF CONTRACT***************************************************************************************************************
*/


define view P_RSHOperationWorkPerDay
  with parameters
    P_StartDate : datum,
    P_EndDate   : datum

  as select from P_RSHOperationCapacityPrWrkDay(P_StartDate : $parameters.P_StartDate, P_EndDate : $parameters.P_EndDate) as CapacityPerDailyShift

    inner join   P_RSHOperationTotalCapacity (P_StartDate : $parameters.P_StartDate, P_EndDate : $parameters.P_EndDate)   as OperationTotalCapacity on  OperationTotalCapacity.CapacityInternalID           = CapacityPerDailyShift.CapacityInternalID
                                                                                                                                                    and OperationTotalCapacity.MaintenanceOrder             = CapacityPerDailyShift.MaintenanceOrder
                                                                                                                                                    and OperationTotalCapacity.MaintenanceOrderOperation    = CapacityPerDailyShift.MaintenanceOrderOperation
                                                                                                                                                    and OperationTotalCapacity.MaintenanceOrderSubOperation = CapacityPerDailyShift.MaintenanceOrderSubOperation


{
  key CapacityPerDailyShift.MaintenanceOrder             as MaintenanceOrder,
  key cast ( ' ' as warpl )                              as MaintenancePlan,
  key CapacityPerDailyShift.MaintenanceOrderOperation    as MaintenanceOrderOperation,
  key CapacityPerDailyShift.MaintenanceOrderSubOperation as MaintenanceOrderSubOperation,
  key CapacityPerDailyShift.CalendarDate                 as CalendarDate,
  key CapacityPerDailyShift.CapacityStartTime            as CapacityStartTime,
  key CapacityPerDailyShift.AvailableCapacityShift       as AvailableCapacityShift,
      CapacityPerDailyShift.CapacityEndTime              as CapacityEndTime,
      CapacityPerDailyShift.OperationControlKey          as OperationControlKey,
      CapacityPerDailyShift.OrderType                    as OrderType,
      CapacityPerDailyShift.MaintenanceActivityType      as MaintenanceActivityType,
      CapacityPerDailyShift.MaintPriority                as MaintPriority,
      CapacityPerDailyShift.MaintPriorityType            as MaintPriorityType,
      CapacityPerDailyShift.MaintPriorityColorCode       as MaintPriorityColorCode,
      CapacityPerDailyShift.ProcessingStatus             as ProcessingStatus,
      CapacityPerDailyShift.WorkCenter,
      CapacityPerDailyShift.WorkCenterTypeCode,
      CapacityPerDailyShift.WorkCenterCategoryCode,
      CapacityPerDailyShift.Plant                        as Plant,
      CapacityPerDailyShift.WorkCenterInternalID,
      CapacityPerDailyShift.CapacityInternalID,
      CapacityPerDailyShift.OperationPlannedWork         as OperationPlannedWork,
      CapacityPerDailyShift.CalCapacityInParallel        as CapacityPerDay,
      OperationTotalCapacity.CapacityInParallel          as TotalCapacity,

      // here we calculate the distribution of the operation work (OperationPlannedWork) across multiple calendar days

      case when OperationTotalCapacity.CapacityInParallel = 0
      /* In case the operation has not found any capacity over the entire duration, the work is divided evenly across all days
         irrespective of working days
         Example:
         The operation spans from Friday, 8pm to Monday, 6am with 20 hours of work.
         The work center is not open on weekends and has normal opening times from 8 am to 6 pm.
         In this case the operation will not have found any capacity on the work center,
         hence the work is distributed as 20 h / 4 days = 5 hours per day */
        then ( CapacityPerDailyShift.OperationPlannedWork / cast( CapacityPerDailyShift.OperationDayCount as abap.fltp ) )
      /* in case capacity was found, the work of the operation is distributed same as to the capacity of each day compared to the total capacity
         Example:
         The operation spans from Monday, 10am to Thursday, 4pm with 20 hours of work.
         The work center has normal opening times from 8 am to 6 pm without break.
         In this case the operation has found 8 hours on Monday, 10 hours each on Tuesday and Wednesday, and 8 hours on Thursday
         Total capacity available is 8 + 10 + 10 + 8 = 36 h
         hence the work is distributed as 20 h * 8 h / 36 h = 4,44 h on Monday and Thursday
         and 20 h * 10 h / 36 h = 5,56 h on Tuesday and Wednesday */
        else ( CapacityPerDailyShift.OperationPlannedWork * CapacityPerDailyShift.CalCapacityInParallel / OperationTotalCapacity.CapacityInParallel )
      end                                                as WorkPerDay,

      CapacityPerDailyShift.OperationPersonResponsible   as OperationPersonResponsible

}

union all

// second part of the calculation gets the single day operations as they consume all their capacity on that day anyway

select from P_RSHOperationWorkDetails(P_StartDate : $parameters.P_StartDate, P_EndDate : $parameters.P_EndDate) as OperationWorkDetails
{
  key OperationWorkDetails.MaintenanceOrder,
  key cast ( ' ' as warpl )                           as MaintenancePlan,
  key OperationWorkDetails.MaintenanceOrderOperation,
  key OperationWorkDetails.MaintenanceOrderSubOperation,
  key OperationWorkDetails.PlannedStartDate           as CalendarDate,
  key cast ( 0 as abap.int4 )                         as CapacityStartTime,
  key cast ( '' as char1 )                            as AvailableCapacityShift,
      cast ( 0 as abap.int4 )                         as CapacityEndTime,
      OperationWorkDetails.OperationControlKey,
      OperationWorkDetails.OrderType,
      OperationWorkDetails.MaintenanceActivityType,
      OperationWorkDetails.MaintPriority,
      OperationWorkDetails.MaintPriorityType,
      OperationWorkDetails.MaintPriorityColorCode,
      OperationWorkDetails.ProcessingStatus,
      OperationWorkDetails.WorkCenter,
      OperationWorkDetails.WorkCenterTypeCode,
      OperationWorkDetails.WorkCenterCategoryCode,
      OperationWorkDetails.Plant,
      OperationWorkDetails.WorkCenterInternalID,
      OperationWorkDetails.CapacityInternalID,

      OperationWorkDetails.OperationPlannedWork,

      // since in case of single day operations, capacity does not matter, but the UNION forces the same data structure across all sources,

      // we have to provide empty fields

      0                                               as CapacityPerDay,
      0                                               as TotalCapacity,

      // the entire operation work is considered on the only day that the operation is planned for


      OperationWorkDetails.OperationPlannedWork       as WorkPerDay,

      OperationWorkDetails.OperationPersonResponsible as OperationPersonResponsible

}

// second part of the calculation applies only to operations spanning just one day

// as it would be a waste of performance to consider work center capacity and come to the same result

where
  OperationWorkDetails.PlannedStartDate = OperationWorkDetails.PlannedEndDate

union all

// third part is to include the operations coming from the maintenance plan

// All the operations from the maintenance plan will be single day operations

select from P_RSHMaintPlanConsumption(P_StartDate : $parameters.P_StartDate, P_EndDate : $parameters.P_EndDate) as MaintenancePlanDetails

{
  key cast (' ' as aufnr )                           as MaintenanceOrder,
  key MaintenancePlanDetails.MaintenancePlan         as MaintenancePlan,
  key MaintenancePlanDetails.Operation               as MaintenanceOrderOperation,
  key MaintenancePlanDetails.SubOperation            as MaintenanceOrderSubOperation,
  key MaintenancePlanDetails.BasicStartDate          as CalendarDate,
  key cast ( 0 as abap.int4 )                        as CapacityStartTime,
  key cast ( '' as char1 )                           as AvailableCapacityShift,
      cast ( 0 as abap.int4 )                        as CapacityEndTime,
      MaintenancePlanDetails.ControlKey              as OperationControlKey,
      MaintenancePlanDetails.OrderType               as OrderType,
      MaintenancePlanDetails.MaintenanceActivityType as MaintenanceActivityType,
      MaintenancePlanDetails.Priority                as MaintPriority,
      MaintenancePlanDetails.PriorityType            as MaintPriorityType,
      MaintenancePlanDetails.MaintPriorityColorCode  as MaintPriorityColorCode,
      cast ( 10 as abap.int1 )                       as ProcessingStatus,
      MaintenancePlanDetails.WorkCenter              as WorkCenter,
      MaintenancePlanDetails.WorkCenterTypeCode      as WorkCenterTypeCode,
      MaintenancePlanDetails.WorkCenterCategoryCode  as WorkCenterCategoryCode,
      MaintenancePlanDetails.Plant                   as Plant,
      MaintenancePlanDetails.WorkCenterInternalID    as WorkCenterInternalId,
      MaintenancePlanDetails.CapacityInternalId      as CapacityInternalID,
      MaintenancePlanDetails.TotalWork               as OperationPlannedWork,
      0                                              as CapacityPerDay,
      0                                              as TotalCapacity,
      MaintenancePlanDetails.TotalWork               as WorkPerDay,

      cast( '00000000' as co_pernr)                  as OperationPersonResponsible

}