P_SchedOperations

DDL: P_SCHEDOPERATIONS SQL: PSCHEDOPERS Type: view COMPOSITE Package: PPH_VDM_CAP_EVAL

Scheduled Operation details

P_SchedOperations is a Composite CDS View that provides data about "Scheduled Operation details" in SAP S/4HANA. It reads from 6 data sources and exposes 110 fields with key fields OrderID, CapacityRequirementItem, CapacityRqmtItemCapacity, OrderCategory, CapacityRequirementItem. It has 1 association to related views. Part of development package PPH_VDM_CAP_EVAL.

Data Sources (6)

SourceAliasJoin Type
I_CapacityRequirementItemCap CapRqmtItmCap from
I_CapacityRequirementItemCap CapRqmtItmCap union_all
P_ProcCapReqOpDurn ProcOpDurn left_outer
P_ProcCapReqOpDurn ProcOpDurn left_outer
P_SchedFirstOperation SchedFrstOp left_outer
P_SchedFirstOperation SchedFrstOp left_outer

Associations (1)

CardinalityTargetAliasCondition
[1..1] P_SchedOrderOperationStatus _OrderStatus CapRqmtItmCap.OrderObjectInternalID = _OrderStatus.StatusObject

Annotations (6)

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

Fields (110)

KeyFieldSource TableSource FieldDescription
KEY OrderID
KEY CapacityRequirementItem I_CapacityRequirementItemCap CapacityRequirementItem
KEY CapacityRqmtItemCapacity I_CapacityRequirementItemCap CapacityRqmtItemCapacity
KEY OrderCategory
Operation
Material
Plant
clientNULLendasPlantCurrentDate
clientNULLendasPlantCurrentTime
AddressTimeZone
MRPArea
MRPController
numc15astimestampendasLastChangeDateTime
CapacityRequirement I_CapacityRequirementItemCap CapacityRequirement
WorkCenterInternalID
WorkCenter
WorkCenterCategoryCode
WorkCenterText
WorkCenterTypeCode
CapacityInternalID I_CapacityRequirementItemCap CapacityInternalID
CapacityCategoryCode
WorkCenterResponsible
CapacityResponsiblePlanner
OrderInternalID I_CapacityRequirementItemCap OrderInternalID
ManufacturingOrder
PlannedOrder
ProductionVersion
ProductionLine
ScheduledBasicStartDate _Order ScheduledBasicStartDate
ScheduledBasicStartTime _Order ScheduledBasicStartTime
ScheduledBasicEndDate _Order ScheduledBasicEndDate
ScheduledBasicEndTime _Order ScheduledBasicEndTime
OperationLatestStartDate I_CapacityRequirementItemCap OperationLatestStartDate
OperationLatestStartTime I_CapacityRequirementItemCap OperationLatestStartTime
OperationLatestEndDate I_CapacityRequirementItemCap OperationLatestEndDate
OperationLatestEndTime I_CapacityRequirementItemCap OperationLatestEndTime
OpLtstSchedldProcgStrtDte I_CapacityRequirementItemCap LtstSchedldProcStrtDte
OpLtstSchedldProcgStrtTme I_CapacityRequirementItemCap LtstSchedldProcStrtTime
OpLtstSchedldTrdwnStrtDte I_CapacityRequirementItemCap LtstSchedldTrdwnStrtDte
OpLtstSchedldTrdwnStrtTme I_CapacityRequirementItemCap LtstSchedldTrdwnStrtTime
RequirementDate
BaseUnit
BOOExplosionDate
BOMExplosionDate
PlndOrderPlannedStartDate
PlndOrderPlannedEndDate
OrderObjectInternalID I_CapacityRequirementItemCap OrderObjectInternalID
OperationIsPhase I_CapacityRequirementItemCap OperationIsPhase
StatusCode _OrderStatus StatusCode
OriginallyScheduledStartDate OperationLatestStartDate
OriginallyScheduledEndDate OperationLatestEndDate
OperationSetupGroup
OperationSetupGroupCategory
BillOfOperationsType
BillOfOperationsGroup
KEY CapacityRequirementItem I_CapacityRequirementItemCap CapacityRequirementItem
KEY CapacityRqmtItemCapacity I_CapacityRequirementItemCap CapacityRqmtItemCapacity
KEY OrderCategory
Operation
Material
Plant
clientNULLendasPlantCurrentDate
clientNULLendasPlantCurrentTime
AddressTimeZone
MRPArea
MRPController
LastChangeDateTime
CapacityRequirement I_CapacityRequirementItemCap CapacityRequirement
WorkCenterInternalID
WorkCenter
WorkCenterCategoryCode
WorkCenterText
WorkCenterTypeCode
CapacityInternalID I_CapacityRequirementItemCap CapacityInternalID
CapacityCategoryCode
WorkCenterResponsible
CapacityResponsiblePlanner
OrderInternalID I_CapacityRequirementItemCap OrderInternalID
ManufacturingOrder
PlannedOrder
ProductionVersion
ProductionLine
ScheduledBasicStartDate _CapacityRequirement ScheduledBasicStartDate
ScheduledBasicStartTime _CapacityRequirement ScheduledBasicStartTime
ScheduledBasicEndDate _CapacityRequirement ScheduledBasicEndDate
ScheduledBasicEndTime _CapacityRequirement ScheduledBasicEndTime
OperationLatestStartDate I_CapacityRequirementItemCap OperationLatestStartDate
OperationLatestStartTime I_CapacityRequirementItemCap OperationLatestStartTime
OperationLatestEndDate I_CapacityRequirementItemCap OperationLatestEndDate
OperationLatestEndTime I_CapacityRequirementItemCap OperationLatestEndTime
OpLtstSchedldProcgStrtDte I_CapacityRequirementItemCap LtstSchedldProcStrtDte
OpLtstSchedldProcgStrtTme I_CapacityRequirementItemCap LtstSchedldProcStrtTime
OpLtstSchedldTrdwnStrtDte I_CapacityRequirementItemCap LtstSchedldTrdwnStrtDte
OpLtstSchedldTrdwnStrtTme I_CapacityRequirementItemCap LtstSchedldTrdwnStrtTime
OrderPlannedTotalQty
BaseUnit
BOOExplosionDate
BOMExplosionDate
PlndOrderPlannedStartDate
PlndOrderPlannedEndDate
OrderObjectInternalID I_CapacityRequirementItemCap OrderObjectInternalID
OperationIsPhase I_CapacityRequirementItemCap OperationIsPhase
StatusCode
OriginallyScheduledStartDate OperationLatestStartDate
OriginallyScheduledEndDate OperationLatestEndDate
OperationSetupGroup
OperationSetupGroupCategory
BillOfOperationsType
BillOfOperationsGroup
OrderHasConfiguration
@AbapCatalog.sqlViewName: 'PSCHEDOPERS'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.private: true
@VDM.viewType: #COMPOSITE
@ClientHandling.algorithm: #SESSION_VARIABLE
define view P_SchedOperations
  as select from    I_CapacityRequirementItemCap as CapRqmtItmCap
    left outer join P_SchedFirstOperation        as SchedFrstOp on  CapRqmtItmCap.CapacityRequirement  = SchedFrstOp.CapacityRequirement
                                                                and CapRqmtItmCap.WorkCenterInternalID = SchedFrstOp.WorkCenterInternalID
                                                                and CapRqmtItmCap.Operation            = SchedFrstOp.Operation
    left outer join P_ProcCapReqOpDurn           as ProcOpDurn  on  CapRqmtItmCap.CapacityRequirement      = ProcOpDurn.CapacityRequirement
                                                                and CapRqmtItmCap.CapacityRequirementItem  = ProcOpDurn.SuperiorOperationInternalID
                                                                and CapRqmtItmCap.CapacityRqmtItemCapacity = ProcOpDurn.CapacityRqmtItemCapacity
                                                                and CapRqmtItmCap.OperationIsPhase         = '1'
  // association [1..1] to I_StatusObjectStatus as _StatusConfirmed on  CapRqmtItmCap.OrderObjectInternalID = _StatusConfirmed.StatusObject

  //                                                                and _StatusConfirmed.StatusCode         = 'I0009'

  //                                                                and _StatusConfirmed.StatusIsActive     = 'X'

  association [1..1] to P_SchedOrderOperationStatus as _OrderStatus on CapRqmtItmCap.OrderObjectInternalID = _OrderStatus.StatusObject

{
  key cast( CapRqmtItmCap.OrderID as pph_cfs_ordernumber )                  as OrderID,
  key CapRqmtItmCap.CapacityRequirementItem                                 as CapacityRequirementItem,
  key CapRqmtItmCap.CapacityRqmtItemCapacity,
  key cast(CapRqmtItmCap._Order.OrderCategory as pph_cfs_sch_ordercategory) as OrderCategory,
      cast( CapRqmtItmCap.Operation as vornr)                               as Operation,

      cast( CapRqmtItmCap._Order.Material as matnr)                         as Material,
      CapRqmtItmCap._WorkCenter.Plant                                       as Plant,
      case 
      when CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone is null
        then
         tstmp_to_dats( tstmp_current_utctimestamp(),
                         abap_system_timezone($session.client, 'NULL'),
                         $session.client,
                         'NULL' )

        else
         tstmp_to_dats( tstmp_current_utctimestamp(),
                         CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,
                         $session.client,
                         'NULL' )
        end                                                                 as PlantCurrentDate,
      case
        when CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone is null
        then
           tstmp_to_tims( tstmp_current_utctimestamp(),
                         abap_system_timezone($session.client, 'NULL'),
                         $session.client,
                         'NULL' )
        else
        tstmp_to_tims( tstmp_current_utctimestamp(),
                         CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,
                         $session.client,
                         'NULL' )

        end                                                                 as PlantCurrentTime,

      CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,

      cast( _Order._OrderMainItem.MRPArea as berid)                         as MRPArea,
      cast( CapRqmtItmCap._Order.MRPController as dispo)                    as MRPController,
      case CapRqmtItmCap._Order.LastChangeDate
        when '00000000'
          then cast(cast( concat( CapRqmtItmCap._Order.CreationDate, CapRqmtItmCap._Order.CreationTime)as abap.numc(15)) as timestamp)
      else cast(cast( concat( CapRqmtItmCap._Order.LastChangeDate, CapRqmtItmCap._Order.LastChangeTime)as abap.numc(15)) as timestamp)
      end                                                                   as LastChangeDateTime,
      CapRqmtItmCap.CapacityRequirement                                     as CapacityRequirement,
      CapRqmtItmCap._WorkCenter.WorkCenterInternalID                        as WorkCenterInternalID,
      CapRqmtItmCap._WorkCenter.WorkCenter                                  as WorkCenter,
      CapRqmtItmCap._WorkCenter.WorkCenterCategoryCode                      as WorkCenterCategoryCode,
      CapRqmtItmCap._WorkCenter._Text[1:Language=$session.system_language].WorkCenterText,
      cast(CapRqmtItmCap.WorkCenterTypeCode as cr_objty)                    as WorkCenterTypeCode,
      CapRqmtItmCap.CapacityInternalID,
      CapRqmtItmCap._Capacity.CapacityCategoryCode,
      CapRqmtItmCap._WorkCenter.WorkCenterResponsible                       as WorkCenterResponsible,
      CapRqmtItmCap._Capacity.CapacityResponsiblePlanner                    as CapacityResponsiblePlanner,
      CapRqmtItmCap.OrderInternalID                                         as OrderInternalID,
      cast(CapRqmtItmCap.OrderID as aufnr)                                  as ManufacturingOrder,
      cast(CapRqmtItmCap.PlannedOrder as plnum)                             as PlannedOrder,
      cast( _Order._OrderMainItem.ProductionVersion as verid)               as ProductionVersion,
      _Order._OrderMainItem._ProductionVersion.ProductionLine               as ProductionLine,
      // Mapping Repetetive manufacturing to Discrete Industry

      cast( case
       when _Order._OrderMainItem._ProductionVersion._BillOfOperationsType.BillOfOperationsApplication = 'R'
       then cast ('P' as plnaw)
       else
       cast (_Order._OrderMainItem._ProductionVersion._BillOfOperationsType.BillOfOperationsApplication as plnaw)
       end as plnaw preserving type )                                       as IndustryType,
      case
        when _OrderOperation.OpDispatchedExecStartDate = '00000000'
          then cast('DALL' as pph_cfs_sch_status)
        else cast('DSPT' as pph_cfs_sch_status)
      end                                                                   as OperationPlanningStatusCode,
      _Order.ScheduledBasicStartDate                                        as ScheduledBasicStartDate,
      _Order.ScheduledBasicStartTime                                        as ScheduledBasicStartTime,
      _Order.ScheduledBasicEndDate                                          as ScheduledBasicEndDate,
      _Order.ScheduledBasicEndTime                                          as ScheduledBasicEndTime,
      CapRqmtItmCap.OperationLatestStartDate                                as OperationLatestStartDate,
      CapRqmtItmCap.OperationLatestStartTime                                as OperationLatestStartTime,
      case
          when CapRqmtItmCap.OperationLatestStartTime >= '240000'
            then cast(cast(concat(dats_add_days(CapRqmtItmCap.OperationLatestStartDate,1,'NULL'),'000000')as abap.numc(15)) as timestamp)
          else
            cast(cast(concat(CapRqmtItmCap.OperationLatestStartDate,CapRqmtItmCap.OperationLatestStartTime)as abap.numc(15)) as timestamp)
        end                                                                 as LtstSchedldExecStrtDteTme,
      CapRqmtItmCap.OperationLatestEndDate                                  as OperationLatestEndDate,
      CapRqmtItmCap.OperationLatestEndTime                                  as OperationLatestEndTime,
      case
          when CapRqmtItmCap.OperationLatestEndTime >= '240000'
            then cast(cast(concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'),'000000')as abap.numc(15)) as timestamp)
          else
            cast(cast(concat(CapRqmtItmCap.OperationLatestEndDate,CapRqmtItmCap.OperationLatestEndTime)as abap.numc(15)) as timestamp)
        end                                                                 as LtstSchedldExecEndDteTme,
      CapRqmtItmCap.LtstSchedldProcStrtDte                                  as OpLtstSchedldProcgStrtDte,
      CapRqmtItmCap.LtstSchedldProcStrtTime                                 as OpLtstSchedldProcgStrtTme,
      CapRqmtItmCap.LtstSchedldTrdwnStrtDte                                 as OpLtstSchedldTrdwnStrtDte,
      CapRqmtItmCap.LtstSchedldTrdwnStrtTime                                as OpLtstSchedldTrdwnStrtTme,
      CapRqmtItmCap._Order.PlannedEndDate                                   as RequirementDate,
      cast ( ( CapRqmtItmCap._Order.OrderPlannedTotalQty
      - CapRqmtItmCap._Order.OrderConfirmedYieldQty )  as mgvrg )           as OrderPlannedTotalQty,
      cast(CapRqmtItmCap._Order.BaseUnit as meins preserving type)          as BaseUnit,
      case
        when CapRqmtItmCap.OperationIsPhase = '1'
          then ProcOpDurn.CapacityRequirementUnit
        else
          CapRqmtItmCap.CapacityRequirementUnit
      end                                                                   as CapacityRequirementUnit,
      case CapRqmtItmCap.RemainingCapReqOpSegSetupDurn
        when 0
          then 0
        else
          cast( unit_conversion(
                QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
                SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
      end                                                                   as RemCapReqOpSegSetupDurnInHours,
      case
        when CapRqmtItmCap.OperationIsPhase = '1'
          then
             case ProcOpDurn.TotRemCapReqOpSegProcgDurn
              when 0
                then 0
              else
                cast( unit_conversion(
                        QUANTITY => ProcOpDurn.TotRemCapReqOpSegProcgDurn,
                        SOURCE_UNIT => ProcOpDurn.CapacityRequirementUnit,
                        TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                        ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
             end
        else
            case CapRqmtItmCap.RemainingCapReqOpSegProcgDurn
              when 0
                then 0
              else
                cast( unit_conversion(
                      QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
                      SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                      TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                      ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
            end
       end                                                                  as RemCapReqOpSegProcgDurnInHours,
      case CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn
        when 0
          then 0
        else
          cast( unit_conversion(
                QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
                SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres )
      end                                                                   as RemCapReqOpSegTrdwnDurnInHours,
      CapRqmtItmCap._Order.BOOExplosionDate                                 as BOOExplosionDate,                                                            //Routing Explosion Date for Manufacturing Orders

      CapRqmtItmCap._Order.BOOExplosionDate                                 as BOMExplosionDate,                                                            //BOM Explosion Date for Manufacturing Orders

      CapRqmtItmCap._PlannedOrder.PlndOrderPlannedStartDate, // Planned Order Start Date

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

      CapRqmtItmCap.OrderObjectInternalID,
      CapRqmtItmCap.OperationIsPhase,
      //_StatusConfirmed.StatusCode,

//      case _OrderStatus.StatusCode

//        when 10 then 'I0001' /*Created*/

//        when 20 then 'I0002' /*Released*/

//        when 30 then 'I0009' /*Confirmed*/

//        when 40 then 'I0010' /*Partially Confirmed*/

//         else ' ' /*Should mainly in case maintainence order*/

//      end                                                                   as StatusCode,

     _OrderStatus.StatusCode as StatusCode,
       
      cast(case
        when SchedFrstOp.Operation is not initial
          then
           'X'
          else
            ' '
        end  as ppsch_is_first_operation_ind )                              as OrderOperationIsFirstInSqnc,

      OperationLatestStartDate                                              as OriginallyScheduledStartDate,
      OperationLatestEndDate                                                as OriginallyScheduledEndDate,

      /*Set up Type Key, Setup Group Category and Set Group Key */
      CapRqmtItmCap._OrderOperation.OperationSetupGroup,
      CapRqmtItmCap._OrderOperation.OperationSetupGroupCategory,
      CapRqmtItmCap._OrderOperation.BillOfOperationsType,
      CapRqmtItmCap._OrderOperation.BillOfOperationsGroup,

      /* AVC configuration */
      case when CapRqmtItmCap._OrderItem.ProductConfiguration is not initial and CapRqmtItmCap._Order.OrderCategory = '10' then
      cast('X' as boole_d preserving type )
      else cast('' as boole_d preserving type )
      end                                                                   as OrderHasConfiguration
}
where
       CapRqmtItmCap._CapacityRequirement.CapacityRequirementOrigin =  '1'
  //and  CapRqmtItmCap.Operation != ''

  and  CapRqmtItmCap.CapacityInternalID                             =  CapRqmtItmCap._WorkCenter.CapacityInternalID
  and  CapRqmtItmCap._WorkCenter.AdvancedPlanningIsSupported        =  ''
  and  CapRqmtItmCap._Capacity.CapacityIsFinite                     =  'X'
  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  _StatusConfirmed.StatusCode                                  is null

  and(
       CapRqmtItmCap.OperationIsPhase                               <> '2'
  )
  
union all select from I_CapacityRequirementItemCap as CapRqmtItmCap
  left outer join     P_SchedFirstOperation        as SchedFrstOp on  CapRqmtItmCap.CapacityRequirement  = SchedFrstOp.CapacityRequirement
                                                                  and CapRqmtItmCap.WorkCenterInternalID = SchedFrstOp.WorkCenterInternalID
                                                                  and CapRqmtItmCap.Operation            = SchedFrstOp.Operation
  left outer join     P_ProcCapReqOpDurn           as ProcOpDurn  on  CapRqmtItmCap.CapacityRequirement      = ProcOpDurn.CapacityRequirement
                                                                  and CapRqmtItmCap.CapacityRequirementItem  = ProcOpDurn.SuperiorOperationInternalID
                                                                  and CapRqmtItmCap.CapacityRqmtItemCapacity = ProcOpDurn.CapacityRqmtItemCapacity
//association [1..1] to I_StatusObjectStatus as _StatusConfirmed on  CapRqmtItmCap.OrderObjectInternalID = _StatusConfirmed.StatusObject

//                                                               and _StatusConfirmed.StatusCode         = 'I0009'

//                                                               and _StatusConfirmed.StatusIsActive     = 'X'

{
  key cast ( CapRqmtItmCap.PlannedOrder as pph_cfs_ordernumber)                           as                                              OrderID,
  key CapRqmtItmCap.CapacityRequirementItem                                               as                                              CapacityRequirementItem,
  key CapRqmtItmCap.CapacityRqmtItemCapacity,
  key cast(CapRqmtItmCap._PlannedOrder.PlannedOrderCategory as pph_cfs_sch_ordercategory) as                                              OrderCategory,
      cast( CapRqmtItmCap.Operation as vornr)                                             as                                              Operation,

      cast ( CapRqmtItmCap._PlannedOrder.Material as matnr )                              as                                              Material,
      CapRqmtItmCap._WorkCenter.Plant                                                     as                                              Plant,
          case 
      when CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone is null
        then
         tstmp_to_dats( tstmp_current_utctimestamp(),
                         abap_system_timezone($session.client, 'NULL'),
                         $session.client,
                         'NULL' )

        else
         tstmp_to_dats( tstmp_current_utctimestamp(),
                         CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,
                         $session.client,
                         'NULL' )
        end                                                                 as PlantCurrentDate,
      case
        when CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone is null
        then
           tstmp_to_tims( tstmp_current_utctimestamp(),
                         abap_system_timezone($session.client, 'NULL'),
                         $session.client,
                         'NULL' )
        else
        tstmp_to_tims( tstmp_current_utctimestamp(),
                         CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,
                         $session.client,
                         'NULL' )

        end                                                                 as PlantCurrentTime,

      CapRqmtItmCap._OrderOperation._WorkCenter._Plant._OrganizationAddress.AddressTimeZone,


      cast ( CapRqmtItmCap._PlannedOrder.MRPArea as berid )                               as                                              MRPArea,
      cast ( CapRqmtItmCap._PlannedOrder.MRPController as dispo )                         as                                              MRPController,
      cast( CapRqmtItmCap._PlannedOrder.LastChangeDateTime as timestamp)                  as                                              LastChangeDateTime,
      CapRqmtItmCap.CapacityRequirement                                                   as                                              CapacityRequirement,
      CapRqmtItmCap._WorkCenter.WorkCenterInternalID                                      as                                              WorkCenterInternalID,
      CapRqmtItmCap._WorkCenter.WorkCenter                                                as                                              WorkCenter,
      CapRqmtItmCap._WorkCenter.WorkCenterCategoryCode                                    as                                              WorkCenterCategoryCode,
      CapRqmtItmCap._WorkCenter._Text[1:Language=$session.system_language].WorkCenterText,
      cast(CapRqmtItmCap.WorkCenterTypeCode as cr_objty)                                  as                                              WorkCenterTypeCode,
      CapRqmtItmCap.CapacityInternalID,
      CapRqmtItmCap._Capacity.CapacityCategoryCode,
      CapRqmtItmCap._WorkCenter.WorkCenterResponsible                                     as                                              WorkCenterResponsible,
      CapRqmtItmCap._Capacity.CapacityResponsiblePlanner                                  as                                              CapacityResponsiblePlanner,
      CapRqmtItmCap.OrderInternalID                                                       as                                              OrderInternalID,
      cast(CapRqmtItmCap.OrderID as aufnr)                                                as                                              ManufacturingOrder,
      cast(CapRqmtItmCap.PlannedOrder as plnum)                                           as                                              PlannedOrder,
      cast ( CapRqmtItmCap._PlannedOrder.ProductionVersion as verid )                     as                                              ProductionVersion,
      CapRqmtItmCap._PlannedOrder._ProductionVersion.ProductionLine                       as                                              ProductionLine,
      // Mapping Repetetive manufacturing to Discrete Industry

      cast( case
       when CapRqmtItmCap._BillOfOperationsType.BillOfOperationsApplication = 'R'
       then cast ('P' as plnaw)
       else
       cast (CapRqmtItmCap._BillOfOperationsType.BillOfOperationsApplication as plnaw)
       end as plnaw preserving type )                                                     as                                              IndustryType,
      case
        when CapRqmtItmCap._OrderStatusObjectStatus.StatusCode = 'I0117' and CapRqmtItmCap._OrderStatusObjectStatus.StatusIsInactive = ''
          then cast('DSPT' as pph_cfs_sch_status)
        else cast('DALL' as pph_cfs_sch_status)
      end                                                                                 as                                              OperationPlanningStatusCode,
      _CapacityRequirement.ScheduledBasicStartDate                                        as                                              ScheduledBasicStartDate,
      _CapacityRequirement.ScheduledBasicStartTime                                        as                                              ScheduledBasicStartTime,
      _CapacityRequirement.ScheduledBasicEndDate                                          as                                              ScheduledBasicEndDate,
      _CapacityRequirement.ScheduledBasicEndTime                                          as                                              ScheduledBasicEndTime,
      CapRqmtItmCap.OperationLatestStartDate                                              as                                              OperationLatestStartDate,
      CapRqmtItmCap.OperationLatestStartTime                                              as                                              OperationLatestStartTime,
      case
          when CapRqmtItmCap.OperationLatestStartTime >= '240000'
            then cast(cast(concat(dats_add_days(CapRqmtItmCap.OperationLatestStartDate,1,'NULL'),'000000')as abap.numc(15)) as timestamp)
          else
            cast(cast(concat(CapRqmtItmCap.OperationLatestStartDate,CapRqmtItmCap.OperationLatestStartTime)as abap.numc(15)) as timestamp)
        end                                                                               as                                              LtstSchedldExecStrtDteTme,
      CapRqmtItmCap.OperationLatestEndDate                                                as                                              OperationLatestEndDate,
      CapRqmtItmCap.OperationLatestEndTime                                                as                                              OperationLatestEndTime,
      case
          when CapRqmtItmCap.OperationLatestEndTime >= '240000'
            then cast(cast(concat(dats_add_days(CapRqmtItmCap.OperationLatestEndDate,1,'NULL'),'000000')as abap.numc(15)) as timestamp)
          else
            cast(cast(concat(CapRqmtItmCap.OperationLatestEndDate,CapRqmtItmCap.OperationLatestEndTime)as abap.numc(15)) as timestamp)
        end                                                                               as                                              LtstSchedldExecEndDteTme,
      CapRqmtItmCap.LtstSchedldProcStrtDte                                                as                                              OpLtstSchedldProcgStrtDte,
      CapRqmtItmCap.LtstSchedldProcStrtTime                                               as                                              OpLtstSchedldProcgStrtTme,
      CapRqmtItmCap.LtstSchedldTrdwnStrtDte                                               as                                              OpLtstSchedldTrdwnStrtDte,
      CapRqmtItmCap.LtstSchedldTrdwnStrtTime                                              as                                              OpLtstSchedldTrdwnStrtTme,
      case CapRqmtItmCap._CapacityRequirement.CapacityRequirementOrigin
         when '1' then CapRqmtItmCap._Order.PlannedEndDate
         when '2' then CapRqmtItmCap._PlannedOrder.PlndOrderPlannedEndDate
      end                                                                                 as                                              RequirementDate,
      cast (  CapRqmtItmCap._PlannedOrder.PlannedTotalQtyInBaseUnit as mgvrg )            as                                              OrderPlannedTotalQty,
      cast(CapRqmtItmCap._PlannedOrder.BaseUnit as meins preserving type)                 as                                              BaseUnit,
      case
        when CapRqmtItmCap.OperationIsPhase = '1'
          then ProcOpDurn.CapacityRequirementUnit
        else
          CapRqmtItmCap.CapacityRequirementUnit
      end                                                                                 as                                              CapacityRequirementUnit,
      case CapRqmtItmCap.RemainingCapReqOpSegSetupDurn
              when 0
                then 0
              else
                cast( unit_conversion(
                      QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegSetupDurn,
                      SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                      TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                      ERROR_HANDLING => 'SET_TO_NULL' ) as cy_krueres )
      end                                                                                 as                                              RemCapReqOpSegSetupDurnInHours,
      case
        when CapRqmtItmCap.OperationIsPhase = '1'
          then case ProcOpDurn.TotRemCapReqOpSegProcgDurn
                  when 0
                    then 0
                  else
                    cast( unit_conversion(
                          QUANTITY => ProcOpDurn.TotRemCapReqOpSegProcgDurn,
                          SOURCE_UNIT => ProcOpDurn.CapacityRequirementUnit,
                          TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                          ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
               end
        else
            case CapRqmtItmCap.RemainingCapReqOpSegProcgDurn
              when 0
                then 0
              else
                cast( unit_conversion(
                      QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegProcgDurn,
                      SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                      TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                      ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kbeares )
            end
       end                                                                                as                                              RemCapReqOpSegProcgDurnInHours,
      case CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn
              when 0
                then 0
              else
                cast( unit_conversion(
                      QUANTITY => CapRqmtItmCap.RemainingCapReqOpSegTrdwnDurn,
                      SOURCE_UNIT => CapRqmtItmCap.CapacityRequirementUnit,
                      TARGET_UNIT => cast( 'H' as abap.unit(3) ),
                      ERROR_HANDLING => 'SET_TO_NULL' ) as cy_kabrres )
      end                                                                                 as                                              RemCapReqOpSegTrdwnDurnInHours,
      CapRqmtItmCap._Order.BOOExplosionDate                                               as                                              BOOExplosionDate, //Routing Explosion Date for Manufacturing Orders

      CapRqmtItmCap._Order.BOOExplosionDate                                               as                                              BOMExplosionDate, //BOM Explosion Date for Manufacturing Orders

      CapRqmtItmCap._PlannedOrder.PlndOrderPlannedStartDate, // Planned Order Start Date

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

      CapRqmtItmCap.OrderObjectInternalID,
      CapRqmtItmCap.OperationIsPhase,
      //_StatusConfirmed.StatusCode,

      'I0001'                                                                             /*showing planning order as Created always*/ as StatusCode,

      cast(case
        when SchedFrstOp.Operation is not initial
          then
           'X'
          else
            ' '
        end  as ppsch_is_first_operation_ind )                                            as                                              OrderOperationIsFirstInSqnc,

      OperationLatestStartDate                                                            as                                              OriginallyScheduledStartDate,
      OperationLatestEndDate                                                              as                                              OriginallyScheduledEndDate,

      /*Set up Type Key, Setup Group Category and Set Group Key */
      CapRqmtItmCap._BOOOperationInternalVersion.OperationSetupGroup,
      CapRqmtItmCap._BOOOperationInternalVersion.OperationSetupGroupCategory,
      CapRqmtItmCap._BOOOperationInternalVersion.BillOfOperationsType,
      CapRqmtItmCap._BOOOperationInternalVersion.BillOfOperationsGroup,

      /* AVC configuration */
      cast('' as boole_d preserving type )                                                as                                              OrderHasConfiguration
}
where
      CapRqmtItmCap._CapacityRequirement.CapacityRequirementOrigin =  '2'
  and CapRqmtItmCap._PlannedOrder.PlannedOrderCategory = '1'
  //and  CapRqmtItmCap.Operation != ''

  and CapRqmtItmCap.CapacityInternalID                             =  CapRqmtItmCap._WorkCenter.CapacityInternalID
  and CapRqmtItmCap._WorkCenter.AdvancedPlanningIsSupported        =  ''
  //and  _StatusConfirmed.StatusCode                                  is null

  and CapRqmtItmCap._Capacity.CapacityIsFinite                     =  'X'
  and(
      CapRqmtItmCap.OperationIsPhase                               <> '2'
  )