P_PurReqnProcFlowGR is a Composite CDS View in SAP S/4HANA. It reads from 2 data sources (P_PurchasingDocHistory, I_PurgDocScheduleLine) and exposes 8 fields with key fields ReferenceDocumentendasPrecedingDocument, SubsequentDocument, SubsequentDocumentItem.
@VDM.private: true@VDM.viewType: #COMPOSITE@AbapCatalog.sqlViewName: 'PPURREQNPFGR'
@AbapCatalog.compiler.compareFilter: true@AccessControl.authorizationCheck: #PRIVILEGED_ONLY//@AccessControl.privilegedAssociations: [ '_purgDocHist' ]@ClientHandling.algorithm: #SESSION_VARIABLEdefineview P_PurReqnProcFlowGR as//PO-->GR, PO-->SES-->GR
//EKET(Find PO for the PR) then Look for GR for the PO
selectfrom 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_MaterialDocumentRecord as _matDoc
on _purgDocHist.MaterialDocumentYear = _matDoc.MaterialDocumentYear
and _purgDocHist.MaterialDocument = _matDoc.MaterialDocument
and _purgDocHist.MaterialDocumentItem = _matDoc.MaterialDocumentItem
{
keycasewhen ( _purgDocHist.PurchaseOrderTransactionType = 'S' ) or
( _purgDocHist.ReferenceDocument = _purgDocHist.MaterialDocument ) or
( _purgDocHist.ReferenceDocument like '5%' ) or//3209157
( _purgDocHist.ReferenceDocument = '' )
then _purgDocHist.PurchasingDocument
else
_purgDocHist.ReferenceDocument
endas PrecedingDocument,
keycasewhen ( _purgDocHist.PurchaseOrderTransactionType = 'S' ) or
( _purgDocHist.ReferenceDocument = _purgDocHist.MaterialDocument ) or
( _purgDocHist.ReferenceDocument like '5%' ) or//3209157
( _purgDocHist.ReferenceDocument = '' )
then _purgDocHist.PurchasingDocumentItem
elsecast( _purgDocHist.ReferenceDocumentItem as char5)
endas PrecedingDocumentItem,
key _purgDocHist.MaterialDocument as SubsequentDocument,
keycast(_purgDocHist.MaterialDocumentItem as char5) as SubsequentDocumentItem,
casewhen ( _purgDocHist.PurchaseOrderTransactionType = 'S' ) or
( _purgDocHist.ReferenceDocument = _purgDocHist.MaterialDocument ) or
( _purgDocHist.ReferenceDocument like '5%' ) or//3209157
( _purgDocHist.ReferenceDocument = '' )
thencast( 'F' as ebstyp)
elsecast( 'S' as ebstyp)
endas PrecedingDocumentCategory,
_purgDocHist.PurchaseOrderTransactionType as SubsequentDocumentCategory,
_matDoc.MaterialDocumentYear,
_matDoc.CompanyCode,
//For Filtering
schedgLine.PurchaseRequisition as PurchaseRequisition,
schedgLine.PurchaseRequisitionItem as PurchaseRequisitionItem
}
where
( _purgDocHist.PurchaseOrderTransactionType = '1' or//Goods Receipt
( _purgDocHist.PurchaseOrderTransactionType = 'S' and _purgDocHist.Quantity isnot initial ) ) // Service Entry Sheet
//Why Quantity isnot initial condition?
//Incase SES is created and deleted, quantity in history is initialized. Hence, quantity isnot initia, then do not show
//This can be achived through associating with ses viewand condition with IsDeleted field. But with new association complexity increases
and _purgDocItem.PurchasingDocumentCategory = 'F' //PO
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_MATERIALDOCUMENTRECORD",
"I_PURCHASINGDOCUMENTITEM",
"I_PURGDOCSCHEDULELINE",
"P_PURCHASINGDOCHISTORY"
],
"ASSOCIATED":
[
"I_MATERIALDOCUMENTRECORD",
"I_PURCHASINGDOCUMENTITEM"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/