@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
)