P_BillingDocProcFlow10 is a Consumption CDS View in SAP S/4HANA. It reads from 2 data sources (P_BillingDocProcFlow0, I_SDDocumentProcessFlow) and exposes 6 fields with key fields Level1Document, Level1DocumentItem.
@ClientHandling.algorithm: #SESSION_VARIABLE@ObjectModel.usageType.dataClass: #MIXED@ObjectModel.usageType.serviceQuality: #C@ObjectModel.usageType.sizeCategory: #XL@VDM.private: true@AccessControl.authorizationCheck: #NOT_REQUIRED@VDM.viewType: #CONSUMPTION@AbapCatalog.sqlViewName: 'PBILLGDOCPROCF10'
@AbapCatalog.preserveKey:truedefineview P_BillingDocProcFlow10
asselectfrom P_BillingDocProcFlow0 as Level0 --> Level 0
innerjoin I_SDDocumentProcessFlow as Level1 --> Level 1
on Level0.BillingDocument = Level1.PrecedingDocument
and (
Level1.SubsequentDocumentCategory = 'O' or --> Credit Memo
Level1.SubsequentDocumentCategory = 'P' or --> Debit Memo
Level1.SubsequentDocumentCategory = 'K' or --> Credit Memo Request
Level1.SubsequentDocumentCategory = 'L' or --> Debit Memo Request
Level1.SubsequentDocumentCategory = 'H' or --> Returns
Level1.SubsequentDocumentCategory = '6' or --> Intercompany Credit Memo
Level1.SubsequentDocumentCategory = 'N' or --> Invoice Cancellatiom
Level1.SubsequentDocumentCategory = 'S' --> Credit Memo Cancellation
)
leftouter to one join
I_SalesDocumentBasic as SalesDocument
on Level1.SubsequentDocument = SalesDocument.SalesDocument
leftouter to one join
I_BillingDocument as BillingDocument
on Level1.SubsequentDocument = BillingDocument.BillingDocument
{
//Keykey Level1.SubsequentDocument as Level1Document,
key Level1.SubsequentDocumentItem as Level1DocumentItem,
key//Category
casewhen
( ( Level1.SubsequentDocumentCategory = 'K' or --> Credit Memo Request
Level1.SubsequentDocumentCategory = 'L' ) and --> Debit Memo Request
SalesDocument.SDDocumentCategory isnotnull ) --> not archived
then SalesDocument.SDDocumentCategory --> from header for mixed documents
when
( ( Level1.SubsequentDocumentCategory = 'O' or --> Credit Memo
Level1.SubsequentDocumentCategory = 'P' ) and --> Debit Memo
BillingDocument.SDDocumentCategory isnotnull ) --> not archived
then BillingDocument.SDDocumentCategory --> from header for mixed documents
when
( ( (Level0.SDDocumentCategory = 'M' or Level0.SDDocumentCategory = 'P') and --> Level 0 is an Invoice/Debit Memo
Level1.PrecedingDocumentCategory = 'K' and --> Level 1 PrecedingDocument is a Credit Memo Request
Level1.SubsequentDocumentCategory = 'S' ) and --> Level 1 SubsequentDocument is a Credit Memo Cancelation
BillingDocument.SDDocumentCategory isnotnull ) --> Level 1 Header SDDocumentCategory must not be empty
then BillingDocument.SDDocumentCategory --> Use Level 1 Header SDDocumentCategory for Level 1 Item SDDocumentCategory
when
( ( Level0.SDDocumentCategory = 'O' and --> Level 0 PrecedingDocument is a Credit Memo
Level1.PrecedingDocumentCategory = 'L' and --> Level 1 PrecedingDocument is a Debit Memo Request
Level1.SubsequentDocumentCategory = 'N' ) and --> Level 1 SubsequentDocument is an Invoice Cancelation
BillingDocument.SDDocumentCategory isnotnull ) --> Level 1 Header SDDocumentCategory must not be empty
then BillingDocument.SDDocumentCategory --> Use Level 1 Header SDDocumentCategory for Level 1 Item SDDocumentCategory
else Level1.SubsequentDocumentCategory
endas Level1DocumentCategory,
Level0.BillingDocument,
Level0.BillingDocumentType,
Level0.SDDocumentCategory,
//Organizatio
Level0.SalesOrganization
}