P_MfgExecEventHistOperation

DDL: P_MFGEXECEVENTHISTOPERATION SQL: PMPEEXECHISTOP Type: view COMPOSITE Package: MPE_EXEC_COMMON

Operation Execution Event History

P_MfgExecEventHistOperation is a Composite CDS View that provides data about "Operation Execution Event History" in SAP S/4HANA. It reads from 8 data sources and exposes 199 fields with key fields MfgExecDocumentCategory, ManufacturingExecutionDocument, MfgExecutionDocumentItem, MfgProcgExecAction, ManufacturingExecutionDocument. Part of development package MPE_EXEC_COMMON.

Data Sources (8)

SourceAliasJoin Type
I_ProductionHoldAction act inner
P_MfgExecEventHistOpActy2 h inner
I_LogisticsOrderBasic LogisticsOrderBasic inner
I_LogisticsOrderBasic LogisticsOrderBasic inner
I_OpActyInstceOpActyNtwkElmnt oai inner
I_OrderOperationBasic oper from
I_OrderOperationBasic oper inner
I_OrderOperationBasic oper inner

Annotations (9)

NameValueLevelField
AbapCatalog.sqlViewName PMPEEXECHISTOP view
AccessControl.authorizationCheck #NOT_REQUIRED view
ClientHandling.algorithm #SESSION_VARIABLE view
ObjectModel.usageType.serviceQuality #C view
ObjectModel.usageType.sizeCategory #XL view
ObjectModel.usageType.dataClass #TRANSACTIONAL view
VDM.viewType #COMPOSITE view
VDM.private true view
AbapCatalog.compiler.compareFilter true view

Fields (199)

KeyFieldSource TableSource FieldDescription
KEY MfgExecDocumentCategory P_MfgExecEventHistOpActy2 MfgExecDocumentCategory
KEY ManufacturingExecutionDocument P_MfgExecEventHistOpActy2 ManufacturingExecutionDocument
KEY MfgExecutionDocumentItem P_MfgExecEventHistOpActy2 MfgExecutionDocumentItem
KEY MfgProcgExecAction P_MfgExecEventHistOpActy2 MfgProcgExecAction
ManufacturingOrder I_OpActyInstceOpActyNtwkElmnt ManufacturingOrder
MfgBuyOffAction P_MfgExecEventHistOpActy2 MfgBuyOffAction
MfgObjectLogEventType P_MfgExecEventHistOpActy2 MfgObjectLogEventType
EventDateTime P_MfgExecEventHistOpActy2 EventDateTime
ShopFloorExecutionUser P_MfgExecEventHistOpActy2 ShopFloorExecutionUser
CreatedByUser P_MfgExecEventHistOpActy2 CreatedByUser
CreationDateTime P_MfgExecEventHistOpActy2 CreationDateTime
SortField P_MfgExecEventHistOpActy2 SortField
OrderInternalID I_OrderOperationBasic OrderInternalID
OrderOperationInternalID I_OrderOperationBasic OrderOperationInternalID
ManufacturingOrderSequence
ManufacturingOrderOperation
MfgOrderOperationText
WorkCenterInternalID
WorkCenterTypeCode I_OrderOperationBasic WorkCenterTypeCode
ShopFloorItem P_MfgExecEventHistOpActy2 ShopFloorItem
OperationActivitySFIGroup P_MfgExecEventHistOpActy2 OperationActivitySFIGroup
OpActyNtwkInstance P_MfgExecEventHistOpActy2 OpActyNtwkInstance
OpActyNtwkElement P_MfgExecEventHistOpActy2 OpActyNtwkElement
OperationActivityName
OpActyNtwkSegmentType I_OpActyInstceOpActyNtwkElmnt OpActyNtwkSegmentType
OperationActivityNetwork I_OpActyInstceOpActyNtwkElmnt OperationActivityNetwork
OpActyNtwkVersionCounter I_OpActyInstceOpActyNtwkElmnt OpActyNtwkVersionCounter
OpActyNtwkElementExternalID I_OpActyInstceOpActyNtwkElmnt OpActyNtwkElementExternalID
OperationActivity I_OpActyInstceOpActyNtwkElmnt OperationActivity
OperationActyVersionCounter I_OpActyInstceOpActyNtwkElmnt OperationActyVersionCounter
DefectInternalID P_MfgExecEventHistOpActy2 DefectInternalID
Notification P_MfgExecEventHistOpActy2 Notification
NotificationItem P_MfgExecEventHistOpActy2 NotificationItem
MaterialComponent P_MfgExecEventHistOpActy2 MaterialComponent
MaterialComponentName P_MfgExecEventHistOpActy2 MaterialComponentName
AssembledShopFloorItem P_MfgExecEventHistOpActy2 AssembledShopFloorItem
AssembledSerialNumber P_MfgExecEventHistOpActy2 AssembledSerialNumber
AssembledMfrSerialNumber P_MfgExecEventHistOpActy2 AssembledMfrSerialNumber
AssembledBatch P_MfgExecEventHistOpActy2 AssembledBatch
ReferenceDesignatorValue P_MfgExecEventHistOpActy2 ReferenceDesignatorValue
StorageLocation P_MfgExecEventHistOpActy2 StorageLocation
InventoryUsabilityCode P_MfgExecEventHistOpActy2 InventoryUsabilityCode
CompDisassemblyPermanence P_MfgExecEventHistOpActy2 CompDisassemblyPermanence
MaterialComponentHasReltdComp P_MfgExecEventHistOpActy2 MaterialComponentHasReltdComp
MfgBuyOffInternalID P_MfgExecEventHistOpActy2 MfgBuyOffInternalID
MfgBuyOffDescription P_MfgExecEventHistOpActy2 MfgBuyoffDescription
MfgBuyOffReferencedStep P_MfgExecEventHistOpActy2 MfgBuyOffReferencedStep
MfgBuyOffAdhocStepDescription P_MfgExecEventHistOpActy2 MfgBuyOffAdhocStepDescription
MfgBuyOffCycle P_MfgExecEventHistOpActy2 MfgBuyOffCycle
RespyMgmtTeamID P_MfgExecEventHistOpActy2 RespyMgmtTeamID
RespyMgmtFunction P_MfgExecEventHistOpActy2 RespyMgmtFunction
BusinessProcessConfirmedQty P_MfgExecEventHistOpActy2 BusinessProcessConfirmedQty
ProductionUnit P_MfgExecEventHistOpActy2 ProductionUnit
OpActyActualDurnInSeconds P_MfgExecEventHistOpActy2 OpActyActualDurnInSeconds
PostingIsRetroactive P_MfgExecEventHistOpActy2 PostingIsRetroactive
MfgActionReasonCodeGroupCtlg P_MfgExecEventHistOpActy2 MfgActionReasonCodeGroupCtlg
MfgActionReasonCodeGroup P_MfgExecEventHistOpActy2 MfgActionReasonCodeGroup
ManufacturingActionReasonCode P_MfgExecEventHistOpActy2 ManufacturingActionReasonCode
MfgExecutionDocumentNote P_MfgExecEventHistOpActy2 MfgExecutionDocumentNote
Equipment P_MfgExecEventHistOpActy2 Equipment
SystemMessageNumber P_MfgExecEventHistOpActy2 SystemMessageNumber
SystemMessageIdentification P_MfgExecEventHistOpActy2 SystemMessageIdentification
MfgExecHistMsgVarblField1 P_MfgExecEventHistOpActy2 MfgExecHistMsgVarblField1
MfgExecHistMsgVarblField2 P_MfgExecEventHistOpActy2 MfgExecHistMsgVarblField2
MfgExecHistMsgVarblField3 P_MfgExecEventHistOpActy2 MfgExecHistMsgVarblField3
MfgExecHistMsgVarblField4 P_MfgExecEventHistOpActy2 MfgExecHistMsgVarblField4
Defect P_MfgExecEventHistOpActy2 Defect
KEY ManufacturingExecutionDocument I_ProductionHoldAction ProductionHold
KEY MfgExecutionDocumentItem I_ProductionHoldAction ProductionHoldItem
KEY MfgProcgExecAction I_ProductionHoldAction MfgProcgExecAction
ManufacturingOrder I_LogisticsOrderBasic OrderID
MfgBuyOffAction
MfgObjectLogEventType
ShopFloorExecutionUser
CreatedByUser
CreationDateTime
SortField
OrderInternalID hold OrderInternalID
OrderOperationInternalID hold OrderOperationInternalID
ManufacturingOrderSequence
ManufacturingOrderOperation
MfgOrderOperationText
WorkCenterInternalID
WorkCenterTypeCode I_OrderOperationBasic WorkCenterTypeCode
ShopFloorItem hold ShopFloorItem
OperationActivitySFIGroup hold OperationActivitySFIGroup
OpActyNtwkInstance hold OpActyNtwkInstance
OpActyNtwkElement hold OpActyNtwkElement
OperationActivityName
OpActyNtwkSegmentType
OperationActivityNetwork
OpActyNtwkVersionCounter
OpActyNtwkElementExternalID
OperationActivity
OperationActyVersionCounter
StatusAndActionSchema
DefectInternalID hold DefectInternalID
Notification hold Notification
NotificationItem hold NotificationItem
MaterialComponent
MaterialComponentName
AssembledShopFloorItem
AssembledSerialNumber
AssembledMfrSerialNumber
AssembledBatch
ReferenceDesignatorValue
StorageLocation
InventoryUsabilityCode
CompDisassemblyPermanence
MaterialComponentHasReltdComp
MfgBuyOffInternalID
MfgBuyOffDescription
MfgBuyOffReferencedStep
MfgBuyOffAdhocStepDescription
MfgBuyOffCycle
RespyMgmtTeamID
RespyMgmtFunction
BusinessProcessConfirmedQty
ProductionUnit
OpActyActualDurnInSeconds
PostingIsRetroactive
MfgActionReasonCodeGroupCtlg I_ProductionHoldAction MfgActionReasonCodeGroupCtlg
MfgActionReasonCodeGroup I_ProductionHoldAction MfgActionReasonCodeGroup
ManufacturingActionReasonCode I_ProductionHoldAction ManufacturingActionReasonCode
MfgExecutionDocumentNote note MfgExecutionDocumentNote
Equipment
SystemMessageIdentification
MfgExecHistMsgVarblField1 20
MfgExecHistMsgVarblField2 18
MfgExecHistMsgVarblField4 0
Defect
KEY ManufacturingExecutionDocument sfirwrk ShopFloorItem
KEY MfgExecutionDocumentItem
KEY MfgProcgExecAction
ManufacturingOrder I_LogisticsOrderBasic OrderID
MfgBuyOffAction
MfgObjectLogEventType
EventDateTime
ShopFloorExecutionUser
CreatedByUser
CreationDateTime
SortField
OrderInternalID I_OrderOperationBasic OrderInternalID
OrderOperationInternalID I_OrderOperationBasic OrderOperationInternalID
ManufacturingOrderSequence
ManufacturingOrderOperation
MfgOrderOperationText
WorkCenterInternalID
WorkCenterTypeCode I_OrderOperationBasic WorkCenterTypeCode
ShopFloorItem sfirwrk ShopFloorItem
OperationActivitySFIGroup
OpActyNtwkInstance
OpActyNtwkElement
OperationActivityName
OpActyNtwkSegmentType
OperationActivityNetwork
OpActyNtwkVersionCounter
OpActyNtwkElementExternalID
OperationActivity
OperationActyVersionCounter
StatusAndActionSchema
DefectInternalID
Notification
NotificationItem
MaterialComponent
MaterialComponentName
AssembledShopFloorItem
AssembledSerialNumber
AssembledMfrSerialNumber
AssembledBatch
ReferenceDesignatorValue
StorageLocation
InventoryUsabilityCode
CompDisassemblyPermanence
MaterialComponentHasReltdComp
MfgBuyOffInternalID
MfgBuyOffDescription
MfgBuyOffReferencedStep
MfgBuyOffAdhocStepDescription
MfgBuyOffCycle
RespyMgmtTeamID
RespyMgmtFunction
BusinessProcessConfirmedQty
ProductionUnit
OpActyActualDurnInSeconds
PostingIsRetroactive
MfgActionReasonCodeGroupCtlg
MfgActionReasonCodeGroup
ManufacturingActionReasonCode
MfgExecutionDocumentNote
Equipment
SystemMessageNumber
SystemMessageIdentification
MfgExecHistMsgVarblField1 7
MfgExecHistMsgVarblField2 18
MfgExecHistMsgVarblField3 0
MfgExecHistMsgVarblField4 0
Defect
MfgProcgExecAttachmentName
@AbapCatalog.sqlViewName: 'PMPEEXECHISTOP'
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.algorithm: #SESSION_VARIABLE
@ObjectModel.usageType: {serviceQuality: #C, sizeCategory: #XL, dataClass: #TRANSACTIONAL}
@VDM.viewType: #COMPOSITE
@VDM.private: true
@AbapCatalog.compiler.compareFilter: true
define view P_MfgExecEventHistOperation
  as
  -- OA History enhanced with operation information
  select from  I_OrderOperationBasic         as oper
    inner join I_OpActyInstceOpActyNtwkElmnt as oai on  oai.OrderInternalID          = oper.OrderInternalID
                                                    and oai.OrderOperationInternalID = oper.OrderOperationInternalID
    inner join P_MfgExecEventHistOpActy2     as h   on  h.OpActyNtwkInstance = oai.OpActyNtwkInstance
                                                    and h.OpActyNtwkElement  = oai.OpActyNtwkElement
  //association [0..1] to I_OpActyBuyOffText as _OpActyBuyOffText on  $projection.OperationActivity           = _OpActyBuyOffText.OperationActivity

  //and $projection.OperationActyVersionCounter = _OpActyBuyOffText.OperationActyVersionCounter

  //and $projection.MfgBuyOffInternalID         = _OpActyBuyOffText.MfgBuyOffInternalID

  //and _OpActyBuyOffText.Language              = $session.system_language

{
  key h.MfgExecDocumentCategory                                                              as MfgExecDocumentCategory,
  key h.ManufacturingExecutionDocument                                                       as ManufacturingExecutionDocument,
  key h.MfgExecutionDocumentItem                                                             as MfgExecutionDocumentItem,
  key h.MfgProcgExecAction                                                                   as MfgProcgExecAction,
      oai.ManufacturingOrder                                                                 as ManufacturingOrder,
      h.MfgBuyOffAction                                                                      as MfgBuyOffAction,
      h.MfgObjectLogEventType                                                                as MfgObjectLogEventType,
      h.EventDateTime                                                                        as EventDateTime,
      h.ShopFloorExecutionUser                                                               as ShopFloorExecutionUser,
      h.CreatedByUser                                                                        as CreatedByUser,
      h.CreationDateTime                                                                     as CreationDateTime,
      h.SortField                                                                            as SortField,
      oper.OrderInternalID                                                                   as OrderInternalID,
      oper.OrderOperationInternalID                                                          as OrderOperationInternalID,
      cast(oper.Sequence as manufacturingordersequence preserving type)                      as ManufacturingOrderSequence,
      cast(oper.Operation as manufacturingorderoperation preserving type)                    as ManufacturingOrderOperation,
      cast(oper.OperationText as mfgorderoperationtext preserving type)                      as MfgOrderOperationText,
      cast(oper.WorkCenterInternalID as pph_arbid preserving type)                           as WorkCenterInternalID,
      oper.WorkCenterTypeCode                                                                as WorkCenterTypeCode,
      cast( case oper.WorkCenterInternalID
        when '00000000' then ''
        else oper.Plant
      end as mpe_wrk_ctr_plant preserving type )                                             as WorkCenterPlant,
      h.ShopFloorItem                                                                        as ShopFloorItem,
      h.OperationActivitySFIGroup                                                            as OperationActivitySFIGroup,
      h.OpActyNtwkInstance                                                                   as OpActyNtwkInstance,
      h.OpActyNtwkElement                                                                    as OpActyNtwkElement,
      oai._OperationActivityText[1: Language=$session.system_language].OperationActivityName as OperationActivityName,
      oai.OpActyNtwkSegmentType                                                              as OpActyNtwkSegmentType,
      oai.OperationActivityNetwork                                                           as OperationActivityNetwork,
      oai.OpActyNtwkVersionCounter                                                           as OpActyNtwkVersionCounter,
      oai.OpActyNtwkElementExternalID                                                        as OpActyNtwkElementExternalID,
      oai.OperationActivity                                                                  as OperationActivity,
      oai.OperationActyVersionCounter                                                        as OperationActyVersionCounter,
      cast(case
        when h.MfgExecDocumentCategory = 1 and h.ActionIsSASAction = 'X' then oai.StatusAndActionSchema
        else h.StatusAndActionSchema
        end as mpe_sasname_type preserving type)                                             as StatusAndActionSchema,
      h.DefectInternalID                                                                     as DefectInternalID,
      h.Notification                                                                         as Notification,
      h.NotificationItem                                                                     as NotificationItem,
      h.MaterialComponent                                                                    as MaterialComponent,
      h.MaterialComponentName                                                                as MaterialComponentName,
      h.AssembledShopFloorItem                                                               as AssembledShopFloorItem,
      h.AssembledSerialNumber                                                                as AssembledSerialNumber,
      h.AssembledMfrSerialNumber                                                             as AssembledMfrSerialNumber,
      h.AssembledBatch                                                                       as AssembledBatch,
      h.ReferenceDesignatorValue                                                             as ReferenceDesignatorValue,
      h.StorageLocation                                                                      as StorageLocation,
      h.InventoryUsabilityCode                                                               as InventoryUsabilityCode,
      h.CompDisassemblyPermanence                                                            as CompDisassemblyPermanence,
      h.MaterialComponentHasReltdComp                                                        as MaterialComponentHasReltdComp,
      h.MfgBuyOffInternalID                                                                  as MfgBuyOffInternalID,
      h.MfgBuyoffDescription                                                                 as MfgBuyOffDescription,
      h.MfgBuyOffReferencedStep                                                              as MfgBuyOffReferencedStep,
      h.MfgBuyOffAdhocStepDescription                                                        as MfgBuyOffAdhocStepDescription,
      h.MfgBuyOffCycle                                                                       as MfgBuyOffCycle,
      h.RespyMgmtTeamID                                                                      as RespyMgmtTeamID,
      h.RespyMgmtFunction                                                                    as RespyMgmtFunction,
      h.BusinessProcessConfirmedQty                                                          as BusinessProcessConfirmedQty,
      h.ProductionUnit                                                                       as ProductionUnit,
      h.OpActyActualDurnInSeconds                                                            as OpActyActualDurnInSeconds,
      h.PostingIsRetroactive                                                                 as PostingIsRetroactive,
      h.MfgActionReasonCodeGroupCtlg                                                         as MfgActionReasonCodeGroupCtlg,
      h.MfgActionReasonCodeGroup                                                             as MfgActionReasonCodeGroup,
      h.ManufacturingActionReasonCode                                                        as ManufacturingActionReasonCode,
      h.MfgExecutionDocumentNote                                                             as MfgExecutionDocumentNote,
      h.Equipment                                                                            as Equipment,
      h.SystemMessageNumber                                                                  as SystemMessageNumber,
      h.SystemMessageIdentification                                                          as SystemMessageIdentification,
      h.MfgExecHistMsgVarblField1                                                            as MfgExecHistMsgVarblField1,
      h.MfgExecHistMsgVarblField2                                                            as MfgExecHistMsgVarblField2,
      h.MfgExecHistMsgVarblField3                                                            as MfgExecHistMsgVarblField3,
      h.MfgExecHistMsgVarblField4                                                            as MfgExecHistMsgVarblField4,
      h.Defect,
      h.MfgProcgExecAttachmentName                                                           as MfgProcgExecAttachmentName
}

union all
-- Operation Holds
select from              I_ProductionHoldBasic  as hold
  inner join             I_LogisticsOrderBasic  as LogisticsOrderBasic on LogisticsOrderBasic.OrderInternalID = hold.OrderInternalID
  inner join             I_OrderOperationBasic  as oper                on  oper.OrderInternalID          = hold.OrderInternalID
                                                                       and oper.OrderOperationInternalID = hold.OrderOperationInternalID
  inner join             I_ProductionHoldAction as act                 on act.ProductionHold = hold.ProductionHold
  left outer to one join I_MfgExecDocumentNote  as note                on  note.MfgExecDocumentCategory = 5
                                                                       and act.ProductionHold           = note.ManufacturingExecutionDocument
                                                                       and act.ProductionHoldItem       = note.MfgExecutionDocumentItem

{
  key cast (5 as mpe_exec_doc_category preserving type)                   as MfgExecDocumentCategory,
  key act.ProductionHold                                                  as ManufacturingExecutionDocument,
  key act.ProductionHoldItem                                              as MfgExecutionDocumentItem,
  key act.MfgProcgExecAction                                              as MfgProcgExecAction,
      LogisticsOrderBasic.OrderID                                         as ManufacturingOrder,
      cast('  ' as mpe_buyoff_action preserving type)                     as MfgBuyOffAction,
      cast(0 as mpe_log_event)                                            as MfgObjectLogEventType,
      @Semantics.businessDate.at: true
      cast( case act.ProductionHoldItem
        when 1 then ProductionHoldStartDateTime
        else ProductionHoldEndDateTime
      end as mpe_perform_timestamp preserving type)                       as EventDateTime,
      cast(act.CreatedByUser as mpe_performed_by_user preserving type)    as ShopFloorExecutionUser,
      @Semantics.user.createdBy: true
      cast(act.CreatedByUser as mpe_create_user preserving type)          as CreatedByUser,
      @Semantics.systemDateTime.createdAt: true
      cast(act.CreationDateTime as mpe_create_timestampl preserving type) as CreationDateTime,
      cast(700 as rszsort)                                                as SortField,
      hold.OrderInternalID                                                as OrderInternalID,
      hold.OrderOperationInternalID                                       as OrderOperationInternalID,
      cast(oper.Sequence as manufacturingordersequence preserving type)   as ManufacturingOrderSequence,
      cast(oper.Operation as manufacturingorderoperation preserving type) as ManufacturingOrderOperation,
      cast(oper.OperationText as mfgorderoperationtext preserving type)   as MfgOrderOperationText,
      cast(oper.WorkCenterInternalID as pph_arbid preserving type)        as WorkCenterInternalID,
      oper.WorkCenterTypeCode                                             as WorkCenterTypeCode,
      cast( case oper.WorkCenterInternalID
        when '00000000' then ''
        else oper.Plant
      end as mpe_wrk_ctr_plant preserving type )                          as WorkCenterPlant,
      hold.ShopFloorItem                                                  as ShopFloorItem,
      hold.OperationActivitySFIGroup                                      as OperationActivitySFIGroup,
      hold.OpActyNtwkInstance                                             as OpActyNtwkInstance,
      hold.OpActyNtwkElement                                              as OpActyNtwkElement,
      cast('' as mpe_oa_description)                                      as OperationActivityName,
      cast('0' as mpe_oan_segment_type preserving type)                   as OpActyNtwkSegmentType,
      cast(0 as mpe_oan_id)                                               as OperationActivityNetwork,
      cast(0 as mpe_oan_version_no)                                       as OpActyNtwkVersionCounter,
      cast('' as mpe_oan_element_number_ext)                              as OpActyNtwkElementExternalID,
      cast(0 as mpe_oa_id)                                                as OperationActivity,
      cast(0 as  mpe_oa_version_no)                                       as OperationActyVersionCounter,
      cast('' as mpe_sasname_type)                                        as StatusAndActionSchema,
      hold.DefectInternalID                                               as DefectInternalID,
      hold.Notification                                                   as Notification,
      hold.NotificationItem                                               as NotificationItem,
      cast('' as mpe_component_matnr)                                     as MaterialComponent,
      cast('' as maktx)                                                   as MaterialComponentName,
      cast(0 as mpe_assembled_sfi_id)                                     as AssembledShopFloorItem,
      cast('' as mpe_assembled_sernr)                                     as AssembledSerialNumber,
      cast('' as mpe_assembled_mfr_sernr)                                 as AssembledMfrSerialNumber,
      cast('' as mpe_assembled_batch)                                     as AssembledBatch,
      cast('' as vmp_ref_des)                                             as ReferenceDesignatorValue,
      cast('    ' as lgort_d preserving type)                             as StorageLocation,
      cast('' as inventoryusabilitycode preserving type)                  as InventoryUsabilityCode,
      cast('' as mpe_disassembly_permanence preserving type )             as CompDisassemblyPermanence,
      cast('' as mpe_is_reassembly preserving type )                      as MaterialComponentHasReltdComp,
      cast(0 as mpe_buyoff_step)                                          as MfgBuyOffInternalID,
      cast('' as mpe_buyoffsqnc_desc)                                     as MfgBuyOffDescription,
      cast(0 as mpe_buyoff_step)                                          as MfgBuyOffReferencedStep,
      cast('' as mpe_buyoffsqnc_desc)                                     as MfgBuyOffAdhocStepDescription,
      cast('000000000000000' as mpe_buyoff_cycle_id preserving type)      as MfgBuyOffCycle,
      cast('00000000' as hrobjid preserving type)                         as RespyMgmtTeamID,
      cast('' as rsm_de_function)                                         as RespyMgmtFunction,
      cast(0 as co_iprzs)                                                 as BusinessProcessConfirmedQty,
      cast('' as mpe_log_unit)                                            as ProductionUnit,
      cast(0 as mpe_actl_exec_duration)                                   as OpActyActualDurnInSeconds,
      cast('' as mpe_is_posted_retroactively preserving type)             as PostingIsRetroactive,
      act.MfgActionReasonCodeGroupCtlg                                    as MfgActionReasonCodeGroupCtlg,
      act.MfgActionReasonCodeGroup                                        as MfgActionReasonCodeGroup,
      act.ManufacturingActionReasonCode                                   as ManufacturingActionReasonCode,
      note.MfgExecutionDocumentNote                                       as MfgExecutionDocumentNote,
      cast('' as equnr)                                                   as Equipment,
      cast(case act.ProductionHoldItem
           when 1 then
             case act._ProductionHoldBasic.ProdnHoldIsAppldForOrderChg
               when 'X' then '064' else '027'
             end
           else
              case act._ProductionHoldBasic.ProdnHoldIsAppldForOrderChg
                when 'X' then '065' else '030'
             end
       end as msgnr)                                                      as SystemMessageNumber,
      cast('MPE_EXEC_COMMON     ' as msgid preserving type)               as SystemMessageIdentification,
      20                                                                  as MfgExecHistMsgVarblField1,
      18                                                                  as MfgExecHistMsgVarblField2, --ManufacturingOrderOperation
      17                                                                  as MfgExecHistMsgVarblField3,
      0                                                                   as MfgExecHistMsgVarblField4,
      cast('' as qdefectid)                                               as Defect,
      cast('' as mpe_file_name)                                           as MfgProcgExecAttachmentName
}
where
  hold.ProductionHoldObjectType = '4'

union all

-- SFIs sent to rework operations
select from  I_SFIReworkOperation  as sfirwrk
  inner join I_OrderOperationBasic as oper                on  oper.OrderInternalID          = sfirwrk.OrderInternalID
                                                          and oper.OrderOperationInternalID = sfirwrk.OrderOperationInternalID
  inner join I_LogisticsOrderBasic as LogisticsOrderBasic on LogisticsOrderBasic.OrderInternalID = sfirwrk.OrderInternalID
{
  key cast (254 as mpe_exec_doc_category preserving type)                     as MfgExecDocumentCategory,
  key sfirwrk.ShopFloorItem                                                   as ManufacturingExecutionDocument,
  key cast(sfirwrk.OrderOperationInternalID as mpe_doc_item)                  as MfgExecutionDocumentItem,
  key cast('' as mpe_action_name_type)                                        as MfgProcgExecAction,
      LogisticsOrderBasic.OrderID                                             as ManufacturingOrder,
      cast('  ' as mpe_buyoff_action preserving type)                         as MfgBuyOffAction,
      cast(0 as mpe_log_event)                                                as MfgObjectLogEventType,
      @Semantics.businessDate.at: true
      cast(sfirwrk.CreationDateTime as mpe_perform_timestamp)                 as EventDateTime,
      cast(sfirwrk.CreatedByUser as mpe_performed_by_user preserving type)    as ShopFloorExecutionUser,
      @Semantics.user.createdBy: true
      cast(sfirwrk.CreatedByUser as mpe_create_user preserving type)          as CreatedByUser,
      @Semantics.systemDateTime.createdAt: true
      cast(sfirwrk.CreationDateTime as mpe_create_timestampl preserving type) as CreationDateTime,
      cast(900 as rszsort)                                                    as SortField,
      oper.OrderInternalID                                                    as OrderInternalID,
      oper.OrderOperationInternalID                                           as OrderOperationInternalID,
      cast(oper.Sequence as manufacturingordersequence preserving type)       as ManufacturingOrderSequence,
      cast(oper.Operation as manufacturingorderoperation preserving type)     as ManufacturingOrderOperation,
      cast(oper.OperationText as mfgorderoperationtext preserving type)       as MfgOrderOperationText,
      cast(oper.WorkCenterInternalID as pph_arbid preserving type)            as WorkCenterInternalID,
      oper.WorkCenterTypeCode                                                 as WorkCenterTypeCode,
      cast( case oper.WorkCenterInternalID
        when '00000000' then ''
        else oper.Plant
      end as mpe_wrk_ctr_plant preserving type )                              as WorkCenterPlant,
      sfirwrk.ShopFloorItem                                                   as ShopFloorItem,
      cast(0 as mpe_sfi_at_oai_group_id)                                      as OperationActivitySFIGroup,
      cast(0 as mpe_oan_instance_id)                                          as OpActyNtwkInstance,
      cast(0 as mpe_oan_element_number)                                       as OpActyNtwkElement,
      cast('' as mpe_oa_description)                                          as OperationActivityName,
      cast('0' as mpe_oan_segment_type preserving type)                       as OpActyNtwkSegmentType,
      cast(0 as mpe_oan_id)                                                   as OperationActivityNetwork,
      cast(0 as mpe_oan_version_no)                                           as OpActyNtwkVersionCounter,
      cast('' as mpe_oan_element_number_ext)                                  as OpActyNtwkElementExternalID,
      cast(0 as mpe_oa_id)                                                    as OperationActivity,
      cast(0 as  mpe_oa_version_no)                                           as OperationActyVersionCounter,
      cast('' as mpe_sasname_type)                                            as StatusAndActionSchema,
      cast('' as qdefectinternalid)                                           as DefectInternalID,
      cast('' as qmnum)                                                       as Notification,
      cast('0000' as felfd preserving type)                                   as NotificationItem,
      cast('' as mpe_component_matnr)                                         as MaterialComponent,
      cast('' as maktx)                                                       as MaterialComponentName,
      cast(0 as mpe_assembled_sfi_id)                                         as AssembledShopFloorItem,
      cast('' as mpe_assembled_sernr)                                         as AssembledSerialNumber,
      cast('' as mpe_assembled_mfr_sernr)                                     as AssembledMfrSerialNumber,
      cast('' as mpe_assembled_batch)                                         as AssembledBatch,
      cast('' as vmp_ref_des)                                                 as ReferenceDesignatorValue,
      cast('    ' as lgort_d preserving type)                                 as StorageLocation,
      cast('' as inventoryusabilitycode preserving type)                      as InventoryUsabilityCode,
      cast('' as mpe_disassembly_permanence preserving type )                 as CompDisassemblyPermanence,
      cast('' as mpe_is_reassembly preserving type )                          as MaterialComponentHasReltdComp,
      cast(0 as mpe_buyoff_step)                                              as MfgBuyOffInternalID,
      cast('' as mpe_buyoffsqnc_desc)                                         as MfgBuyOffDescription,
      cast(0 as mpe_buyoff_step)                                              as MfgBuyOffReferencedStep,
      cast('' as mpe_buyoffsqnc_desc)                                         as MfgBuyOffAdhocStepDescription,
      cast('000000000000000' as mpe_buyoff_cycle_id preserving type)          as MfgBuyOffCycle,
      cast('00000000' as hrobjid preserving type)                             as RespyMgmtTeamID,
      cast('' as rsm_de_function)                                             as RespyMgmtFunction,
      cast(0 as co_iprzs)                                                     as BusinessProcessConfirmedQty,
      cast('' as mpe_log_unit)                                                as ProductionUnit,
      cast(0 as mpe_actl_exec_duration)                                       as OpActyActualDurnInSeconds,
      cast('' as mpe_is_posted_retroactively preserving type)                 as PostingIsRetroactive,
      cast('' as qkatart)                                                     as MfgActionReasonCodeGroupCtlg,
      cast('' as qcodegrp)                                                    as MfgActionReasonCodeGroup,
      cast('' as mpe_action_reason_code)                                      as ManufacturingActionReasonCode,
      ''                                                                      as MfgExecutionDocumentNote,
      cast('' as equnr)                                                       as Equipment,
      cast('027' as msgnr)                                                    as SystemMessageNumber,
      cast('MPE_EXEC_SFI' as msgid)                                           as SystemMessageIdentification,
      7                                                                       as MfgExecHistMsgVarblField1,
      18                                                                      as MfgExecHistMsgVarblField2,
      0                                                                       as MfgExecHistMsgVarblField3,
      0                                                                       as MfgExecHistMsgVarblField4,
      cast('' as qdefectid)                                                   as Defect,
      cast('' as mpe_file_name)                                               as MfgProcgExecAttachmentName
}