C_RetsReferenceDocumentUnion

DDL: C_RETSREFERENCEDOCUMENTUNION Type: view_entity CONSUMPTION Package: ODATA_SD_RETURN_V2

Returns Reference Document

C_RetsReferenceDocumentUnion is a Consumption CDS View that provides data about "Returns Reference Document" in SAP S/4HANA. It reads from 12 data sources and exposes 82 fields with key field ReferenceSDDocument. Part of development package ODATA_SD_RETURN_V2.

Data Sources (12)

SourceAliasJoin Type
P_AllwdCustRetTypePerSlsOrg AllwdCustRetTypePerSlsOrg inner
P_AllwdCustRetTypePerSlsOrg AllwdCustRetTypePerSlsOrg inner
P_AllwdTypPerSlsOrgCnt AllwdTypPerSlsOrgCnt inner
P_AllwdTypPerSlsOrgCnt AllwdTypPerSlsOrgCnt inner
I_BillingDocument BillingDocument union_all
I_BillingDocument BillingDocument union_all
P_CustRetAvailRefSlsDocType CustRetCpyCtrlSrceDocType inner
P_CustRetAvailRefSlsDocType CustRetCpyCtrlSrceDocType inner
P_CustRetAvailRefBillgDocType CustRetCpyCtrlSrceDocType inner
P_CustRetAvailRefBillgDocType CustRetCpyCtrlSrceDocType inner
I_SalesDocument SalesDocument from
I_SalesDocument SalesDocument union_all

Annotations (7)

NameValueLevelField
VDM.viewType #CONSUMPTION view
AccessControl.authorizationCheck #NOT_REQUIRED view
ObjectModel.usageType.dataClass #MIXED view
ObjectModel.usageType.serviceQuality #C view
ObjectModel.usageType.sizeCategory #XL view
EndUserText.label Returns Reference Document view
Metadata.ignorePropagatedAnnotations true view

Fields (82)

KeyFieldSource TableSource FieldDescription
KEY ReferenceSDDocument
SDDocumentCategory I_SalesDocument SDDocumentCategory
ReferenceSDDocumentType
DocumentTypeName
PurchaseOrderByCustomer I_SalesDocument PurchaseOrderByCustomer
SoldToParty I_SalesDocument SoldToParty
SoldToPartyName
ShipToParty
ShipToPartyName
DocumentDate I_SalesDocument SalesDocumentDate
TotalNetAmount I_SalesDocument TotalNetAmount
TransactionCurrency I_SalesDocument TransactionCurrency
CreatedByUser I_SalesDocument CreatedByUser
ResponsibleEmployee
SalesOrganization I_SalesDocument SalesOrganization
DistributionChannel I_SalesDocument DistributionChannel
OrganizationDivision I_SalesDocument OrganizationDivision
SalesGroup I_SalesDocument SalesGroup
SalesOffice I_SalesDocument SalesOffice
PricingDate I_SalesDocument PricingDate
OverallSDProcessStatus I_SalesDocument OverallSDProcessStatus
SDDocumentCategory I_SalesDocument SDDocumentCategory
ReferenceSDDocumentType
DocumentTypeName
PurchaseOrderByCustomer I_SalesDocument PurchaseOrderByCustomer
SoldToParty I_SalesDocument SoldToParty
SoldToPartyName
ShipToParty
ShipToPartyName
DocumentDate I_SalesDocument SalesDocumentDate
TotalNetAmount I_SalesDocument TotalNetAmount
TransactionCurrency I_SalesDocument TransactionCurrency
CreatedByUser I_SalesDocument CreatedByUser
ResponsibleEmployee
SalesOrganization I_SalesDocument SalesOrganization
DistributionChannel I_SalesDocument DistributionChannel
OrganizationDivision I_SalesDocument OrganizationDivision
SalesGroup I_SalesDocument SalesGroup
SalesOffice I_SalesDocument SalesOffice
PricingDate I_SalesDocument PricingDate
OverallSDProcessStatus I_SalesDocument OverallSDProcessStatus
SDDocumentCategory I_BillingDocument SDDocumentCategory
ReferenceSDDocumentType
DocumentTypeName
PurchaseOrderByCustomer I_BillingDocument PurchaseOrderByCustomer
SoldToParty I_BillingDocument SoldToParty
SoldToPartyName
ShipToParty
ShipToPartyName
DocumentDate I_BillingDocument BillingDocumentDate
TotalNetAmount I_BillingDocument TotalNetAmount
TransactionCurrency I_BillingDocument TransactionCurrency
CreatedByUser I_BillingDocument CreatedByUser
ResponsibleEmployee
SalesOrganization I_BillingDocument SalesOrganization
DistributionChannel I_BillingDocument DistributionChannel
OrganizationDivision I_BillingDocument Division
SalesGroup
SalesOffice
PricingDate
OverallSDProcessStatus I_BillingDocument OverallSDProcessStatus
SDDocumentCategory I_BillingDocument SDDocumentCategory
ReferenceSDDocumentType
DocumentTypeName
PurchaseOrderByCustomer I_BillingDocument PurchaseOrderByCustomer
SoldToParty I_BillingDocument SoldToParty
SoldToPartyName
ShipToParty
ShipToPartyName
DocumentDate I_BillingDocument BillingDocumentDate
TotalNetAmount I_BillingDocument TotalNetAmount
TransactionCurrency I_BillingDocument TransactionCurrency
CreatedByUser I_BillingDocument CreatedByUser
ResponsibleEmployee
SalesOrganization I_BillingDocument SalesOrganization
DistributionChannel I_BillingDocument DistributionChannel
OrganizationDivision I_BillingDocument Division
SalesGroup
SalesOffice
PricingDate
OverallSDProcessStatus I_BillingDocument OverallSDProcessStatus
OverallSDProcessStatusDesc
@VDM.viewType: #CONSUMPTION
@AccessControl.authorizationCheck: #NOT_REQUIRED
@AccessControl.personalData.blocking: #('TRANSACTIONAL_DATA')
@AbapCatalog.viewEnhancementCategory: [#PROJECTION_LIST, #UNION]
@ObjectModel: {
  semanticKey: ['ReferenceSDDocument'],
  usageType: {
    dataClass:      #MIXED,
    serviceQuality: #C,
    sizeCategory:   #XL
  }
}
@EndUserText.label: 'Returns Reference Document'
@Metadata.ignorePropagatedAnnotations: true

define view entity C_RetsReferenceDocumentUnion
  as select from I_SalesDocument             as SalesDocument

    inner join   P_CustRetAvailRefSlsDocType as CustRetCpyCtrlSrceDocType on CustRetCpyCtrlSrceDocType.SourceSalesDocumentType = SalesDocument.SalesDocumentType
  //Below logic is needed for conbine sales area

    inner join   P_AllwdTypPerSlsOrgCnt      as AllwdTypPerSlsOrgCnt      on AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount <> 0
    inner join   P_AllwdCustRetTypePerSlsOrg as AllwdCustRetTypePerSlsOrg on  SalesDocument.DistributionChannel  = AllwdCustRetTypePerSlsOrg.DistributionChannel
                                                                          and SalesDocument.SalesOrganization    = AllwdCustRetTypePerSlsOrg.SalesOrganization
                                                                          and SalesDocument.OrganizationDivision = AllwdCustRetTypePerSlsOrg.Division
{
  key cast(SalesDocument.SalesDocument as vgbel preserving type)                                         as ReferenceSDDocument,

      SalesDocument.SDDocumentCategory,

      cast(SalesDocument.SalesDocumentType as vbart preserving type)                                     as ReferenceSDDocumentType,
      cast(SalesDocument._SalesDocumentType._Text[1: Language=$session.system_language].SalesDocumentTypeName as bezei40) as DocumentTypeName,

      //PO Number

      SalesDocument.PurchaseOrderByCustomer,

      //Sold-To Party

      SalesDocument.SoldToParty,
      cast('' as ad_namtext )                                                                            as SoldToPartyName,

      //Ship-To Party

      SalesDocument._StandardPartner.ShipToParty                                                         as ShipToParty,
      SalesDocument._StandardPartner._ShipToParty.CustomerFullName                                       as ShipToPartyName,

      //Document Date

      SalesDocument.SalesDocumentDate                                                                    as DocumentDate,

      //Total Amount

      @Semantics.amount.currencyCode: 'TransactionCurrency'
      SalesDocument.TotalNetAmount,

      SalesDocument.TransactionCurrency,

      SalesDocument.CreatedByUser,
      cast(SalesDocument._Partner[PartnerFunction = 'ZM'].Personnel as resp_empl)                        as ResponsibleEmployee,

      SalesDocument.SalesOrganization,

      SalesDocument.DistributionChannel,

      SalesDocument.OrganizationDivision,

      SalesDocument.SalesGroup                                                                           as SalesGroup,

      SalesDocument.SalesOffice                                                                          as SalesOffice,

      SalesDocument.PricingDate,

      SalesDocument.OverallSDProcessStatus,

      SalesDocument._OverallSDProcessStatus._Text[1: Language=$session.system_language].OverallSDProcessStatusDesc
}
where
  //Get rid of incomplete sales order in reference document

      SalesDocument.HdrGeneralIncompletionStatus     = 'C'
  and SalesDocument.OvrlItmGeneralIncompletionSts    = 'C'
  //Below logic is needed for conbine sales area

  and AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount > 0

union all

select from              I_SalesDocument             as SalesDocument
  inner join             P_CustRetAvailRefSlsDocType as CustRetCpyCtrlSrceDocType on CustRetCpyCtrlSrceDocType.SourceSalesDocumentType = SalesDocument.SalesDocumentType
//Below logic is needed for conbine sales area

  left outer to one join P_AllwdTypPerSlsOrgCnt      as AllwdTypPerSlsOrgCnt      on AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount <> 0
{
  key cast(SalesDocument.SalesDocument as vgbel preserving type)                                         as ReferenceSDDocument,

      SalesDocument.SDDocumentCategory,

      cast(SalesDocument.SalesDocumentType as vbart preserving type)                                     as ReferenceSDDocumentType,
      SalesDocument._SalesDocumentType._Text[1: Language=$session.system_language].SalesDocumentTypeName as DocumentTypeName,

      //PO Number

      SalesDocument.PurchaseOrderByCustomer,

      //Sold-To Party

      SalesDocument.SoldToParty,
      cast('' as ad_namtext )                                                                            as SoldToPartyName,

      //Ship-To Party

      SalesDocument._StandardPartner.ShipToParty                                                         as ShipToParty,
      SalesDocument._StandardPartner._ShipToParty.CustomerFullName                                       as ShipToPartyName,

      //Document Date

      SalesDocument.SalesDocumentDate                                                                    as DocumentDate,

      //Total Amount


      SalesDocument.TotalNetAmount,

      SalesDocument.TransactionCurrency,

      SalesDocument.CreatedByUser,

      cast(SalesDocument._Partner[PartnerFunction = 'ZM'].Personnel as resp_empl)                        as ResponsibleEmployee,

      SalesDocument.SalesOrganization,

      SalesDocument.DistributionChannel,

      SalesDocument.OrganizationDivision,

      SalesDocument.SalesGroup                                                                           as SalesGroup,

      SalesDocument.SalesOffice                                                                          as SalesOffice,

      SalesDocument.PricingDate,

      SalesDocument.OverallSDProcessStatus,

      SalesDocument._OverallSDProcessStatus._Text[1: Language=$session.system_language].OverallSDProcessStatusDesc
}
where
  //Get rid of incomplete sales order in reference document

       SalesDocument.HdrGeneralIncompletionStatus     = 'C'
  and  SalesDocument.OvrlItmGeneralIncompletionSts    = 'C'
  //Below logic is needed for conbine sales area

  and(
       AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount is null
    or AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount = 0
  )

union all

select from  I_BillingDocument             as BillingDocument
//Below logic is needed for conbine sales area

  inner join P_CustRetAvailRefBillgDocType as CustRetCpyCtrlSrceDocType on CustRetCpyCtrlSrceDocType.SourceBillingDocumentType = BillingDocument.BillingDocumentType
  inner join P_AllwdTypPerSlsOrgCnt        as AllwdTypPerSlsOrgCnt      on AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount <> 0
  inner join P_AllwdCustRetTypePerSlsOrg   as AllwdCustRetTypePerSlsOrg on  BillingDocument.DistributionChannel = AllwdCustRetTypePerSlsOrg.DistributionChannel
                                                                        and BillingDocument.SalesOrganization   = AllwdCustRetTypePerSlsOrg.SalesOrganization
                                                                        and BillingDocument.Division            = AllwdCustRetTypePerSlsOrg.Division
{
  key cast(BillingDocument.BillingDocument as vgbel preserving type)                                           as ReferenceSDDocument,

      BillingDocument.SDDocumentCategory,

      cast(BillingDocument.BillingDocumentType as vbart preserving type)                                       as ReferenceSDDocumentType,
      BillingDocument._BillingDocumentType._Text[1: Language=$session.system_language].BillingDocumentTypeName as DocumentTypeName,

      //Customer Reference


      BillingDocument.PurchaseOrderByCustomer,

      //Sold-To Party

      BillingDocument.SoldToParty,
      cast('' as ad_namtext )                                                                                  as SoldToPartyName,

      //Ship-To Party


      cast('' as kunwe)                                                                                        as ShipToParty,
      cast('' as shipto_name)                                                                                  as ShipToPartyName,

      //Document Date


      BillingDocument.BillingDocumentDate                                                                      as DocumentDate,

      //Total Amount


      BillingDocument.TotalNetAmount,

      BillingDocument.TransactionCurrency,

      BillingDocument.CreatedByUser,

      cast(BillingDocument._Partner[PartnerFunction = 'ZM'].Personnel as resp_empl)                            as ResponsibleEmployee,

      BillingDocument.SalesOrganization,

      BillingDocument.DistributionChannel,

      BillingDocument.Division                                                                                 as OrganizationDivision,

      //Placeholder, needed for union, SalesGroup not part of BillingDocument

      ''                                                                                                       as SalesGroup, //SalesGroup is not part of I_BillingDocument


      //Placeholder, needed for union, SalesOffice not part of BillingDocument

      ''                                                                                                       as SalesOffice, //SalesOffice is not part of I_BillingDocument

      '00000000'                                                                                               as PricingDate,

      BillingDocument.OverallSDProcessStatus,

      BillingDocument._OverallSDProcessStatus._Text[1: Language=$session.system_language].OverallSDProcessStatusDesc
}
where
      BillingDocument.BillingDocumentIsCancelled     <> 'X'
  //Get rid of temporary billing in reference document

  and BillingDocument.BillingDocumentIsTemporary     =  ''
  //Below logic is needed for conbine sales area

  and AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount >  0

union all

select from              I_BillingDocument             as BillingDocument
//Below logic is needed for conbine sales area

  inner join             P_CustRetAvailRefBillgDocType as CustRetCpyCtrlSrceDocType on CustRetCpyCtrlSrceDocType.SourceBillingDocumentType = BillingDocument.BillingDocumentType
  left outer to one join P_AllwdTypPerSlsOrgCnt        as AllwdTypPerSlsOrgCnt      on AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount <> 0
{
  key cast(BillingDocument.BillingDocument as vgbel preserving type)                                           as ReferenceSDDocument,

      BillingDocument.SDDocumentCategory,

      cast(BillingDocument.BillingDocumentType as vbart preserving type)                                       as ReferenceSDDocumentType,
      BillingDocument._BillingDocumentType._Text[1: Language=$session.system_language].BillingDocumentTypeName as DocumentTypeName,

      //Customer Reference

      BillingDocument.PurchaseOrderByCustomer,

      //Sold-To Party

      BillingDocument.SoldToParty,
      cast('' as ad_namtext )                                                                                  as SoldToPartyName,

      //Ship-To Party

      cast('' as kunwe)                                                                                        as ShipToParty,
      cast('' as shipto_name)                                                                                  as ShipToPartyName,

      //Document Date


      BillingDocument.BillingDocumentDate                                                                      as DocumentDate,

      //Total Amount


      BillingDocument.TotalNetAmount,

      BillingDocument.TransactionCurrency,

      BillingDocument.CreatedByUser,

      cast(BillingDocument._Partner[PartnerFunction = 'ZM'].Personnel as resp_empl)                            as ResponsibleEmployee,

      BillingDocument.SalesOrganization,

      BillingDocument.DistributionChannel,

      BillingDocument.Division                                                                                 as OrganizationDivision,
      //Placeholder, needed for union, SalesGroup not part of BillingDocument

      ''                                                                                                       as SalesGroup, //SalesGroup is not part of I_BillingDocument

      //Placeholder, needed for union, SalesOffice not part of BillingDocument

      ''                                                                                                       as SalesOffice, //SalesOffice is not part of I_BillingDocument

      '00000000'                                                                                               as PricingDate,
      BillingDocument.OverallSDProcessStatus,

      BillingDocument._OverallSDProcessStatus._Text[1: Language=$session.system_language].OverallSDProcessStatusDesc
}
where
       BillingDocument.BillingDocumentIsCancelled     <> 'X'
  //Get rid of temporary billing in reference document

  and  BillingDocument.BillingDocumentIsTemporary     =  ''
  and(
       AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount is null
    or AllwdTypPerSlsOrgCnt.AllwdOrdTypPerSlsOrgCount =  0
  )