P_SchedChgOpLvCacheMapBsc

DDL: P_SCHEDCHGOPLVCACHEMAPBSC Type: view_entity COMPOSITE Package: PPH_VDM_CAP_EVAL

Map changed Operation Detail

P_SchedChgOpLvCacheMapBsc is a Composite CDS View that provides data about "Map changed Operation Detail" in SAP S/4HANA. It reads from 5 data sources (I_CapacityRequirementItemCap, I_CapacityRequirementItemCap, I_LogisticsOrder, I_WorkCenter, I_WorkCenter) and exposes 52 fields with key fields OrderID, CapacityRequirementItem, CapacityRqmtItemCapacity, OrderCategory, CapacityRequirement. Part of development package PPH_VDM_CAP_EVAL.

Data Sources (5)

SourceAliasJoin Type
I_CapacityRequirementItemCap CapRqmtItmCap inner
I_CapacityRequirementItemCap CapRqmtItmCap union_all
I_LogisticsOrder Orders from
I_WorkCenter workcenter inner
I_WorkCenter workcenter inner

Parameters (2)

NameTypeDefault
P_StartDate datum
P_EndDate datum

Annotations (7)

NameValueLevelField
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.private true view
VDM.viewType #COMPOSITE view
Metadata.ignorePropagatedAnnotations true view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.sizeCategory #XL view
ObjectModel.usageType.dataClass #MIXED view

Fields (52)

KeyFieldSource TableSource FieldDescription
KEY OrderID
KEY CapacityRequirementItem I_CapacityRequirementItemCap CapacityRequirementItem
KEY CapacityRqmtItemCapacity I_CapacityRequirementItemCap CapacityRqmtItemCapacity
KEY OrderCategory
KEY CapacityRequirement I_CapacityRequirementItemCap CapacityRequirement
OperationIsPhase I_CapacityRequirementItemCap OperationIsPhase
SuperiorOperationInternalID I_CapacityRequirementItemCap SuperiorOperationInternalID
OrderInternalID
OrderOperationInternalID I_CapacityRequirementItemCap OrderOperationInternalID
OperationasvornrendasOperation
Plant I_WorkCenter Plant
WorkCenterInternalID I_CapacityRequirementItemCap WorkCenterInternalID
WorkCenter I_WorkCenter WorkCenter
CapacityInternalID I_CapacityRequirementItemCap CapacityInternalID
ProductionLineendasProductionLine
ResourceID
ScheduledBasicStartDate I_LogisticsOrder ScheduledBasicStartDate
ScheduledBasicStartTime I_LogisticsOrder ScheduledBasicStartTime
ScheduledBasicEndDate I_LogisticsOrder ScheduledBasicEndDate
ScheduledBasicEndTime I_LogisticsOrder ScheduledBasicEndTime
PlndOrderPlannedStartDate
char17endasLastChangeDateTime
AddressTimeZoneendasPlantTimeZone
OpDispatchedExecStartDate
StatusCode _OrderStatus StatusCode
KEY CapacityRequirementItem I_CapacityRequirementItemCap CapacityRequirementItem
KEY CapacityRqmtItemCapacity I_CapacityRequirementItemCap CapacityRqmtItemCapacity
KEY OrderCategory
KEY CapacityRequirement I_CapacityRequirementItemCap CapacityRequirement
OperationIsPhase I_CapacityRequirementItemCap OperationIsPhase
SuperiorOperationInternalID I_CapacityRequirementItemCap SuperiorOperationInternalID
OrderInternalID
OrderOperationInternalID I_CapacityRequirementItemCap BOOOperationInternalID
Operation
Plant I_WorkCenter Plant
WorkCenterInternalID I_WorkCenter WorkCenterInternalID
workcenter I_WorkCenter WorkCenter
CapacityInternalID I_CapacityRequirementItemCap CapacityInternalID
ProductionLine
ResourceID
LiveCacheOrderID
LiveCacheActivityID
ScheduledBasicStartDate
ScheduledBasicStartTime
ScheduledBasicEndDate
ScheduledBasicEndTime
PlndOrderPlannedStartDate
LastChangeDateTime
AddressTimeZoneendasPlantTimeZone
OpDispatchedExecStartDate
StatusCode
StatusIsInactive
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.private:true
@VDM.viewType: #COMPOSITE
//@EndUserText.label: 'Map changed Operation Detail'

@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
  serviceQuality: #D,
  sizeCategory: #XL,
  dataClass: #MIXED
}
define view entity P_SchedChgOpLvCacheMapBsc  with parameters
    P_StartDate : datum,
    P_EndDate   : datum
  as select from I_LogisticsOrder as Orders
  // instead of selecting data from kbed select it from I_LogisticsOrder so that p_start and p_enddate filter can be passed

  //suboperation are fetched in the view P_SchedChngOpersLiveCacheMap

   inner join I_CapacityRequirementItemCap as CapRqmtItmCap on CapRqmtItmCap.OrderID = Orders.OrderID
  
   inner join I_WorkCenter  as workcenter on  workcenter.WorkCenterTypeCode = CapRqmtItmCap.WorkCenterTypeCode 
                                              and workcenter.WorkCenterInternalID = CapRqmtItmCap.WorkCenterInternalID
                                              and  workcenter.CapacityInternalID = CapRqmtItmCap.CapacityInternalID
    left outer to one join  I_SchedProdnOrderTimeZone    as OrderTimeZone  on  OrderTimeZone.UserID = $session.user
    //association [1..1] to P_SchedOrderOperationStatus as _OrderStatus      on CapRqmtItmCap.OrderObjectInternalID = _OrderStatus.StatusObject

    left outer to one join I_StatusObjectStatusBasic as _OrderStatus on CapRqmtItmCap.OrderObjectInternalID = _OrderStatus.StatusObject
                                            and ( _OrderStatus.StatusCode = 'I0010'
                                             or _OrderStatus.StatusCode = 'I0009') and _OrderStatus.StatusIsInactive = ''
    
{
  key cast(Orders.OrderID as pph_cfs_ordernumber)                                                as    OrderID,
  key CapRqmtItmCap.CapacityRequirementItem,
  key CapRqmtItmCap.CapacityRqmtItemCapacity,
  key cast(Orders.OrderCategory as pph_cfs_sch_ordercategory)                                     as    OrderCategory,
  key CapRqmtItmCap.CapacityRequirement,
      // Mapping Repetetive manufacturing to Discrete Industry

      cast( case
       when Orders._OrderMainItem._ProductionVersion._BillOfOperationsType.BillOfOperationsApplication = 'R'
       then cast ('P' as plnaw)
       else
       cast (Orders._OrderMainItem._ProductionVersion._BillOfOperationsType.BillOfOperationsApplication as plnaw)
       end as plnaw preserving type )                                                             as    IndustryType,
      CapRqmtItmCap.OperationIsPhase,
      CapRqmtItmCap.SuperiorOperationInternalID,
      cast(CapRqmtItmCap.OrderInternalID as abap.char(10))                                        as    OrderInternalID,
      CapRqmtItmCap.OrderOperationInternalID,
      case CapRqmtItmCap.Operation
        when ''
          then cast('1' as vornr)
        else
          cast ( CapRqmtItmCap.Operation as vornr )
          end               as    Operation,
      workcenter.Plant as Plant,
      CapRqmtItmCap.WorkCenterInternalID                                                          as    WorkCenterInternalID,
      workcenter.WorkCenter as  WorkCenter,
      CapRqmtItmCap.CapacityInternalID,
      case
       when Orders.OrderCategory = '30'
         then CapRqmtItmCap._WorkCenter.WorkCenter
       else
       Orders._OrderMainItem._ProductionVersion.ProductionLine
      end                                                                                         as    ProductionLine,
      concat(concat(concat(CapRqmtItmCap.WorkCenterInternalID,'A'),workcenter.Plant), CapRqmtItmCap.CapacityInternalID)      as    ResourceID,
      case Orders.OrderCategory
        when '10'
          then cast(concat(concat(Orders.OrderID, '|'), '2') as /sapapo/om_orderuid )
        when '40'
          then cast(concat(concat(Orders.OrderID, '|'), '3') as /sapapo/om_orderuid )
        when '30'
          then cast(concat(concat(Orders.OrderID, '|'), '4') as /sapapo/om_orderuid )
        else
          cast(concat(Orders.OrderID, '|') as /sapapo/om_orderuid )
      end                                                                                         as    LiveCacheOrderID,
      case Orders.OrderCategory
        when '10'
          then cast(concat(CapRqmtItmCap.CapacityRequirementItem, concat(Orders.OrderID, '2')) as /sapapo/om_orderuid )
        when '40'
          then cast(concat(CapRqmtItmCap.CapacityRequirementItem, concat(Orders.OrderID, '3')) as /sapapo/om_orderuid )
        when '30'
          then cast(concat(CapRqmtItmCap.CapacityRequirementItem,concat(Orders.OrderID, '4')) as /sapapo/om_orderuid )
        else
          cast(Orders.OrderID as /sapapo/om_orderuid )
      end                                                                                         as    LiveCacheActivityID,
      Orders.ScheduledBasicStartDate,
      Orders.ScheduledBasicStartTime,
      case
        when Orders.ScheduledBasicStartTime >= '240000'
          then concat(dats_add_days(Orders.ScheduledBasicStartDate,1,'NULL'), '000000')
        else
          concat(Orders.ScheduledBasicStartDate, CapRqmtItmCap._Order.ScheduledBasicStartTime)
      end                                                                                         as    ScheduledBasicStartTmstmp,
      Orders.ScheduledBasicEndDate,
      Orders.ScheduledBasicEndTime,
      case
        when Orders.ScheduledBasicEndTime >= '240000'
          then concat(dats_add_days(Orders.ScheduledBasicEndDate,1,'NULL'), '000000')
        else
          concat(Orders.ScheduledBasicEndDate, Orders.ScheduledBasicEndTime)
      end                                                                                         as    ScheduledBasicEndTmstmp,
      case
      when CapRqmtItmCap.OperationLatestStartTime >= '240000'
        then concat(dats_add_days(CapRqmtItmCap.OperationLatestStartDate,1,'NULL'), '000000')
      else
        concat(CapRqmtItmCap.OperationLatestStartDate, CapRqmtItmCap.OperationLatestStartTime)
      end                                                                                         as    OperationLatestStartTmstmp,
      case
        when CapRqmtItmCap.OperationLatestEndTime >= '240000'
          then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
        else
          concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
      end                                                                                         as    OperationLatestEndTmstmp,
      case
        when CapRqmtItmCap.RemainingCapReqOpSegSetupDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldProcStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldProcStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldProcStrtDte, CapRqmtItmCap.LtstSchedldProcStrtTime)
            end
        when CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
            end
        else
          case
            when CapRqmtItmCap.OperationLatestEndTime >= '240000'
              then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
            else
              concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
          end
      end                                                                                             as    OpLtstSchedldSetupEndTmstmp,

      case
        when CapRqmtItmCap.LtstSchedldProcStrtTime >= '240000'
          then concat(dats_add_days(CapRqmtItmCap.LtstSchedldProcStrtDte,1,'NULL'), '000000')
        else
          concat(CapRqmtItmCap.LtstSchedldProcStrtDte, CapRqmtItmCap.LtstSchedldProcStrtTime)
      end                                                                                             as    OpLtstSchedldProcgStrtTmstmp,
      case
        when CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
            end
        else
          case
            when CapRqmtItmCap.OperationLatestEndTime >= '240000'
              then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
            else
              concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
          end
      end                                                                                              as    OpLtstSchedldProcgEndTmstmp,
      case
        when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
          then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
        else
          concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
      end                                                                                               as    OpLtstSchedldTrdwnStrtTmstmp,
      case CapRqmtItmCap.RemainingCapReqOpSegSetupDurn
        when 0
          then 0
        else
          cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
      end                                                                                               as    RemCapReqOpSegSetupDurnInSecs,
      case CapRqmtItmCap.RemainingCapReqOpSegProcgDurn
        when 0
          then 0
        else
          cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
      end                                                                                                as    RemCapReqOpSegProcgDurnInSecs,
       case CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn
       when 0
          then 0
        else
          cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres )
      end                                                                                                 as    RemCapReqOpSegTrdwnDurnInSecs,
 
         case
        when ((CapRqmtItmCap._Order.OrderCategory = '30' and CapRqmtItmCap.RemainingCapReqOpSegSetupDurn > 0) or _OrderStatus.StatusCode = 'I0010')
          then cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
      when CapRqmtItmCap._OrderOperation.OpPlannedSetupDurn > 0
        then cast( unit_conversion(
               QUANTITY => CapRqmtItmCap._OrderOperation.OpPlannedSetupDurn,
               SOURCE_UNIT => CapRqmtItmCap._OrderOperation.OpPlannedSetupDurnUnit,
               TARGET_UNIT => cast( 'S' as abap.unit(3) ),
               ERROR_HANDLING => 'SET_TO_NULL' ) as ruest )

//"Only capacity Requirement" scheduling type then refering the KBED capacity since afvv has o durations//               

          when ((CapRqmtItmCap._Order.BasicSchedulingType = '3' and CapRqmtItmCap._Order.OrderCategory = '10' and CapRqmtItmCap._OrderOperation.OpPlannedSetupDurn = 0 ) )     
             then cast( unit_conversion(         
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres ) 
// end of "Only capacity Requirement" scheduling type change         

               
      else
        0
      end    as    SetupDurationInSecs,
    
     case
        when ((CapRqmtItmCap._Order.OrderCategory = '30' and CapRqmtItmCap.RemainingCapReqOpSegProcgDurn > 0) or _OrderStatus.StatusCode = 'I0010')
          then cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
        when CapRqmtItmCap._OrderOperation.OpPlannedProcessingDurn > 0
          then cast( unit_conversion(
              QUANTITY => CapRqmtItmCap._OrderOperation.OpPlannedProcessingDurn,
              SOURCE_UNIT => CapRqmtItmCap._OrderOperation.OpPlannedProcessingDurnUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as bearzeit )
         
//"Only capacity Requirement" scheduling type then refering the KBED capacity since afvv has o durations//               

          when ((CapRqmtItmCap._Order.BasicSchedulingType = '3' and CapRqmtItmCap._Order.OrderCategory = '10' and CapRqmtItmCap._OrderOperation.OpPlannedProcessingDurn = 0 ) )     
             then cast( unit_conversion(         
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres ) 
// end of "Only capacity Requirement" scheduling type change         

              
        else
          0
      end                                                                                           as    ProcgDurationInSecs,
      case
        when ((CapRqmtItmCap._Order.OrderCategory = '30' and CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn > 0) or _OrderStatus.StatusCode = 'I0010')
          then cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
        when CapRqmtItmCap._OrderOperation.OpPlannedTeardownDurn > 0
          then cast( unit_conversion(
              QUANTITY => CapRqmtItmCap._OrderOperation.OpPlannedTeardownDurn,
              SOURCE_UNIT => CapRqmtItmCap._OrderOperation.OpPlannedTeardownDurnUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as abrue )
//"Only capacity Requirement" scheduling type then refering the KBED capacity since afvv has o durations//               

          when ((CapRqmtItmCap._Order.BasicSchedulingType = '3' and CapRqmtItmCap._Order.OrderCategory = '10' and CapRqmtItmCap._OrderOperation.OpPlannedTeardownDurn = 0 ) )     
             then cast( unit_conversion(         
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres ) 
// end of "Only capacity Requirement" scheduling type change               

        else
          0
      end                                                                                              as    TrdwnDurationInSecs,
      case
         when CapRqmtItmCap._OrderOperation.MinimumWaitDuration > 0
           then cast( unit_conversion(
               QUANTITY => CapRqmtItmCap._OrderOperation.MinimumWaitDuration,
               SOURCE_UNIT => CapRqmtItmCap._OrderOperation.MinimumWaitDurationUnit,
               TARGET_UNIT => cast( 'S' as abap.unit(3) ),
               ERROR_HANDLING => 'SET_TO_NULL' ) as cx_liegen )
         else
           0
       end                                                                                              as    WaitDurationInSecs,
      cast('00000000' as psttr)                                                                         as    PlndOrderPlannedStartDate,
      case CapRqmtItmCap._Order.LastChangeDate
        when '00000000'
//          then concat( CapRqmtItmCap._Order.CreationDate, CapRqmtItmCap._Order.CreationTime)

          then cast( dats_tims_to_tstmp( CapRqmtItmCap._Order.CreationDate, CapRqmtItmCap._Order.CreationTime ,OrderTimeZone.TimeZoneID , $session.client, 'NULL' ) as abap.char(17))
//        else concat( CapRqmtItmCap._Order.LastChangeDate, CapRqmtItmCap._Order.LastChangeTime)

        else cast( dats_tims_to_tstmp( CapRqmtItmCap._Order.LastChangeDate, CapRqmtItmCap._Order.LastChangeTime , OrderTimeZone.TimeZoneID, $session.client, 'NULL' )  as abap.char(17))
      end                                                                                                as    LastChangeDateTime,
     case
     when workcenter._Plant._StandardOrganizationAddress.AddressTimeZone  is null or workcenter._Plant._StandardOrganizationAddress.AddressTimeZone  is initial
          then OrderTimeZone.TimeZoneID
     else workcenter._Plant._StandardOrganizationAddress.AddressTimeZone                                end      as    PlantTimeZone,    
     CapRqmtItmCap._OrderOperation.OpDispatchedExecStartDate                                             as    OpDispatchedExecStartDate,
     _OrderStatus.StatusCode                                                                             as    StatusCode ,
     CapRqmtItmCap._OrderStatusObjectStatus.StatusIsInactive                                             as    StatusIsInactive
                                                                                                                                                                                                                                                                                                                                                                                                                             
}
where
       Orders.ScheduledBasicStartDate <= $parameters.P_EndDate
  and  Orders.ScheduledBasicEndDate   >= $parameters.P_StartDate
  and
  (
       CapRqmtItmCap.OperationIsPhase != '1' //do not pick operation headers having phases

  )

  and(
       CapRqmtItmCap.Operation != ''
    or CapRqmtItmCap._Order.OrderCategory           = '30'
  )
  //removing this check cause inner join on I_workcenter is done

//  and  CapRqmtItmCap.CapacityInternalID             = CapRqmtItmCap._WorkCenter.CapacityInternalID

  and(
       CapRqmtItmCap._Order.OrderCategory           = '10' and CapRqmtItmCap._OrderOperation.Sequence = '000000'
    or CapRqmtItmCap._Order.OrderCategory           = '40' and CapRqmtItmCap._OrderOperation.Sequence = '000000'
    or CapRqmtItmCap._Order.OrderCategory           = '30'
  )
  and  CapRqmtItmCap._Capacity.CapacityIsFinite     = 'X'
  /*Prevent loading of confirmed orders to LC*/
  and (_OrderStatus.StatusCode != 'I0009'
  or _OrderStatus.StatusCode is null )
  

union all select from I_CapacityRequirementItemCap as CapRqmtItmCap
//  left outer join     I_CapacityRequirementItemCap as SupCapRqmt on  SupCapRqmt.CapacityRequirement      = CapRqmtItmCap.CapacityRequirement

//                                                                 and SupCapRqmt.CapacityRequirementItem  = CapRqmtItmCap.SuperiorOperationInternalID

//                                                                 and SupCapRqmt.CapacityRqmtItemCapacity = CapRqmtItmCap.CapacityRqmtItemCapacity

 inner join I_WorkCenter  as workcenter on  workcenter.WorkCenterTypeCode = CapRqmtItmCap.WorkCenterTypeCode 
                                              and workcenter.WorkCenterInternalID = CapRqmtItmCap.WorkCenterInternalID
                                              and  workcenter.CapacityInternalID = CapRqmtItmCap.CapacityInternalID
  left outer to one join  I_BillOfOperationsOpBasic    as Routing    on  Routing.BillOfOperationsType    = CapRqmtItmCap.BillOfOperationsType
                                                                 and Routing.BillOfOperationsGroup       = CapRqmtItmCap.BillOfOperationsGroup
                                                                 and Routing.BOOOperationInternalID      = CapRqmtItmCap.BOOOperationInternalID
                                                                 and Routing.BOOOpInternalVersionCounter = CapRqmtItmCap.BOOOpInternalVersionCounter
{
  key cast ( CapRqmtItmCap.PlannedOrder as pph_cfs_ordernumber)                                               as    OrderID,
  key CapRqmtItmCap.CapacityRequirementItem,
  key CapRqmtItmCap.CapacityRqmtItemCapacity,
  key cast(CapRqmtItmCap._PlannedOrder.PlannedOrderCategory as pph_cfs_sch_ordercategory)                     as    OrderCategory,
  key  CapRqmtItmCap.CapacityRequirement,
  
//  Mapping Repetetive manufacturing to Discrete Industry for Planned order

       cast( 
       case when CapRqmtItmCap._BillOfOperationsType.BillOfOperationsApplication  = 'R'
       then'P'
       else
       CapRqmtItmCap._BillOfOperationsType.BillOfOperationsApplication
       end as plnaw preserving type )                                                                          as    IndustryType,
      CapRqmtItmCap.OperationIsPhase,
      CapRqmtItmCap.SuperiorOperationInternalID,
      cast(concat(CapRqmtItmCap.BillOfOperationsGroup,CapRqmtItmCap.BillOfOperations) as abap.char( 10 ))      as    OrderInternalID,
      CapRqmtItmCap.BOOOperationInternalID                                                                     as    OrderOperationInternalID,
      cast( CapRqmtItmCap.Operation as vornr)                                                                  as    Operation,
      workcenter.Plant as Plant,
      workcenter.WorkCenterInternalID as WorkCenterInternalID,
      workcenter.WorkCenter as workcenter,
      CapRqmtItmCap.CapacityInternalID,
      CapRqmtItmCap._PlannedOrder._ProductionVersion.ProductionLine                                             as    ProductionLine,
      concat(concat(concat(CapRqmtItmCap.WorkCenterInternalID,'A'),workcenter.Plant), CapRqmtItmCap.CapacityInternalID)          as    ResourceID,
      cast(concat(concat(CapRqmtItmCap.PlannedOrder, '|'), '1') as /sapapo/om_orderuid )                                         as    LiveCacheOrderID,
      cast(concat(CapRqmtItmCap.CapacityRequirementItem, concat(CapRqmtItmCap.PlannedOrder, '1')) as /sapapo/om_orderuid )       as    LiveCacheActivityID,
      CapRqmtItmCap._CapacityRequirement.ScheduledBasicStartDate,
      CapRqmtItmCap._CapacityRequirement.ScheduledBasicStartTime,
      case
          when CapRqmtItmCap.OperationLatestStartTime >= '240000'
            then concat(dats_add_days(CapRqmtItmCap._CapacityRequirement.ScheduledBasicStartDate,1,'NULL'),'000000')
          else
            concat(CapRqmtItmCap._CapacityRequirement.ScheduledBasicStartDate,CapRqmtItmCap._CapacityRequirement.ScheduledBasicStartTime)
        end                                                                                                     as    ScheduledBasicStartTmstmp,
      CapRqmtItmCap._CapacityRequirement.ScheduledBasicEndDate,
      CapRqmtItmCap._CapacityRequirement.ScheduledBasicEndTime,
      case
          when CapRqmtItmCap.OperationLatestEndTime >= '240000'
            then concat(dats_add_days(CapRqmtItmCap._CapacityRequirement.ScheduledBasicEndDate,1,'NULL'),'000000')
          else
            concat(CapRqmtItmCap._CapacityRequirement.ScheduledBasicEndDate,CapRqmtItmCap._CapacityRequirement.ScheduledBasicEndTime)
        end                                                                                                     as    ScheduledBasicEndTmstmp,

      case
      when CapRqmtItmCap.OperationLatestStartTime >= '240000'
        then concat(dats_add_days(CapRqmtItmCap.OperationLatestStartDate,1,'NULL'), '000000')
      else
        concat(CapRqmtItmCap.OperationLatestStartDate, CapRqmtItmCap.OperationLatestStartTime)
      end                                                                                                       as    OperationLatestStartTmstmp,
      case
         when CapRqmtItmCap.OperationLatestEndTime >= '240000'
           then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
         else
           concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
           end
                                                                                                                as    OperationLatestEndTmstmp,
      case
        when CapRqmtItmCap.RemainingCapReqOpSegSetupDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldProcStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldProcStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldProcStrtDte, CapRqmtItmCap.LtstSchedldProcStrtTime)
            end
        when CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
            end
        else
          case
            when CapRqmtItmCap.OperationLatestEndTime >= '240000'
              then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
            else
              concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
          end
      end                                                                                                         as    OpLtstSchedldSetupEndTmstmp,

      case
        when CapRqmtItmCap.LtstSchedldProcStrtTime >= '240000'
          then concat(dats_add_days(CapRqmtItmCap.LtstSchedldProcStrtDte,1,'NULL'), '000000')
        else
          concat(CapRqmtItmCap.LtstSchedldProcStrtDte, CapRqmtItmCap.LtstSchedldProcStrtTime)
      end                                                                                                         as    OpLtstSchedldProcgStrtTmstmp,
      case
        when CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn > 0
          then
            case
              when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
                then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
              else
                concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
            end
        else
          case
            when CapRqmtItmCap.OperationLatestEndTime >= '240000'
              then concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'), '000000')
            else
              concat(CapRqmtItmCap.OperationLatestEndDate, CapRqmtItmCap.OperationLatestEndTime)
          end
      end                                                                                                           as    OpLtstSchedldProcgEndTmstmp,
      case
        when CapRqmtItmCap.LtstSchedldTrdwnStrtTime >= '240000'
          then concat(dats_add_days(CapRqmtItmCap.LtstSchedldTrdwnStrtDte,1,'NULL'), '000000')
        else
          concat(CapRqmtItmCap.LtstSchedldTrdwnStrtDte, CapRqmtItmCap.LtstSchedldTrdwnStrtTime)
      end                                                                                                           as    OpLtstSchedldTrdwnStrtTmstmp,
      case CapRqmtItmCap.RemainingCapReqOpSegSetupDurn 
        when 0
          then 0
        else
          cast( unit_conversion(
                QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
                SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                TARGET_UNIT => cast( 'S' as abap.unit(3) ),
                ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
      end                                                                                     as    RemCapReqOpSegSetupDurnInSecs,
      case CapRqmtItmCap.RemainingCapReqOpSegProcgDurn
        when 0
          then 0
        else
          cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
      end                                                                                     as    RemCapReqOpSegProcgDurnInSecs,
      case CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn
        when 0
          then 0
        else
          cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres )
      end                                                                                      as    RemCapReqOpSegTrdwnDurnInSecs,
        
      case CapRqmtItmCap.RemainingCapReqOpSegSetupDurn
        when 0
          then 0
        else
          cast( unit_conversion(
                   QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
                   SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                   TARGET_UNIT => cast( 'S' as abap.unit(3) ),
                   ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
       end                                                                                      as    SetupDurationInSecs,
      case CapRqmtItmCap.RemainingCapReqOpSegProcgDurn
       when 0
         then 0
       else
         cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
      end                                                                                        as    ProcgDurationInSecs,
      case CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn
       when 0
         then 0
       else
         cast( unit_conversion(
              QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
              SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres )
      end                                                                                        as    TrdwnDurationInSecs,
      case
        when Routing.MinimumWaitDuration > 0
          then cast( unit_conversion(
              QUANTITY => Routing.MinimumWaitDuration,
              SOURCE_UNIT => Routing.MinimumWaitDurationUnit,
              TARGET_UNIT => cast( 'S' as abap.unit(3) ),
              ERROR_HANDLING => 'SET_TO_NULL' ) as cx_liegen )
        else
          0
      end                                                                                          as    WaitDurationInSecs,
      CapRqmtItmCap._PlannedOrder.PlndOrderPlannedStartDate, // Planned Order Start Date

      //CapRqmtItmCap._PlannedOrder.PlndOrderPlannedEndDate, //Planned Order end date

      cast(CapRqmtItmCap._PlannedOrder.LastChangeDateTime as abap.char( 17 ))                      as    LastChangeDateTime,
     case
      when workcenter._Plant._StandardOrganizationAddress.AddressTimeZone  is null or workcenter._Plant._StandardOrganizationAddress.AddressTimeZone  is initial
          then abap_system_timezone($session.client, 'NULL') 
     else  workcenter._Plant._StandardOrganizationAddress.AddressTimeZone                           end    as    PlantTimeZone,
       CapRqmtItmCap._OrderOperation.OpDispatchedExecStartDate                                     as    OpDispatchedExecStartDate,
     CapRqmtItmCap._OrderStatusObjectStatus.StatusCode                                             as    StatusCode,
     CapRqmtItmCap._OrderStatusObjectStatus.StatusIsInactive                                       as    StatusIsInactive
   
}
where
       CapRqmtItmCap._CapacityRequirement.CapacityRequirementOrigin = '2'
  and(
       CapRqmtItmCap.OperationIsPhase                               = '0'
    or CapRqmtItmCap.OperationIsPhase                               = '2'
  )
  and  CapRqmtItmCap.Operation != ''
 // and  CapRqmtItmCap.CapacityInternalID                             = CapRqmtItmCap._WorkCenter.CapacityInternalID

  and  CapRqmtItmCap._Capacity.CapacityIsFinite                     = 'X'
  and  CapRqmtItmCap.OperationLatestStartDate                       <= $parameters.P_EndDate
  and  CapRqmtItmCap.OperationLatestEndDate                         >= $parameters.P_StartDate