C_InhRepairProcessFlow

DDL: C_INHREPAIRPROCESSFLOW Type: view CONSUMPTION Package: CRMS4_REPAIR_ODATA

Transaction History of In-House Repair Item

C_InhRepairProcessFlow is a Consumption CDS View that provides data about "Transaction History of In-House Repair Item" in SAP S/4HANA. It reads from 36 data sources and exposes 128 fields with key fields PrecedingDocument, PrecedingDocumentCategory, SubsequentDocument, InHouseRepairItem, SubsequentDocument. It has 5 associations to related views. Part of development package CRMS4_REPAIR_ODATA.

Associations (5)

CardinalityTargetAliasCondition
[0..1] I_ServiceDocument _SuccessorServiceTransaction rel1.CustMgmtSuccssrTransactionUUID = _SuccessorServiceTransaction.ServiceDocumentUUID and rel1.CustMgmtSuccssrTransacObjType = _SuccessorServiceTransaction.ServiceObjectType
[1..1] I_InHouseRepair _InHouseRepair $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType and $projection.InHouseRepair = _InHouseRepair.InHouseRepair
[0..1] I_ServiceDocument _PredecessorServiceTransaction rel1.CustMgmtPrdcssrTransactionUUID = _PredecessorServiceTransaction.ServiceDocumentUUID and rel1.CustMgmtPrdcssrTransacObjType = _PredecessorServiceTransaction.ServiceObjectType
[0..1] I_ServiceDocument _ServiceTransactionQ relVq.CustMgmtPrdcssrTransactionUUID = _ServiceTransactionQ.ServiceDocumentUUID and relVq.CustMgmtPrdcssrTransacObjType = _ServiceTransactionQ.ServiceObjectType
[0..1] I_ServiceDocument _ServiceTransactionO relVq.CustMgmtSuccssrTransactionUUID = _ServiceTransactionO.ServiceDocumentUUID and relVq.CustMgmtSuccssrTransacObjType = _ServiceTransactionO.ServiceObjectType

Annotations (12)

NameValueLevelField
EndUserText.label Transaction History of In-House Repair Item view
VDM.viewType #CONSUMPTION view
AccessControl.authorizationCheck #CHECK view
ObjectModel.usageType.serviceQuality #C view
ObjectModel.usageType.sizeCategory #XXL view
ObjectModel.usageType.dataClass #MIXED view
Metadata.ignorePropagatedAnnotations true view
Metadata.allowExtensions true view
ClientHandling.algorithm #SESSION_VARIABLE view
AbapCatalog.sqlViewName CINHRPRPROCFLW view
AbapCatalog.compiler.compareFilter true view
AbapCatalog.preserveKey true view

Fields (128)

KeyFieldSource TableSource FieldDescription
KEY PrecedingDocument I_InHouseRepairItem InHouseRepair
KEY PrecedingDocumentCategory
KEY SubsequentDocument _SuccessorServiceTransaction ServiceDocument
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY SubsequentDocument I_InHouseRepairItem InHouseRepair
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType _PredecessorServiceTransaction ServiceObjectType
ServiceDocument _PredecessorServiceTransaction ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument _ServiceTransactionO ServiceDocument
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType _SuccessorServiceTransaction ServiceObjectType
ServiceDocument _SuccessorServiceTransaction ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument _ServiceTransactionQ ServiceDocument
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType _SuccessorServiceTransaction ServiceObjectType
ServiceDocument _SuccessorServiceTransaction ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument _SuccessorServiceTransaction ServiceDocument
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType _PredecessorServiceTransaction ServiceObjectType
ServiceDocument _PredecessorServiceTransaction ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
PrecedingDocument
KEY PrecedingDocumentCategory I_SDDocumentMultiLevelProcFlow PrecedingDocumentCategory
KEY SubsequentDocument I_SDDocumentMultiLevelProcFlow SubsequentDocument
KEY SubsequentDocumentCategory I_SDDocumentMultiLevelProcFlow SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_CustomerReturn ServiceObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_SDDocumentMultiLevelProcFlow SubsequentDocument
KEY SubsequentDocumentCategory I_SDDocumentMultiLevelProcFlow SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType conf ServiceObjectType
ServiceDocument conf ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
PrecedingDocument
KEY PrecedingDocumentCategory I_SDDocumentMultiLevelProcFlow PrecedingDocumentCategory
KEY SubsequentDocument I_SDDocumentMultiLevelProcFlow SubsequentDocument
KEY SubsequentDocumentCategory I_SDDocumentMultiLevelProcFlow SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
CustomerReturnasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_InHouseRepairItem InHouseRepair
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
InHouseRepairasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_CustomerReturn DeliveryDocument
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
InHouseRepairasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_CustomerReturn CustomerReturn
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_SalesDocument SalesDocument
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
PrecedingDocumentasPrecedingDocument
KEY PrecedingDocumentCategory
KEY SubsequentDocument I_SDDocumentMultiLevelProcFlow SubsequentDocument
KEY SubsequentDocumentCategory
KEY InHouseRepairItem I_InHouseRepairItem InHouseRepairItem
ServiceObjectType I_InHouseRepairItem CustMgmtObjectType
ServiceDocument
InHouseRepair I_InHouseRepairItem InHouseRepair
InhRepairType I_InHouseRepairItem InhRepairType
CustMgmtObjectType I_InHouseRepairItem CustMgmtObjectType
_InHouseRepair _InHouseRepair
@EndUserText.label: 'Transaction History of In-House Repair Item'
@VDM: {
  viewType: #CONSUMPTION
}
@AccessControl: {
  authorizationCheck: #CHECK,
  personalData.blocking: #('TRANSACTIONAL_DATA')
}
@ObjectModel: {
  usageType: {serviceQuality: #C, sizeCategory: #XXL, dataClass: #MIXED}
}
@Metadata: {
  ignorePropagatedAnnotations: true,
  allowExtensions: true
}
@ClientHandling: {
  algorithm: #SESSION_VARIABLE
}
@AbapCatalog: {
  sqlViewName: 'CINHRPRPROCFLW',
  compiler.compareFilter: true,
  preserveKey: true
}
define view C_InhRepairProcessFlow

  // In-House Repair Items and Repair Quotations/Orders


  as select from           I_InHouseRepairItem           as repobj

  // there is at most one VONA relation to a service quotation or service order for each repair object

  // this is a left outer join, beacause when there is no service quotation and no order we still want to return a record for the repair object

    left outer to one join I_CustMgmtTransactionRelation as rel1 on rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                 and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                 and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                 and rel1.CustMgmtTransacRelationType    = 'VONA'

  // we have to read the object ID for the service quotation and order from I_ServiceDocument, because the relation view contains just GUIDs

  /*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
  association [0..1] to I_ServiceDocument as _SuccessorServiceTransaction on  rel1.CustMgmtSuccssrTransactionUUID = _SuccessorServiceTransaction.ServiceDocumentUUID
                                                                          and rel1.CustMgmtSuccssrTransacObjType  = _SuccessorServiceTransaction.ServiceObjectType

  // used for authorization check

  association [1..1] to I_InHouseRepair   as _InHouseRepair               on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                                          and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key repobj.InHouseRepair                         as PrecedingDocument,
  key 'REPA'                                       as PrecedingDocumentCategory,
  key _SuccessorServiceTransaction.ServiceDocument as SubsequentDocument,
  key case  _SuccessorServiceTransaction.ServiceDocumentIsQuotation
        when 'X' then 'REPQ'
        when ' ' then 'CSVO'
      end                                          as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      cast('' as crmt_subobject_category_db)       as ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db)                as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}

//  Repair Quotations/Orders and In-House Repair Items


  union all select from           I_InHouseRepairItem           as repobj

  // there is at most one VONA relation to a service quotation or service order for each repair object

  // this is a left outer join, beacause when there is no service quotation and no order we still want to return a record for the repair object

    inner join I_CustMgmtTransactionRelation as rel1 on rel1.CustMgmtSuccssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                 and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000116'
                                                                 and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000257'
                                                                 and rel1.CustMgmtTransacRelationType    = 'VONA'

  // we have to read the object ID for the service quotation and order from I_ServiceDocument, because the relation view contains just GUIDs

  /*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
  association [0..1] to I_ServiceDocument as _PredecessorServiceTransaction on  rel1.CustMgmtPrdcssrTransactionUUID = _PredecessorServiceTransaction.ServiceDocumentUUID
                                                                           and rel1.CustMgmtPrdcssrTransacObjType = _PredecessorServiceTransaction.ServiceObjectType

  // used for authorization check

  association [1..1] to I_InHouseRepair   as _InHouseRepair               on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                                          and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key _PredecessorServiceTransaction.ServiceDocument  as PrecedingDocument,
  key case  _PredecessorServiceTransaction.ServiceDocumentIsQuotation
        when 'X' then 'REPQ'
        when ' ' then 'CSVO'
      end                                          as PrecedingDocumentCategory,
  key repobj.InHouseRepair                         as SubsequentDocument,
  key 'REPA'                                       as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      _PredecessorServiceTransaction.ServiceObjectType  as ServiceObjectType,
      //cast('' as crmt_subobject_category_db)       as ServiceObjectType,

      // we need the ServiceDocument as navigation to service actuals

      _PredecessorServiceTransaction.ServiceDocument  as ServiceDocument,
      //cast('' as crmt_object_id_db)                as ServiceDocument,

      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}

    // Repair Quotations and Repair Orders


// Direction: in-house repair -> quotation -> order

union all select from I_InHouseRepairItem           as repobj

// here we read the relation to the service quotation

// there is at most one relation to a service quotation for each repair object

// this is an inner join to suppress all records that do not have a service order as successor of a quotation

  inner join          I_CustMgmtTransactionRelation as relQ on  relQ.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relQ.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relQ.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relQ.CustMgmtTransacRelationType    = 'IHR2'

// here we read the relation to the service order

// there is at most one relation to a service order for each repair object

// this is an inner join to suppress all records that do not have a service order as successor of a quotation

// note, we cannot read the orders as successor of the quotation, because there could be multiple orders per quotation (when the quotation contains multiple repair objects)

  inner join          I_CustMgmtTransactionRelation as relO on  relO.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relO.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relO.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relO.CustMgmtTransacRelationType    = 'IHR1'

// with introduction of diagnosis orders, it is now possible to have a quotation as follow-up of a diagnosis order.

// with this the quotation is no longer the follow-up of the ihr but of the diagnosis order.

// to find out if the diagnosis order or the quotation is the follow-up of the in-house repair we need the direct successor

// of the in-house repair. the direct successor is defined by a VONA relationship

  inner join          I_CustMgmtTransactionRelation as relX on  relX.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relX.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relX.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relX.CustMgmtTransacRelationType    = 'VONA'

// there is a VONA ralation from quotation to order

  inner join         I_CustMgmtTransactionRelation as relVq on  relVq.CustMgmtPrdcssrTransactionUUID = relQ.CustMgmtSuccssrTransactionUUID
                                                            and relVq.CustMgmtPrdcssrTransactionUUID = relX.CustMgmtSuccssrTransactionUUID
                                                            and relVq.CustMgmtSuccssrTransactionUUID = relO.CustMgmtSuccssrTransactionUUID
                                                            and relVq.CustMgmtPrdcssrTransacObjType  = 'BUS2000116'
                                                            and relVq.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relVq.CustMgmtTransacRelationType    = 'VONA'

// we have to read the object IDs for service quotation and order from I_ServiceDocument, because the relation view contains just GUIDs

/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _ServiceTransactionQ         on  relVq.CustMgmtPrdcssrTransactionUUID = _ServiceTransactionQ.ServiceDocumentUUID
                                                                        and relVq.CustMgmtPrdcssrTransacObjType  = _ServiceTransactionQ.ServiceObjectType
/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _ServiceTransactionO         on  relVq.CustMgmtSuccssrTransactionUUID = _ServiceTransactionO.ServiceDocumentUUID
                                                                        and relVq.CustMgmtSuccssrTransacObjType  = _ServiceTransactionO.ServiceObjectType

/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _SuccessorServiceTransaction on  relVq.CustMgmtPrdcssrTransactionUUID = _SuccessorServiceTransaction.ServiceDocumentUUID
                                                                        and relVq.CustMgmtPrdcssrTransacObjType  = _SuccessorServiceTransaction.ServiceObjectType

// used for authorization check

association [1..1] to I_InHouseRepair   as _InHouseRepair               on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key _ServiceTransactionQ.ServiceDocument         as PrecedingDocument,
  key 'REPQ'                                       as PrecedingDocumentCategory,
  key _ServiceTransactionO.ServiceDocument         as SubsequentDocument,
  key 'CSVO'                                       as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      _SuccessorServiceTransaction.ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      _SuccessorServiceTransaction.ServiceDocument as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}

// Direction: in-house repair -> order -> quotation

union all select from I_InHouseRepairItem           as repobj

// here we read the relation to the service quotation

// there is at most one relation to a service quotation for each repair object

// this is an inner join to suppress all records that do not have a service order as successor of a quotation

  inner join          I_CustMgmtTransactionRelation as relQ on  relQ.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relQ.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relQ.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relQ.CustMgmtTransacRelationType    = 'IHR2'

// here we read the relation to the service order

// there is at most one relation to a service order for each repair object

// this is an inner join to suppress all records that do not have a service order as successor of a quotation

// note, we cannot read the orders as successor of the quotation, because there could be multiple orders per quotation (when the quotation contains multiple repair objects)

  inner join          I_CustMgmtTransactionRelation as relO on  relO.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relO.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relO.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relO.CustMgmtTransacRelationType    = 'IHR1'

// with introduction of diagnosis orders, it is now possible to have a quotation as follow-up of a diagnosis order.

// with this the quotation is no longer the follow-up of the ihr but of the diagnosis order.

// to find out if the diagnosis order or the quotation is the follow-up of the in-house repair we need the direct successor

// of the in-house repair. the direct successor is defined by a VONA relationship

  inner join          I_CustMgmtTransactionRelation as relX on  relX.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                            and relX.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                            and relX.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relX.CustMgmtTransacRelationType    = 'VONA'

// there is a VONA ralation from order to quotation

  inner join          I_CustMgmtTransactionRelation as relVo on relVo.CustMgmtPrdcssrTransactionUUID = relO.CustMgmtSuccssrTransactionUUID
                                                            and relVo.CustMgmtPrdcssrTransactionUUID = relX.CustMgmtSuccssrTransactionUUID
                                                            and relVo.CustMgmtSuccssrTransactionUUID = relQ.CustMgmtSuccssrTransactionUUID
                                                            and relVo.CustMgmtPrdcssrTransacObjType  = 'BUS2000116'
                                                            and relVo.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                            and relVo.CustMgmtTransacRelationType    = 'VONA'

// we have to read the object IDs for service quotation and order from I_ServiceDocument, because the relation view contains just GUIDs

/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _ServiceTransactionO         on  relVo.CustMgmtPrdcssrTransactionUUID = _ServiceTransactionO.ServiceDocumentUUID
                                                                        and relVo.CustMgmtPrdcssrTransacObjType  = _ServiceTransactionO.ServiceObjectType
/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _ServiceTransactionQ         on  relVo.CustMgmtSuccssrTransactionUUID = _ServiceTransactionQ.ServiceDocumentUUID
                                                                        and relVo.CustMgmtSuccssrTransacObjType  = _ServiceTransactionQ.ServiceObjectType

/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _SuccessorServiceTransaction on  relVo.CustMgmtPrdcssrTransactionUUID = _SuccessorServiceTransaction.ServiceDocumentUUID
                                                                        and relVo.CustMgmtPrdcssrTransacObjType  = _SuccessorServiceTransaction.ServiceObjectType

// used for authorization check

association [1..1] to I_InHouseRepair   as _InHouseRepair               on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key _ServiceTransactionO.ServiceDocument         as PrecedingDocument,
  key 'CSVO'                                       as PrecedingDocumentCategory,
  key _ServiceTransactionQ.ServiceDocument         as SubsequentDocument,
  key 'REPQ'                                       as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      _SuccessorServiceTransaction.ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      _SuccessorServiceTransaction.ServiceDocument as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}


// Repair Orders and Repair Confirmations


union all select from     I_InHouseRepairItem           as repobj

// the following join is an inner join because here we want to be sure that we have an order

// there is at most one relation to a service order for each repair object

  inner join              I_CustMgmtTransactionRelation as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                and rel1.CustMgmtTransacRelationType    = 'IHR1' // with this condition we skip the repair quotation


// select the relations from service order to confirmation

// here we use an outer join so we get service orders when there is no confirmation

// this is necessary to get BUS2000116 in field ServiceObjectType to display details from the order (ServiceObjectType contains the BUS type of the predecessor)

  left outer to many join I_CustMgmtTransactionRelation as rel2 on  rel2.CustMgmtPrdcssrTransactionUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                and rel2.CustMgmtPrdcssrTransacObjType  = rel1.CustMgmtSuccssrTransacObjType
                                                                and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2000117'
                                                                and rel2.CustMgmtTransacRelationType    = 'VONA'

// we have to read the object IDs for service order and confirmation from I_ServiceDocument, because the relation view contains just GUIDs

/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _PredecessorServiceTransaction on  rel1.CustMgmtSuccssrTransactionUUID = _PredecessorServiceTransaction.ServiceDocumentUUID
                                                                          and rel1.CustMgmtSuccssrTransacObjType  = _PredecessorServiceTransaction.ServiceObjectType
/*+[hideWarning] { "IDS" : [ "CARDINALITY_CHECK" ] }*/
association [0..1] to I_ServiceDocument as _SuccessorServiceTransaction   on  rel2.CustMgmtSuccssrTransactionUUID = _SuccessorServiceTransaction.ServiceDocumentUUID
                                                                          and rel2.CustMgmtSuccssrTransacObjType  = _SuccessorServiceTransaction.ServiceObjectType

// used for authorization check

association [1..1] to I_InHouseRepair   as _InHouseRepair                 on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                                          and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key _PredecessorServiceTransaction.ServiceDocument as PrecedingDocument,
  key 'CSVO'                                         as PrecedingDocumentCategory,
  key _SuccessorServiceTransaction.ServiceDocument   as SubsequentDocument,
  key case when _SuccessorServiceTransaction.ServiceDocument is not null
        then'CSCO'
      end                                            as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      _PredecessorServiceTransaction.ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      _PredecessorServiceTransaction.ServiceDocument as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}



// Repair Orders and Billing Document Requests


// I_SDDocumentMultiLevelProcFlow returns multiple records when there are billing documents with multiple items, hence we use "select distinct" here.

union all select distinct from I_InHouseRepairItem      as repobj

// there is at most one relation to a service order for each repair object

  left outer to one join I_CustMgmtTransactionRelation  as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                and rel1.CustMgmtTransacRelationType    = 'IHR1' // with this condition we skip the repair quotation


// we have to read the object ID for the service order from I_ServiceDocument, because the relation view contains just GUIDs

  left outer to one join I_ServiceDocument              as ord  on  ord.ServiceDocumentUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                and ord.ServiceObjectType   = rel1.CustMgmtSuccssrTransacObjType

// the following join is an inner join to suppress all records that do not have a billing document request

// select the billing document requests for the service orders

  inner join             I_SDDocumentMultiLevelProcFlow as rel3 on  rel3.SubsequentDocumentCategory = 'EBDR'   // Billing Document Request

                                                                and rel3.PrecedingDocument          = ord.ServiceDocument
                                                                and rel3.PrecedingDocumentCategory  = 'CSVO'   // Service Order


// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key rel3.PrecedingDocument,
  key rel3.PrecedingDocumentCategory,
  key rel3.SubsequentDocument,
  key rel3.SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      ord.ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}



// Repair Confirmations and Billing Document Requests


// I_SDDocumentMultiLevelProcFlow returns multiple records when there are billing documents with multiple items, hence we use "select distinct" here.

union all select distinct from I_InHouseRepairItem       as repobj

// there is at most one relation to a service order for each repair object

  left outer to one join  I_CustMgmtTransactionRelation  as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                 and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                 and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                 and rel1.CustMgmtTransacRelationType    = 'IHR1' // with this condition we skip the repair quotation


// the following join is an inner join because here we want to be sure that we have a confirmation

// select the relations from service order to confirmation

  inner join              I_CustMgmtTransactionRelation  as rel2 on  rel2.CustMgmtPrdcssrTransactionUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                 and rel2.CustMgmtPrdcssrTransacObjType  = rel1.CustMgmtSuccssrTransacObjType
                                                                 and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2000117'
                                                                 and rel2.CustMgmtTransacRelationType    = 'VONA'

// we have to read the object ID for service confirmation from I_ServiceDocument, because the relation view contains just GUIDs

  left outer to one join  I_ServiceDocument              as conf on  conf.ServiceDocumentUUID = rel2.CustMgmtSuccssrTransactionUUID
                                                                 and conf.ServiceObjectType   = rel2.CustMgmtSuccssrTransacObjType

// select the billing document requests for the service confirmations

// here we use an outer join so we get service confirmations when there is no billing document request

// this is necessary to get BUS2000117 in field ServiceObjectType to display details from the confirmation (ServiceObjectType contains the BUS type of the predecessor)

  left outer to many join I_SDDocumentMultiLevelProcFlow as rel3 on  rel3.SubsequentDocumentCategory = 'EBDR'  // Billing Document Request

                                                                 and rel3.PrecedingDocument          = conf.ServiceDocument
                                                                 and rel3.PrecedingDocumentCategory  = 'CSCO'  // Service Confirmation


// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key conf.ServiceDocument as PrecedingDocument,
  key 'CSCO'               as PrecedingDocumentCategory,
  key rel3.SubsequentDocument,
  key rel3.SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      conf.ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      conf.ServiceDocument as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}



// Billing Document Requests and Billing Documents


// I_SDDocumentMultiLevelProcFlow returns multiple records when there are billing documents with multiple items, hence we use "select distinct" here.

union all select distinct from I_InHouseRepairItem       as repobj

// there is at most one relation to a service order for each repair object

  left outer to one join  I_CustMgmtTransactionRelation  as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                 and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                 and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                 and rel1.CustMgmtTransacRelationType    = 'IHR1' // with this condition we skip the repair quotation


// select the relations from service order to confirmation

  left outer to many join I_CustMgmtTransactionRelation  as rel2 on  rel2.CustMgmtPrdcssrTransactionUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                 and rel2.CustMgmtPrdcssrTransacObjType  = rel1.CustMgmtSuccssrTransacObjType
                                                                 and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2000117'
                                                                 and rel2.CustMgmtTransacRelationType    = 'VONA'

// the following joins are inner joins to suppress all records that do not have an invoice

// we have to read the object IDs for service order and confirmation from I_ServiceDocument, because the relation view contains just GUIDs

  left outer to one join  I_ServiceDocument              as ord  on  ord.ServiceDocumentUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                 and ord.ServiceObjectType   = rel1.CustMgmtSuccssrTransacObjType

  left outer to one join  I_ServiceDocument              as conf on  conf.ServiceDocumentUUID = rel2.CustMgmtSuccssrTransactionUUID
                                                                 and conf.ServiceObjectType   = rel2.CustMgmtSuccssrTransacObjType

// select the billing document requests for the service orders and confirmations

  inner join              I_SDDocumentMultiLevelProcFlow as rel3 on rel3.SubsequentDocumentCategory   = 'EBDR' // Billing Document Request

                                                                 and(
                                                                   rel3.PrecedingDocument             = conf.ServiceDocument
                                                                   and rel3.PrecedingDocumentCategory = 'CSCO' // Service Order

                                                                   or rel3.PrecedingDocument          = ord.ServiceDocument
                                                                   and rel3.PrecedingDocumentCategory = 'CSVO' // Service Confirmation

                                                                 )

// select the invoices for the billing document requests

  inner join              I_SDDocumentMultiLevelProcFlow as rel4 on  rel4.PrecedingDocument          = rel3.SubsequentDocument
                                                                 and rel4.PrecedingDocumentCategory  = rel3.SubsequentDocumentCategory
                                                                 and rel4.SubsequentDocumentCategory = 'M' // Invoice


// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key rel4.PrecedingDocument,
  key rel4.PrecedingDocumentCategory,
  key rel4.SubsequentDocument,
  key rel4.SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      cast('' as crmt_subobject_category_db) as ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db)          as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}

// Return Order and In-House Repair


union all select from I_InHouseRepairItem           as repobj

// Relation of Return Order with In-House Repair Item

  inner join          I_CustMgmtTransactionRelation as rel1 on  rel1.CustMgmtSuccssrTransactionUUID = repobj.InHouseRepairUUID
                                                            and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2102'
                                                            and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000256'
                                                            and rel1.CustMgmtTransacRelationType    = 'VONA' // with this condition we skip the repair quotation



// we have to read the Customer Return ID from I_CustomerReturn, because the relation view contains Transaction Key which is Return ID number

  inner join          I_CustomerReturn              as ord  on ord.CustomerReturn = rel1.CustMgmtPrdcssrTransactionKey
// and ord.CustomerReturnType = 'RE2'


// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key ord.CustomerReturn            as PrecedingDocument,
      // key ord.CustomerReturnType                      as PrecedingDocumentCategory,

  key 'H'                           as PrecedingDocumentCategory,
  key repobj.InHouseRepair          as SubsequentDocument,
      //  key repobj.InhRepairType                        as SubsequentDocumentCategory,

  key 'REPA'                        as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      repobj.CustMgmtObjectType     as ServiceObjectType,

      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}

// Outbound Delivery and In-House Repair


union all select from I_InHouseRepairItem           as repobj

  inner join          I_SrvcDocItemRelation         as ItemRel on  ItemRel.ServiceDocumentItemPredecessor = repobj.InHouseRepairItemCharUUID
                                                               and ItemRel.ServiceDocItmPrdcssrBusObjType = 'BUS2000257'
                                                               and ItemRel.ServiceDocItmSuccssrBusObjType = 'LIPS'
                                                               and ItemRel.ServiceDocumentItmRelationType = 'VONA'
// Relation of Return Order with In-House Repair Item

  inner join          I_CustMgmtTransactionRelation as rel1    on  rel1.CustMgmtTransacRelationUUID   = ItemRel.ServiceDocumentItmRelationUUID
                                                               and rel1.CustMgmtPrdcssrTransacObjType = 'BUS2000256'
                                                               and rel1.CustMgmtSuccssrTransacObjType = 'LIKP'
                                                               and rel1.CustMgmtTransacRelationType   = 'VONA'


// we have to read the Delivery Document ID from I_DeliveryDocument, because the relation view contains Transaction Key which is Delivery ID number

  inner join          I_DeliveryDocument            as ord     on ord.DeliveryDocument = rel1.CustMgmtSuccssrTransactionKey
//   and ord.DeliveryDocumentType = 'LR2' //'LF'


// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair


{
  key repobj.InHouseRepair          as PrecedingDocument,
  key 'REPA'                        as PrecedingDocumentCategory,
  key ord.DeliveryDocument          as SubsequentDocument,
  key 'J'                           as SubsequentDocumentCategory,
      // key ord.DeliveryDocumentType                    as SubsequentDocumentCategory,

  key repobj.InHouseRepairItem, // used to filter on in-house repair item


      repobj.CustMgmtObjectType     as ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType, // also required to read details like status from in-house repair

      @Consumption.hidden: true
      _InHouseRepair
}


// Return order as a follow-up of IHR

union all select from I_InHouseRepairItem           as repobj
// Relation of Return Order Header with In-House Repair Object

  inner join          I_InhRepairItmCustRetRelation as rel1 on  rel1.ServiceDocumentItemPredecessor = repobj.InHouseRepairItemCharUUID
                                                            and rel1.ServiceDocItmPrdcssrBusObjType = 'BUS2000257'
                                                            and rel1.ServiceDocItmSuccssrBusObjType = 'VBAP'
                                                            and rel1.ServiceDocumentItmRelationType = 'VONA'

// Relationship of In-House Repair with In-House Repair Objects

  inner join          I_CustMgmtTransactionRelation as rel2 on  rel2.CustMgmtTransacRelationUUID    = rel1.ServiceDocumentItmRelationUUID
                                                            and rel2.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairUUID
                                                            and rel2.CustMgmtPrdcssrTransacObjType  = 'BUS2000256'
                                                            and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2102'
                                                            and rel2.CustMgmtTransacRelationType    = 'VONA'

// Read the Customer Return ID from I_CustomerReturn, because the relation view contains Transaction Key which is Return ID number

  inner join          I_CustomerReturn              as ord  on ord.CustomerReturn = rel2.CustMgmtSuccssrTransactionKey

// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key repobj.InHouseRepair          as PrecedingDocument,
  key 'REPA'                        as PrecedingDocumentCategory,
  key ord.CustomerReturn            as SubsequentDocument,
  key 'H'                           as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem,

      repobj.CustMgmtObjectType     as ServiceObjectType,

      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType,
      @Consumption.hidden: true
      _InHouseRepair
}

//MSO and Debit Memo Requests


union all select from    I_InHouseRepairItem           as repobj

//There is at most one relation to a service order for each repair object

  left outer to one join I_CustMgmtTransactionRelation as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                               and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                               and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                               and rel1.CustMgmtTransacRelationType    = 'IHR1' //with this condition we skip the repair quotation


//we have to read the object ID for the service order from I_ServiceDocument, because the relation view contains just GUIDs

// will be use for Precending Document field

  left outer to one join I_ServiceDocument             as ord  on  ord.ServiceDocumentUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                               and ord.ServiceObjectType   = rel1.CustMgmtSuccssrTransacObjType

// the following join is an inner join to suppress all records that do not have a debit memo requests

// select the debit memo requests UUID

  inner join             I_CustMgmtTransactionRelation as rel2 on  rel2.CustMgmtPrdcssrTransactionUUID = ord.ServiceDocumentUUID
                                                               and rel2.CustMgmtPrdcssrTransacObjType  = 'BUS2000116'
                                                               and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2096'
                                                               and rel2.CustMgmtTransacRelationType    = 'VONA'

// select the debit memo request for the service orders

  inner join             I_SalesDocument               as dmr  on  dmr.SalesDocument = rel2.CustMgmtSuccssrTransactionKey

// used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key ord.ServiceDocument           as PrecedingDocument,
  key 'CSVO'                        as PrecedingDocumentCategory,
  key dmr.SalesDocument             as SubsequentDocument,
  key 'EDMR'                        as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, //used to filter on in-house repair item


      repobj.CustMgmtObjectType     as ServiceObjectType,

      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType,
      @Consumption.hidden: true
      _InHouseRepair
}

// Debit Memo Request and Debit Memo


union all select distinct from    I_InHouseRepairItem           as repobj

//there is at most one relation to a service order for each repair object

  left outer to one join I_CustMgmtTransactionRelation  as rel1 on  rel1.CustMgmtPrdcssrTransactionUUID = repobj.InHouseRepairItemUUID
                                                                and rel1.CustMgmtPrdcssrTransacObjType  = 'BUS2000257'
                                                                and rel1.CustMgmtSuccssrTransacObjType  = 'BUS2000116'
                                                                and rel1.CustMgmtTransacRelationType    = 'IHR1' //with this condition we skip the repair quotation


//the following join is an inner join to suppress all records that do not have a debit memo requests

//select the debit memo requests

  inner join             I_CustMgmtTransactionRelation  as rel2 on  rel2.CustMgmtPrdcssrTransactionUUID = rel1.CustMgmtSuccssrTransactionUUID
                                                                and rel2.CustMgmtPrdcssrTransacObjType  = 'BUS2000116'
                                                                and rel2.CustMgmtSuccssrTransacObjType  = 'BUS2096'
                                                                and rel2.CustMgmtTransacRelationType    = 'VONA'

//select the debit memo request for the service orders

  inner join             I_SalesDocument                as dmr  on  dmr.SalesDocument = rel2.CustMgmtSuccssrTransactionKey

//select the debit memo for the debit memo request

  inner join             I_SDDocumentMultiLevelProcFlow as dm   on  dm.PrecedingDocument          = dmr.SalesDocument
                                                                and dm.PrecedingDocumentCategory  = 'L'
                                                                and dm.SubsequentDocumentCategory = 'P'

//used for authorization check

association [1..1] to I_InHouseRepair as _InHouseRepair on  $projection.CustMgmtObjectType = _InHouseRepair.CustMgmtObjectType
                                                        and $projection.InHouseRepair      = _InHouseRepair.InHouseRepair

{
  key dm.PrecedingDocument          as PrecedingDocument,
  key 'EDMR'                        as PrecedingDocumentCategory,
  key dm.SubsequentDocument         as SubsequentDocument,
  key 'P'                           as SubsequentDocumentCategory,
  key repobj.InHouseRepairItem, //used to filter on in-house repair item


      repobj.CustMgmtObjectType     as ServiceObjectType,
      // we need the ServiceDocument as navigation to service actuals

      cast('' as crmt_object_id_db) as ServiceDocument,
      // used to filter on in-house repair item

      repobj.InHouseRepair,
      // used for authorization check

      @Consumption.hidden: true
      repobj.InhRepairType,
      repobj.CustMgmtObjectType,
      @Consumption.hidden: true
      _InHouseRepair
}