@AbapCatalog.sqlViewName: 'PSDDPLSLSDOCGRPG'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'Grouping Criteria for Duplicate Sales Documents'
@VDM.viewType: #CONSUMPTION
@VDM.private: true
define view P_DuplicateSalesDocumentGrpg
with parameters
P_DateFunction : datefunctionid
as select from I_SalesDocument as SalesDocument
inner join C_SglGregorianCalDateFunction( P_DateFunction: $parameters.P_DateFunction, P_Language: $session.system_language ) as Range
on SalesDocument.CreationDate >= Range.DateFunctionStartDate
and SalesDocument.CreationDate <= Range.DateFunctionEndDate
{
key min( SalesDocument.SalesDocument ) as DuplicateSalesDocumentGroup,
count( * ) as NumberOfDuplicateSlsDocuments,
@ObjectModel.foreignKey.association: '_SDDocumentCategory'
SalesDocument.SDDocumentCategory,
SalesDocument._SDDocumentCategory,
@ObjectModel.foreignKey.association: '_SalesDocumentType'
SalesDocument.SalesDocumentType,
SalesDocument._SalesDocumentType,
@ObjectModel.foreignKey.association: '_SoldToParty'
SalesDocument.SoldToParty,
SalesDocument._SoldToParty,
SalesDocument.CreationDate,
SalesDocument.TotalNetAmount,
@ObjectModel.foreignKey.association: '_TransactionCurrency'
SalesDocument.TransactionCurrency,
SalesDocument._TransactionCurrency,
@ObjectModel.foreignKey.association: '_SalesOrganization'
SalesDocument.SalesOrganization,
SalesDocument._SalesOrganization,
@ObjectModel.foreignKey.association: '_DistributionChannel'
SalesDocument.DistributionChannel,
SalesDocument._DistributionChannel,
@ObjectModel.foreignKey.association: '_OrganizationDivision'
SalesDocument.OrganizationDivision,
SalesDocument._OrganizationDivision,
SalesDocument.PurchaseOrderByCustomer
}
where
SalesDocument.SalesDocumentProcessingType <> 'S'
and
SalesDocument.SalesDocumentProcessingType <> 'P'
and
SalesDocument.OverallSDDocumentRejectionSts <> 'C'
and(
SalesDocument.SDDocumentCategory = 'A' // Inquiry
or SalesDocument.SDDocumentCategory = 'B' // Quotation
or SalesDocument.SDDocumentCategory = 'C' // Order
or SalesDocument.SDDocumentCategory = 'G' // Contract
or SalesDocument.SDDocumentCategory = 'H' // Returns
or SalesDocument.SDDocumentCategory = 'I' // Order w/o charge
or SalesDocument.SDDocumentCategory = 'K' // Credit memo request
or SalesDocument.SDDocumentCategory = 'L' // Debit memo request
)
group by
SalesDocument.SDDocumentCategory,
SalesDocument.SalesDocumentType,
SalesDocument.SoldToParty,
SalesDocument.CreationDate,
SalesDocument.TotalNetAmount,
SalesDocument.TransactionCurrency,
SalesDocument.SalesOrganization,
SalesDocument.DistributionChannel,
SalesDocument.OrganizationDivision,
SalesDocument.PurchaseOrderByCustomer
having
count( * ) > 1
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"C_SGLGREGORIANCALDATEFUNCTION",
"I_SALESDOCUMENT"
],
"ASSOCIATED":
[
"I_CURRENCY",
"I_CUSTOMER",
"I_DISTRIBUTIONCHANNEL",
"I_DIVISION",
"I_SALESDOCUMENTTYPE",
"I_SALESORGANIZATION",
"I_SDDOCUMENTCATEGORY"
],
"BASE":
[
"I_SALESDOCUMENT"
],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/