P_PurReqnProcFlowInvc is a Composite CDS View in SAP S/4HANA. It reads from 2 data sources (P_PurchasingDocHistory, I_PurgDocScheduleLine) and exposes 10 fields with key fields ReferenceDocumentendasPrecedingDocument, SubsequentDocument, SubsequentDocumentItem.
@VDM.private: true@VDM.viewType: #COMPOSITE@AbapCatalog.sqlViewName: 'PPURREQNPFINV'
@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #PRIVILEGED_ONLY@ClientHandling.algorithm: #SESSION_VARIABLE//@AccessControl.privilegedAssociations: [ '_refDocumet' ]defineview P_PurReqnProcFlowInvc asselectfrom//PO-->IV(Incase GR Based IV isnot enabled in PO) or GR-->IV(Incase GR Based IV is enabled in PO)
//SES-->IV(Incase lean services)
I_PurgDocScheduleLine as _schedgLine
innerjoin P_PurchasingDocHistory as _purgDocHist
on _purgDocHist.PurchasingDocument = _schedgLine.PurchasingDocument
and _purgDocHist.PurchasingDocumentItem = _schedgLine.PurchasingDocumentItem
association to I_PurchasingDocumentItem as _purgDocItem
on _purgDocItem.PurchasingDocument = _schedgLine.PurchasingDocument
and _purgDocItem.PurchasingDocumentItem = _schedgLine.PurchasingDocumentItem
association to I_SupplierInvoice as _SupInvc
on _purgDocHist.MaterialDocument = _SupInvc.SupplierInvoice
and _purgDocHist.MaterialDocumentYear = _SupInvc.FiscalYear //2976706
association[0..*] to P_PurchasingDocHistory as _refDocumet
on _refDocumet.MaterialDocument = _purgDocHist.ReferenceDocument
and _refDocumet.MaterialDocumentItem = _purgDocHist.ReferenceDocumentItem
{
//---> Caculate Predecessor based on Reference Document of Invoice
//---> IF reference is initial, then PO is predecessor
//---> Else, GR is predecessor incase of material item
//---> SES is predecessor incase of lean services item
keycase _purgDocHist.ReferenceDocument
when ''
then _purgDocHist.PurchasingDocument
else
_purgDocHist.ReferenceDocument
endas PrecedingDocument,
keycase _purgDocHist.ReferenceDocument
when ''
then _purgDocHist.PurchasingDocumentItem
elsecast( _purgDocHist.ReferenceDocumentItem as char5)
endas PrecedingDocumentItem,
key _purgDocHist.MaterialDocument as SubsequentDocument,
keycast(_purgDocHist.MaterialDocumentItem as char5) as SubsequentDocumentItem,
case _purgDocHist.ReferenceDocument
when ''
thencast( 'F' as ebstyp)
elsecast( _refDocumet.PurchaseOrderTransactionType as ebstyp)
endas PrecedingDocumentCategory,
_purgDocHist.PurchaseOrderTransactionType as SubsequentDocumentCategory,
_SupInvc.FiscalYear,
_SupInvc.CompanyCode,
//For Filtering
_schedgLine.PurchaseRequisition as PurchaseRequisition,
_schedgLine.PurchaseRequisitionItem as PurchaseRequisitionItem,
_purgDocHist.ReferenceDocument,
_purgDocHist.ReferenceDocumentItem
//_refDocumet
}
where _purgDocHist.PurchaseOrderTransactionType = '2'
and _purgDocItem.PurchasingDocumentCategory = 'F'
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_PURCHASINGDOCUMENTITEM",
"I_PURGDOCSCHEDULELINE",
"I_SUPPLIERINVOICE",
"P_PURCHASINGDOCHISTORY"
],
"ASSOCIATED":
[
"I_PURCHASINGDOCUMENTITEM",
"I_SUPPLIERINVOICE",
"P_PURCHASINGDOCHISTORY"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/