P_SlsOrdFlfmtProcHierNode2

DDL: P_SLSORDFLFMTPROCHIERNODE2 SQL: PSDSOFPROCHRCND2 Type: view CONSUMPTION Package: ODATA_SD_SOF

Sales Order Fulfillment Process Hierarchy Node 2

P_SlsOrdFlfmtProcHierNode2 is a Consumption CDS View that provides data about "Sales Order Fulfillment Process Hierarchy Node 2" in SAP S/4HANA. It reads from 5 data sources (I_SalesDocumentBasic, P_SlsOrdFlfmt1stLvlSDProcSqnc1, P_SlsOrdFlfmt2ndLvlSDProcSqnc1, P_SlsOrdWithOvrlFlfmtSts1, P_SlsOrdFlfmtSupProcSqnc) and exposes 207 fields with key fields SalesDocument, HierarchyNode, HierarchyNodeLevel, NodeType, DocumentCategory. It has 16 associations to related views. Part of development package ODATA_SD_SOF.

Data Sources (5)

SourceAliasJoin Type
I_SalesDocumentBasic Lvl0 union_all
P_SlsOrdFlfmt1stLvlSDProcSqnc1 Lvl1 union_all
P_SlsOrdFlfmt2ndLvlSDProcSqnc1 Lvl2 union_all
P_SlsOrdWithOvrlFlfmtSts1 SOOvrl from
P_SlsOrdFlfmtSupProcSqnc SupLvl1 union_all

Associations (16)

CardinalityTargetAliasCondition
[0..1] I_SalesDocumentType _RootNodeDocumentSalesDocType $projection.RootNodeDocumentSalesDocType = _RootNodeDocumentSalesDocType.SalesDocumentType
[0..1] I_SalesDocumentType _SalesDocumentType $projection.SalesDocumentType = _SalesDocumentType.SalesDocumentType
[0..1] I_DeliveryDocumentType _DeliveryDocumentType $projection.DeliveryDocumentType = _DeliveryDocumentType.DeliveryDocumentType
[0..1] I_BillingDocumentType _BillingDocumentType $projection.BillingDocumentType = _BillingDocumentType.BillingDocumentType
[0..1] I_PurchasingDocumentType _PurchaseOrderType _PurchaseOrderType.PurchasingDocumentCategory = 'F' and $projection.PurchaseOrderType = _PurchaseOrderType.PurchasingDocumentType
[0..1] I_MfgOrderType _MfgOrderType $projection.ManufacturingOrderType = _MfgOrderType.ManufacturingOrderType
[0..1] I_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus $projection.SalesDocFulfillmentStatus = _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus
[0..1] I_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus $projection.OutbDelivFulfillmentStatus = _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus
[0..1] I_AccountingTransferStatus _AccountingTransferStatus $projection.AccountingTransferStatus = _AccountingTransferStatus.AccountingTransferStatus
[0..1] I_PurchasingDocumentStatus _PurchasingDocumentStatus $projection.PurchasingDocumentStatus = _PurchasingDocumentStatus.PurchasingDocumentStatus
[0..1] I_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts $projection.SlsOrdReltdPurProcFlfmtSts = _SlsOrdReltdPurProcFlfmtSts.SlsOrdReltdPurProcFlfmtSts
[0..1] I_SlsOrdReltdMfgProcFlfmtSts _SlsOrdReltdMfgProcFlfmtSts $projection.SlsOrdReltdMfgProcFlfmtSts = _SlsOrdReltdMfgProcFlfmtSts.SlsOrdReltdMfgProcFlfmtSts
[0..1] I_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts $projection.SalesOrdOvrlDelivFlfmtSts = _SalesOrdOvrlDelivFlfmtSts.SalesOrdOvrlDelivFlfmtSts
[0..1] I_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts $projection.SalesOrdOvrlInvcgFlfmtSts = _SalesOrdOvrlInvcgFlfmtSts.SalesOrdOvrlInvcgFlfmtSts
[0..1] I_Currency _TransactionCurrency $projection.TransactionCurrency = _TransactionCurrency.Currency
[0..1] I_OverallSDProcessStatus _OverallSDProcessStatus $projection.OverallSDProcessStatus = _OverallSDProcessStatus.OverallSDProcessStatus

Annotations (8)

NameValueLevelField
ClientHandling.algorithm #SESSION_VARIABLE view
ObjectModel.usageType.dataClass #MIXED view
ObjectModel.usageType.serviceQuality #C view
ObjectModel.usageType.sizeCategory #L view
VDM.private true view
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.viewType #CONSUMPTION view
AbapCatalog.sqlViewName PSDSOFPROCHRCND2 view

Fields (207)

KeyFieldSource TableSource FieldDescription
KEY SalesDocument SalesDocument
HierarchyNode
KEY HierarchyNode
KEY HierarchyNodeLevel
KEY NodeType
KEY DocumentCategory
SalesOrganization SalesOrganization
DistributionChannel DistributionChannel
OrganizationDivision OrganizationDivision
RootNodeDocumentSalesDocType
SalesDocumentType SalesDocumentType
TotalNetAmount TotalNetAmount
TransactionCurrency TransactionCurrency
DeliveryDocumentType
BillingDocumentType
PurchaseOrderType
ManufacturingOrderType
OverallSDProcessStatus P_SlsOrdWithOvrlFlfmtSts1 OverallSDProcessStatus
SalesOrdOvrlDelivFlfmtSts SalesOrdOvrlDelivFlfmtSts
SalesOrdOvrlInvcgFlfmtSts SalesOrdOvrlInvcgFlfmtSts
SalesDocFulfillmentStatus
OutbDelivFulfillmentStatus
AccountingTransferStatus
PurchasingDocumentStatus
SlsOrdReltdPurProcFlfmtSts
SlsOrdReltdMfgProcFlfmtSts
_SalesOrganization _SalesOrganization
_DistributionChannel _DistributionChannel
_OrganizationDivision _OrganizationDivision
_RootNodeDocumentSalesDocType _RootNodeDocumentSalesDocType
_SalesDocumentType _SalesDocumentType
_TransactionCurrency _TransactionCurrency
_DeliveryDocumentType _DeliveryDocumentType
_BillingDocumentType _BillingDocumentType
_PurchaseOrderType _PurchaseOrderType
_MfgOrderType _MfgOrderType
_OverallSDProcessStatus _OverallSDProcessStatus
_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts
_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts
_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus
_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus
_AccountingTransferStatus _AccountingTransferStatus
_PurchasingDocumentStatus _PurchasingDocumentStatus
_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts
KEY HierarchyNode
KEY HierarchyNodeLevel
KEY NodeType
KEY DocumentCategory SDDocumentCategory
SalesOrganization SalesOrganization
DistributionChannel DistributionChannel
OrganizationDivision OrganizationDivision
RootNodeDocumentSalesDocType
SalesDocumentType SalesDocumentType
TotalNetAmount TotalNetAmount
TransactionCurrency TransactionCurrency
DeliveryDocumentType
BillingDocumentType
PurchaseOrderType
ManufacturingOrderType
OverallSDProcessStatus I_SalesDocumentBasic OverallSDProcessStatus
SalesOrdOvrlDelivFlfmtSts
SalesOrdOvrlInvcgFlfmtSts
OutbDelivFulfillmentStatus
AccountingTransferStatus
PurchasingDocumentStatus
SlsOrdReltdPurProcFlfmtSts
SlsOrdReltdMfgProcFlfmtSts
_SalesOrganization _SalesOrganization
_DistributionChannel _DistributionChannel
_OrganizationDivision _OrganizationDivision
_RootNodeDocumentSalesDocType _RootNodeDocumentSalesDocType
_SalesDocumentType _SalesDocumentType
_TransactionCurrency _TransactionCurrency
_DeliveryDocumentType _DeliveryDocumentType
_BillingDocumentType _BillingDocumentType
_PurchaseOrderType _PurchaseOrderType
_MfgOrderType _MfgOrderType
_OverallSDProcessStatus _OverallSDProcessStatus
_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts
_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts
_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus
_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus
_AccountingTransferStatus _AccountingTransferStatus
_PurchasingDocumentStatus _PurchasingDocumentStatus
_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts
KEY HierarchyNode L1SubsequentDoc
KEY HierarchyNodeLevel
KEY DocumentCategory L1SubsequentDocCat
SalesOrganization SalesOrganization
DistributionChannel DistributionChannel
OrganizationDivision OrganizationDivision
RootNodeDocumentSalesDocType
TotalNetAmount
TransactionCurrency
DeliveryDocumentType
BillingDocumentType
PurchaseOrderType
ManufacturingOrderType
OverallSDProcessStatus P_SlsOrdFlfmt1stLvlSDProcSqnc1 L1OverallSDProcessStatus
SalesOrdOvrlDelivFlfmtSts
SalesOrdOvrlInvcgFlfmtSts
OutbDelivFulfillmentStatus
AccountingTransferStatus P_SlsOrdFlfmt1stLvlSDProcSqnc1 L1AccountingTransferStatus
PurchasingDocumentStatus
SlsOrdReltdPurProcFlfmtSts
SlsOrdReltdMfgProcFlfmtSts
_SalesOrganization _SalesOrganization
_DistributionChannel _DistributionChannel
_OrganizationDivision _OrganizationDivision
_RootNodeDocumentSalesDocType _RootNodeDocumentSalesDocType
_SalesDocumentType _SalesDocumentType
_TransactionCurrency _TransactionCurrency
_DeliveryDocumentType _DeliveryDocumentType
_BillingDocumentType _BillingDocumentType
_PurchaseOrderType _PurchaseOrderType
_MfgOrderType _MfgOrderType
_OverallSDProcessStatus _OverallSDProcessStatus
_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts
_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts
_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus
_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus
_AccountingTransferStatus _AccountingTransferStatus
_PurchasingDocumentStatus _PurchasingDocumentStatus
_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts
AccountingTransferStatuskeySalesDocument
KEY HierarchyNode L1SubsequentDoc
KEY HierarchyNodeLevel
KEY DocumentCategory L1SubsequentDocCat
SalesOrganization SalesOrganization
DistributionChannel DistributionChannel
OrganizationDivision OrganizationDivision
RootNodeDocumentSalesDocType
SalesDocumentType
TotalNetAmount
TransactionCurrency
DeliveryDocumentType
BillingDocumentType
PurchaseOrderType PurchaseOrderType
ManufacturingOrderType ManufacturingOrderType
SalesOrdOvrlDelivFlfmtSts
SalesOrdOvrlInvcgFlfmtSts
SalesDocFulfillmentStatus
OutbDelivFulfillmentStatus
AccountingTransferStatus
PurchasingDocumentStatus PurchasingDocumentStatus
SlsOrdReltdPurProcFlfmtSts SlsOrdReltdPurProcFlfmtSts
SlsOrdReltdMfgProcFlfmtSts SlsOrdReltdMfgProcFlfmtSts
_SalesOrganization _SalesOrganization
_DistributionChannel _DistributionChannel
_OrganizationDivision _OrganizationDivision
_RootNodeDocumentSalesDocType _RootNodeDocumentSalesDocType
_SalesDocumentType _SalesDocumentType
_TransactionCurrency _TransactionCurrency
_DeliveryDocumentType _DeliveryDocumentType
_BillingDocumentType _BillingDocumentType
_PurchaseOrderType _PurchaseOrderType
_MfgOrderType _MfgOrderType
_OverallSDProcessStatus _OverallSDProcessStatus
_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts
_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts
_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus
_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus
_AccountingTransferStatus _AccountingTransferStatus
_PurchasingDocumentStatus _PurchasingDocumentStatus
_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts
KEY HierarchyNode L2SubsequentDoc
KEY HierarchyNodeLevel
KEY DocumentCategory L2SubsequentDocCat
SalesOrganization SalesOrganization
DistributionChannel DistributionChannel
OrganizationDivision OrganizationDivision
RootNodeDocumentSalesDocType
SalesDocumentType
TotalNetAmount
TransactionCurrency
DeliveryDocumentType
BillingDocumentType
PurchaseOrderType
ManufacturingOrderType
OverallSDProcessStatus P_SlsOrdFlfmt2ndLvlSDProcSqnc1 L2OverallSDProcessStatus
SalesOrdOvrlDelivFlfmtSts
SalesOrdOvrlInvcgFlfmtSts
SalesDocFulfillmentStatus
OutbDelivFulfillmentStatus
AccountingTransferStatus P_SlsOrdFlfmt2ndLvlSDProcSqnc1 L2AccountingTransferStatus
PurchasingDocumentStatus
SlsOrdReltdPurProcFlfmtSts
SlsOrdReltdMfgProcFlfmtSts
_SalesOrganization _SalesOrganization
_DistributionChannel _DistributionChannel
_OrganizationDivision _OrganizationDivision
_RootNodeDocumentSalesDocType _RootNodeDocumentSalesDocType
_SalesDocumentType _SalesDocumentType
_TransactionCurrency _TransactionCurrency
_DeliveryDocumentType _DeliveryDocumentType
_BillingDocumentType _BillingDocumentType
_PurchaseOrderType _PurchaseOrderType
_MfgOrderType _MfgOrderType
_OverallSDProcessStatus _OverallSDProcessStatus
_SalesOrdOvrlDelivFlfmtSts _SalesOrdOvrlDelivFlfmtSts
_SalesOrdOvrlInvcgFlfmtSts _SalesOrdOvrlInvcgFlfmtSts
_SalesDocFulfillmentStatus _SalesDocFulfillmentStatus
_OutbDelivFulfillmentStatus _OutbDelivFulfillmentStatus
_AccountingTransferStatus _AccountingTransferStatus
_PurchasingDocumentStatus _PurchasingDocumentStatus
_SlsOrdReltdPurProcFlfmtSts _SlsOrdReltdPurProcFlfmtSts
_SlsOrdReltdMfgProcFlfmtSts _SlsOrdReltdMfgProcFlfmtSts
@ClientHandling.algorithm: #SESSION_VARIABLE 
@ObjectModel.usageType.dataClass: #MIXED
@ObjectModel.usageType.serviceQuality: #C
@ObjectModel.usageType.sizeCategory: #L

@VDM.private: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION

@AbapCatalog.sqlViewName: 'PSDSOFPROCHRCND2'

-- Union of Nodes for
-- Sales Order Overall Fulfillment, Initial Sales Order, Level 1 Subsequent SD Processes, Level 1 Subsequent Supply Processes, Level 2 Subsequent SD Processes

define view P_SlsOrdFlfmtProcHierNode2
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
// Node for sales order overall fulfillment 

as select from         P_SlsOrdWithOvrlFlfmtSts1    as SOOvrl

 association [0..1] to I_SalesDocumentType          as _RootNodeDocumentSalesDocType on $projection.RootNodeDocumentSalesDocType      = _RootNodeDocumentSalesDocType.SalesDocumentType 
 association [0..1] to I_SalesDocumentType          as _SalesDocumentType            on $projection.SalesDocumentType                 =            _SalesDocumentType.SalesDocumentType
 association [0..1] to I_DeliveryDocumentType       as _DeliveryDocumentType         on $projection.DeliveryDocumentType              =         _DeliveryDocumentType.DeliveryDocumentType                     
 association [0..1] to I_BillingDocumentType        as _BillingDocumentType          on $projection.BillingDocumentType               =          _BillingDocumentType.BillingDocumentType    
 association [0..1] to I_PurchasingDocumentType     as _PurchaseOrderType            on _PurchaseOrderType.PurchasingDocumentCategory =                             'F'
                                                                                    and $projection.PurchaseOrderType                 =            _PurchaseOrderType.PurchasingDocumentType                         
 association [0..1] to I_MfgOrderType               as _MfgOrderType                 on $projection.ManufacturingOrderType            =                 _MfgOrderType.ManufacturingOrderType                    
 association [0..1] to I_SalesDocFulfillmentStatus  as _SalesDocFulfillmentStatus    on $projection.SalesDocFulfillmentStatus         =    _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus                   
 association [0..1] to I_OutbDelivFulfillmentStatus as _OutbDelivFulfillmentStatus   on $projection.OutbDelivFulfillmentStatus        =   _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus                     
 association [0..1] to I_AccountingTransferStatus   as _AccountingTransferStatus     on $projection.AccountingTransferStatus          =     _AccountingTransferStatus.AccountingTransferStatus
 association [0..1] to I_PurchasingDocumentStatus   as _PurchasingDocumentStatus     on $projection.PurchasingDocumentStatus          =     _PurchasingDocumentStatus.PurchasingDocumentStatus                    
 association [0..1] to I_SlsOrdReltdPurProcFlfmtSts as _SlsOrdReltdPurProcFlfmtSts   on $projection.SlsOrdReltdPurProcFlfmtSts        =   _SlsOrdReltdPurProcFlfmtSts.SlsOrdReltdPurProcFlfmtSts                    
 association [0..1] to I_SlsOrdReltdMfgProcFlfmtSts as _SlsOrdReltdMfgProcFlfmtSts   on $projection.SlsOrdReltdMfgProcFlfmtSts        =   _SlsOrdReltdMfgProcFlfmtSts.SlsOrdReltdMfgProcFlfmtSts 
                                                                                                                                                      
{
  //key

  key SalesDocument,
  --key cast( concat_with_space( 'R', SalesDocument, 1 ) as dme_node )                   as HierarchyNode,    
  key cast( concat( '_', SalesDocument )               as dme_node )                   as HierarchyNode,    
  key cast( 0                                          as int2 )                       as HierarchyNodeLevel,   -- fulfillment process on Tree Hierarchy Node Level 0
  key cast( ''                                         as parnode )                    as ParentNode,
  key cast( 'ROOT'                                     as sls_ord_flfllmnt_node_type ) as NodeType,
  key cast( SOOvrl.SalesDocumentCategory               as vbtypl )                     as DocumentCategory,    
   
  //Organization

  SalesOrganization,
  DistributionChannel,
  OrganizationDivision,
  
  //Category

  @ObjectModel.foreignKey.association: '_RootNodeDocumentSalesDocType'
  cast( SalesDocumentType                              as auart )                      as RootNodeDocumentSalesDocType,
  SalesDocumentType,
  
  //Sales

  TotalNetAmount,
  TransactionCurrency,   
  
  //Subsequent Category

  @ObjectModel.foreignKey.association: '_DeliveryDocumentType'
  cast( ''                                             as lfart )                      as DeliveryDocumentType,
  @ObjectModel.foreignKey.association: '_BillingDocumentType'
  cast( ''                                             as fkart )                      as BillingDocumentType,  
  @ObjectModel.foreignKey.association: '_PurchaseOrderType'
  cast( ''                                             as esart )                      as PurchaseOrderType,  
  @ObjectModel.foreignKey.association: '_MfgOrderType'
  cast( ''                                             as manufacturingordertype )     as ManufacturingOrderType,
     
  //Status

  SOOvrl.OverallSDProcessStatus,
  
  //Sales Order Overall Delivery Fulfillment and Overall Invoicing Fulfillment Status

  SalesOrdOvrlDelivFlfmtSts,
  SalesOrdOvrlInvcgFlfmtSts, 
  
  //Sales Document Fulfillment Status 

  @ObjectModel.foreignKey.association: '_SalesDocFulfillmentStatus'
  cast( ''                                             as salesdocfulfillmentstatus )  as SalesDocFulfillmentStatus,
    
  //Outbound Delivery Fulfillment Status

  @ObjectModel.foreignKey.association: '_OutbDelivFulfillmentStatus'
  cast( ''                                             as outbdelivfulfillmentstatus ) as OutbDelivFulfillmentStatus, 
     
  //Accounting Transfer Status

  @ObjectModel.foreignKey.association: '_AccountingTransferStatus'
  cast( ''                                             as rfbsk )                      as AccountingTransferStatus,  
    
  //Purchasing Document Status

  @ObjectModel.foreignKey.association: '_PurchasingDocumentStatus'
  cast( ''                                             as mmpur_doc_status )           as PurchasingDocumentStatus, 
  
  //Sales Order Related Purchase Process Fulfillment Status

  @ObjectModel.foreignKey.association: '_SlsOrdReltdPurProcFlfmtSts'
  cast( ''                                             as slsordreltdpurprocflfmtsts ) as SlsOrdReltdPurProcFlfmtSts,
  
  //Sales Order Related Manfacturing Process Fulfillment Status

  @ObjectModel.foreignKey.association: '_SlsOrdReltdMfgProcFlfmtSts'
  cast( ''                                             as slsordreltdmfgprocflfmtsts ) as SlsOrdReltdMfgProcFlfmtSts, 
  
  //Associations

  _SalesOrganization,
  _DistributionChannel,
  _OrganizationDivision,
  
  _RootNodeDocumentSalesDocType,
  _SalesDocumentType,
  
  _TransactionCurrency,
  
  _DeliveryDocumentType,
  _BillingDocumentType,
  _PurchaseOrderType,
  _MfgOrderType,
  
  _OverallSDProcessStatus, 
  _SalesOrdOvrlDelivFlfmtSts,
  _SalesOrdOvrlInvcgFlfmtSts,
  _SalesDocFulfillmentStatus,
  _OutbDelivFulfillmentStatus,
  _AccountingTransferStatus,
  _PurchasingDocumentStatus,
  _SlsOrdReltdPurProcFlfmtSts,
  _SlsOrdReltdMfgProcFlfmtSts  
 } 
 
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
 // Node for initial Sales Order as level 0 process 

union all
 select from           I_SalesDocumentBasic         as Lvl0
 
 association [0..1] to I_SalesDocumentType          as _RootNodeDocumentSalesDocType on $projection.RootNodeDocumentSalesDocType      = _RootNodeDocumentSalesDocType.SalesDocumentType
 association [0..1] to I_DeliveryDocumentType       as _DeliveryDocumentType         on $projection.DeliveryDocumentType              =         _DeliveryDocumentType.DeliveryDocumentType               
 association [0..1] to I_BillingDocumentType        as _BillingDocumentType          on $projection.BillingDocumentType               =          _BillingDocumentType.BillingDocumentType    
 association [0..1] to I_PurchasingDocumentType     as _PurchaseOrderType            on _PurchaseOrderType.PurchasingDocumentCategory =                             'F'
                                                                                    and $projection.PurchaseOrderType                 =            _PurchaseOrderType.PurchasingDocumentType                   
 association [0..1] to I_MfgOrderType               as _MfgOrderType                 on $projection.ManufacturingOrderType            =                 _MfgOrderType.ManufacturingOrderType
 association [0..1] to I_SalesOrdOvrlDelivFlfmtSts  as _SalesOrdOvrlDelivFlfmtSts    on $projection.SalesOrdOvrlDelivFlfmtSts         =    _SalesOrdOvrlDelivFlfmtSts.SalesOrdOvrlDelivFlfmtSts        
 association [0..1] to I_SalesOrdOvrlInvcgFlfmtSts  as _SalesOrdOvrlInvcgFlfmtSts    on $projection.SalesOrdOvrlInvcgFlfmtSts         =    _SalesOrdOvrlInvcgFlfmtSts.SalesOrdOvrlInvcgFlfmtSts   
 association [0..1] to I_SalesDocFulfillmentStatus  as _SalesDocFulfillmentStatus    on $projection.SalesDocFulfillmentStatus         =    _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus            
 association [0..1] to I_OutbDelivFulfillmentStatus as _OutbDelivFulfillmentStatus   on $projection.OutbDelivFulfillmentStatus        =   _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus
 association [0..1] to I_AccountingTransferStatus   as _AccountingTransferStatus     on $projection.AccountingTransferStatus          =     _AccountingTransferStatus.AccountingTransferStatus 
 association [0..1] to I_PurchasingDocumentStatus   as _PurchasingDocumentStatus     on $projection.PurchasingDocumentStatus          =     _PurchasingDocumentStatus.PurchasingDocumentStatus  
 association [0..1] to I_SlsOrdReltdPurProcFlfmtSts as _SlsOrdReltdPurProcFlfmtSts   on $projection.SlsOrdReltdPurProcFlfmtSts        =   _SlsOrdReltdPurProcFlfmtSts.SlsOrdReltdPurProcFlfmtSts
 association [0..1] to I_SlsOrdReltdMfgProcFlfmtSts as _SlsOrdReltdMfgProcFlfmtSts   on $projection.SlsOrdReltdMfgProcFlfmtSts        =   _SlsOrdReltdMfgProcFlfmtSts.SlsOrdReltdMfgProcFlfmtSts 
                                                                                                                
{ 
  //key

  key SalesDocument,
  key cast( SalesDocument                              as dme_node )                   as HierarchyNode,
  key cast( 1                                          as int2 )                       as HierarchyNodeLevel,  -- initial sales order on Hierarchy Node Level 1
  key cast( concat( '_', SalesDocument )               as parnode )                    as ParentNode,
  key cast( 'SDOC'                                     as sls_ord_flfllmnt_node_type ) as NodeType,
  key SDDocumentCategory                                                               as DocumentCategory,
  
  //Organization

  SalesOrganization,
  DistributionChannel,
  OrganizationDivision,
  
  //Category

  @ObjectModel.foreignKey.association: '_RootNodeDocumentSalesDocType'
  cast( SalesDocumentType                              as auart )                      as RootNodeDocumentSalesDocType, 
  SalesDocumentType,  
  
  //Sales

  TotalNetAmount,
  TransactionCurrency, 
  
  //Subsequent Category

  cast( ''                                             as lfart )                      as DeliveryDocumentType, 
  cast( ''                                             as fkart )                      as BillingDocumentType,
  cast( ''                                             as esart  )                     as PurchaseOrderType,
  cast( ''                                             as manufacturingordertype)      as ManufacturingOrderType,  
    
  //Status

  Lvl0.OverallSDProcessStatus,
  
  //Sales Order Overall Delivery Fulfillment and Overall Invoicing Fulfillment Status

  cast( ''                                             as salesordovrldelivflfmtsts )  as SalesOrdOvrlDelivFlfmtSts,   
  cast( ''                                             as salesordovrlinvcgflfmtsts )  as SalesOrdOvrlInvcgFlfmtSts,          
    
  //Sales Document Fulfillment Status 

  @ObjectModel.foreignKey.association: '_SalesDocFulfillmentStatus'
  cast( 
   case when Lvl0.OverallSDDocumentRejectionSts = 'C'
         then '0'
        else
         case when Lvl0.OverallTotalDeliveryStatus != ''
               then case when Lvl0.OverallSDDocumentRejectionSts = 'B'         
                           then OverallTotalDeliveryStatus
                          else OverallDeliveryStatus
                     end     
              else
               case when Lvl0.OverallOrdReltdBillgStatus = 'A' then 'I'
                    when Lvl0.OverallOrdReltdBillgStatus = 'B' then 'J' 
                    when Lvl0.OverallOrdReltdBillgStatus = 'C' then 'K'  
                     else ''
                end
          end
    end                                                as salesdocfulfillmentstatus )  as SalesDocFulfillmentStatus,                
   
  //Outbound Delivery Fulfillment Status

  cast( ''                                             as outbdelivfulfillmentstatus ) as OutbDelivFulfillmentStatus, 
    
  //Accounting Transfer Status

  cast( ''                                             as rfbsk )                      as AccountingTransferStatus,   
    
  //Purchasing Document Status

  @ObjectModel.foreignKey.association: '_PurchasingDocumentStatus'
  cast( ''                                             as mmpur_doc_status)            as PurchasingDocumentStatus,
    
  //Sales Order Related Purchase Process Fulfillment Status

  cast( ''                                             as slsordreltdpurprocflfmtsts ) as SlsOrdReltdPurProcFlfmtSts,
    
  //Sales Order Related Manfacturing Process Fulfillment Status

  cast( ''                                             as slsordreltdmfgprocflfmtsts ) as SlsOrdReltdMfgProcFlfmtSts,
    
  //Associations

  _SalesOrganization,
  _DistributionChannel,
  _OrganizationDivision,
  
  _RootNodeDocumentSalesDocType,
  _SalesDocumentType,
  
  _TransactionCurrency,
  
  _DeliveryDocumentType,
  _BillingDocumentType,
  _PurchaseOrderType,
  _MfgOrderType,
   
  _OverallSDProcessStatus,
  _SalesOrdOvrlDelivFlfmtSts,
  _SalesOrdOvrlInvcgFlfmtSts,
  _SalesDocFulfillmentStatus,
  _OutbDelivFulfillmentStatus,
  _AccountingTransferStatus,
  _PurchasingDocumentStatus,
  _SlsOrdReltdPurProcFlfmtSts,
  _SlsOrdReltdMfgProcFlfmtSts   
}
------- as parent doc only SD doc categories:
where (Lvl0.SDDocumentCategory = 'C'        -- C - Order
   or  Lvl0.SDDocumentCategory = 'I'        -- I - Order Without Charge
   or  Lvl0.SDDocumentCategory = 'L'        -- L - Debit Memo Request
       )
       
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
  // Nodes for Sales and Distribution Processes Level 1

union all
 select from           P_SlsOrdFlfmt1stLvlSDProcSqnc1 as Lvl1
 
 association [0..1] to I_Currency                     as _TransactionCurrency          on $projection.TransactionCurrency               =          _TransactionCurrency.Currency                  
 association [0..1] to I_SalesDocumentType            as _RootNodeDocumentSalesDocType on $projection.RootNodeDocumentSalesDocType      = _RootNodeDocumentSalesDocType.SalesDocumentType
 association [0..1] to I_SalesDocumentType            as _SalesDocumentType            on $projection.SalesDocumentType                 =            _SalesDocumentType.SalesDocumentType
 association [0..1] to I_DeliveryDocumentType         as _DeliveryDocumentType         on $projection.DeliveryDocumentType              =         _DeliveryDocumentType.DeliveryDocumentType            
 association [0..1] to I_BillingDocumentType          as _BillingDocumentType          on $projection.BillingDocumentType               =          _BillingDocumentType.BillingDocumentType
 association [0..1] to I_PurchasingDocumentType       as _PurchaseOrderType            on _PurchaseOrderType.PurchasingDocumentCategory =                             'F'
                                                                                    and $projection.PurchaseOrderType                 =            _PurchaseOrderType.PurchasingDocumentType       
 association [0..1] to I_MfgOrderType                 as _MfgOrderType                 on $projection.ManufacturingOrderType            =                 _MfgOrderType.ManufacturingOrderType
 association [0..1] to I_OverallSDProcessStatus       as _OverallSDProcessStatus       on $projection.OverallSDProcessStatus            =       _OverallSDProcessStatus.OverallSDProcessStatus        
 association [0..1] to I_SalesOrdOvrlDelivFlfmtSts    as _SalesOrdOvrlDelivFlfmtSts    on $projection.SalesOrdOvrlDelivFlfmtSts         =    _SalesOrdOvrlDelivFlfmtSts.SalesOrdOvrlDelivFlfmtSts        
 association [0..1] to I_SalesOrdOvrlInvcgFlfmtSts    as _SalesOrdOvrlInvcgFlfmtSts    on $projection.SalesOrdOvrlInvcgFlfmtSts         =    _SalesOrdOvrlInvcgFlfmtSts.SalesOrdOvrlInvcgFlfmtSts  
 association [0..1] to I_SalesDocFulfillmentStatus    as _SalesDocFulfillmentStatus    on $projection.SalesDocFulfillmentStatus         =    _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus                                          
 association [0..1] to I_OutbDelivFulfillmentStatus   as _OutbDelivFulfillmentStatus   on $projection.OutbDelivFulfillmentStatus        =   _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus    
 association [0..1] to I_AccountingTransferStatus     as _AccountingTransferStatus     on $projection.AccountingTransferStatus          =     _AccountingTransferStatus.AccountingTransferStatus
 association [0..1] to I_PurchasingDocumentStatus     as _PurchasingDocumentStatus     on $projection.PurchasingDocumentStatus          =     _PurchasingDocumentStatus.PurchasingDocumentStatus  
 association [0..1] to I_SlsOrdReltdPurProcFlfmtSts   as _SlsOrdReltdPurProcFlfmtSts   on $projection.SlsOrdReltdPurProcFlfmtSts        =   _SlsOrdReltdPurProcFlfmtSts.SlsOrdReltdPurProcFlfmtSts
 association [0..1] to I_SlsOrdReltdMfgProcFlfmtSts   as _SlsOrdReltdMfgProcFlfmtSts   on $projection.SlsOrdReltdMfgProcFlfmtSts        =   _SlsOrdReltdMfgProcFlfmtSts.SlsOrdReltdMfgProcFlfmtSts
                                                                                                     
{
  //key 

  key SalesDocument,
  key L1SubsequentDoc                                                     as HierarchyNode, 
  key cast( 2                             as int2 )                       as HierarchyNodeLevel,  --Lvl 1 Subsequent maps to ProcessFlowLevel '00' maps to Tree HierarchyNodeLevel 2
  key SalesDocument                                                       as ParentNode,
    
  key cast(
          case
           when L1SubsequentDocCat = 'K'  then 'SDOC'  // Credit memo request

           when L1SubsequentDocCat = 'L'  then 'SDOC'  // Debit memo request

           when L1SubsequentDocCat = 'J'  then 'DDOC'  // Delivery

           when L1SubsequentDocCat = 'M'  then 'BDOC'  // Invoice            

           when L1SubsequentDocCat = 'O'  then 'BDOC'  // Credit memo

           when L1SubsequentDocCat = 'P'  then 'BDOC'  // Debit memo

           when L1SubsequentDocCat = 'U'  then 'BDOC'  // Pro forma invoice

          else  ''
           end                            as sls_ord_flfllmnt_node_type ) as NodeType,
  key L1SubsequentDocCat                                                  as DocumentCategory,
  
  //Organization

  SalesOrganization,
  DistributionChannel,
  OrganizationDivision,
  
  //Category

  @ObjectModel.foreignKey.association: '_RootNodeDocumentSalesDocType'
  cast( Lvl1.SalesDocumentType            as auart )                      as RootNodeDocumentSalesDocType, 
  @ObjectModel.foreignKey.association: '_SalesDocumentType'
  cast(
      case when L1SubsequentDocCat = 'K'  
             or L1SubsequentDocCat = 'L'
            then Lvl1.L1SalesDocumentType
           else ''
       end                                as auart )                      as SalesDocumentType,  
       
  //Sales

  @DefaultAggregation: #NONE
  @Semantics.amount.currencyCode: 'TransactionCurrency'
  cast( 0                                 as netwr_ak )                   as TotalNetAmount,
  @Semantics.currencyCode: true
  @ObjectModel.foreignKey.association: '_TransactionCurrency'
  cast( ''                                as waerk )                      as TransactionCurrency,
      
  //Subsequent Category

  @ObjectModel.foreignKey.association: '_DeliveryDocumentType'
  cast( Lvl1.L1DeliveryDocumentType       as lfart )                      as DeliveryDocumentType,

  @ObjectModel.foreignKey.association: '_BillingDocumentType'
  cast( Lvl1.L1BillingDocumentType        as fkart )                      as BillingDocumentType,  
      
  cast( ''                                as esart )                      as PurchaseOrderType,  
  cast( ''                                as manufacturingordertype )     as ManufacturingOrderType,    
      
  //Status

  @ObjectModel.foreignKey.association: '_OverallSDProcessStatus'
  Lvl1.L1OverallSDProcessStatus                                           as OverallSDProcessStatus, 
  
  //Sales Order Overall Delivery Fulfillment and Overall Invoicing Fulfillment Status

  cast( ''                                as salesordovrldelivflfmtsts )  as SalesOrdOvrlDelivFlfmtSts,
    
  cast( ''                                as salesordovrlinvcgflfmtsts )  as SalesOrdOvrlInvcgFlfmtSts,
    
  //Sales Document Fulfillment Status

--- to be calculated for L1 Debit Memo Request   
  @ObjectModel.foreignKey.association: '_SalesDocFulfillmentStatus'
  cast( 
   case when Lvl1.L1OvrlSDDocumentRejectionSts = 'C'
          then '0'
         else
          case when Lvl1.L1OverallTotalDeliveryStatus != ''
                then OverallTotalDeliveryStatus
               else
                case when Lvl1.L1OverallOrdReltdBillgStatus = 'A' then 'I'
                     when Lvl1.L1OverallOrdReltdBillgStatus = 'B' then 'J' 
                     when Lvl1.L1OverallOrdReltdBillgStatus = 'C' then 'K'  
                    else ''
                 end
           end
    end                                   as salesdocfulfillmentstatus )  as SalesDocFulfillmentStatus,  
    
  //Outbound Delivery Fulfillment Status

  @ObjectModel.foreignKey.association: '_OutbDelivFulfillmentStatus'
  cast( Lvl1.L1OverallGoodsMovementStatus as outbdelivfulfillmentstatus ) as OutbDelivFulfillmentStatus,
    
  //Accounting Transfer Status

  @ObjectModel.foreignKey.association: '_AccountingTransferStatus'
  Lvl1.L1AccountingTransferStatus                                         as AccountingTransferStatus, 
   
  //Purchasing Document Status

  @ObjectModel.foreignKey.association: '_PurchasingDocumentStatus'
  cast( ''                                as mmpur_doc_status )           as PurchasingDocumentStatus,
    
  //Sales Order Related Purchase Process Fulfillment Status

  cast( ''                                as slsordreltdpurprocflfmtsts ) as SlsOrdReltdPurProcFlfmtSts,
    
  //Sales Order Related Manfacturing Process Fulfillment Status

  cast( ''                                as slsordreltdmfgprocflfmtsts ) as SlsOrdReltdMfgProcFlfmtSts,
    
  //Associations

  _SalesOrganization,
  _DistributionChannel,
  _OrganizationDivision,
  
  _RootNodeDocumentSalesDocType,
  _SalesDocumentType,
  
  _TransactionCurrency,
  
  _DeliveryDocumentType,
  _BillingDocumentType,
  _PurchaseOrderType,
  _MfgOrderType,
    
  _OverallSDProcessStatus,
  _SalesOrdOvrlDelivFlfmtSts,
  _SalesOrdOvrlInvcgFlfmtSts,
  _SalesDocFulfillmentStatus,
  _OutbDelivFulfillmentStatus,
  _AccountingTransferStatus,
  _PurchasingDocumentStatus,
  _SlsOrdReltdPurProcFlfmtSts,
  _SlsOrdReltdMfgProcFlfmtSts  
}
where ( L1SubsequentDocCat = 'L'  // Debit memo request

   or L1SubsequentDocCat = 'J'  // Delivery

   
   or
     (L1SubsequentDocCat = 'M'  // Invoice   

   or L1SubsequentDocCat = 'O'  // Credit memo

   or L1SubsequentDocCat = 'P'  // Debit memo

   or L1SubsequentDocCat = 'U'  // Pro forma invoice

      ) and Lvl1.L1BillgDocIsCancelled != 'X' )
  and Lvl1.L1DeliveryDocumentType != '?!A'
  and Lvl1.L1BillingDocumentType != '?!A'
  and Lvl1.L1SalesDocumentType != '?!A'
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
  // Nodes for Supply Processes 

union all 
 select from           P_SlsOrdFlfmtSupProcSqnc     as SupLvl1

 association [0..1] to I_Currency                   as _TransactionCurrency          on $projection.TransactionCurrency               =          _TransactionCurrency.Currency                  
 association [0..1] to I_SalesDocumentType          as _RootNodeDocumentSalesDocType on $projection.RootNodeDocumentSalesDocType      = _RootNodeDocumentSalesDocType.SalesDocumentType
 association [0..1] to I_SalesDocumentType          as _SalesDocumentType            on $projection.SalesDocumentType                 =            _SalesDocumentType.SalesDocumentType
 association [0..1] to I_DeliveryDocumentType       as _DeliveryDocumentType         on $projection.DeliveryDocumentType              =         _DeliveryDocumentType.DeliveryDocumentType            
 association [0..1] to I_BillingDocumentType        as _BillingDocumentType          on $projection.BillingDocumentType               =          _BillingDocumentType.BillingDocumentType
 association [0..1] to I_OverallSDProcessStatus     as _OverallSDProcessStatus       on $projection.OverallSDProcessStatus            =       _OverallSDProcessStatus.OverallSDProcessStatus        
 association [0..1] to I_SalesOrdOvrlDelivFlfmtSts  as _SalesOrdOvrlDelivFlfmtSts    on $projection.SalesOrdOvrlDelivFlfmtSts         =    _SalesOrdOvrlDelivFlfmtSts.SalesOrdOvrlDelivFlfmtSts        
 association [0..1] to I_SalesOrdOvrlInvcgFlfmtSts  as _SalesOrdOvrlInvcgFlfmtSts    on $projection.SalesOrdOvrlInvcgFlfmtSts         =    _SalesOrdOvrlInvcgFlfmtSts.SalesOrdOvrlInvcgFlfmtSts   
 association [0..1] to I_SalesDocFulfillmentStatus  as _SalesDocFulfillmentStatus    on $projection.SalesDocFulfillmentStatus         =    _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus                                          
 association [0..1] to I_OutbDelivFulfillmentStatus as _OutbDelivFulfillmentStatus   on $projection.OutbDelivFulfillmentStatus        =   _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus    
 association [0..1] to I_AccountingTransferStatus   as _AccountingTransferStatus     on $projection.AccountingTransferStatus          =     _AccountingTransferStatus.AccountingTransferStatus
 
{
  //key

  key SalesDocument,  
  key L1SubsequentDoc                                             as HierarchyNode, 
  key cast( 2                     as int2 )                       as HierarchyNodeLevel,  --Lvl 1 Subsequent maps to ProcessFlowLevel '00' maps to Tree HierarchyNodeLevel 2   
  key SalesDocument                                               as ParentNode,
  key cast(
           case
             when L1SubsequentDocCat = 'V'  then 'PDOC'  // Purchase Order

             when L1SubsequentDocCat = '10' then 'MDOC'  // Manufacturing Order

             when L1SubsequentDocCat = '40' then 'MDOC'  // Manufacturing Order

            else  ''
            end
                                  as sls_ord_flfllmnt_node_type ) as NodeType,  
  key L1SubsequentDocCat                                          as DocumentCategory,
  
  //Organization

  SalesOrganization,
  DistributionChannel,
  OrganizationDivision,
  
  //Category

  @ObjectModel.foreignKey.association: '_RootNodeDocumentSalesDocType'
  cast( SupLvl1.SalesDocumentType as auart )                      as RootNodeDocumentSalesDocType, 
  cast( ''                        as auart )                      as SalesDocumentType, 
    
  //Sales

  @DefaultAggregation: #NONE
  @Semantics.amount.currencyCode: 'TransactionCurrency'
  cast ( 0                        as netwr_ak )                   as TotalNetAmount,
  @Semantics.currencyCode: true
  @ObjectModel.foreignKey.association: '_TransactionCurrency'
  cast ( ''                       as waerk )                      as TransactionCurrency, 
     
  //Subsequent Category

  cast( ''                        as lfart )                      as DeliveryDocumentType,
  cast( ''                        as fkart )                      as BillingDocumentType, 
  PurchaseOrderType,
  ManufacturingOrderType,  
   
  //Supply Level 1 'Pseudo Overall SD Process Status' 

  @ObjectModel.foreignKey.association: '_OverallSDProcessStatus'
  cast( 
   case when L1SubsequentDocCat = 'V'                                    // Purchase Order

         then case when L1OverallSDProcessStatus = 'C'                       
                    then L1OverallSDProcessStatus
                  else case when (SlsOrdReltdPurProcFlfmtSts = 'B' 
                              or  SlsOrdReltdPurProcFlfmtSts = 'J')
                             then 'B'                     
                           else 'A'
                        end
               end      
        when L1SubsequentDocCat = '10' then SlsOrdReltdMfgProcFlfmtSts  // Manufacturing Order

        when L1SubsequentDocCat = '40' then SlsOrdReltdMfgProcFlfmtSts  // Manufacturing Order

       else  ''
    end                           as gbstk )                      as OverallSDProcessStatus,    
   
  //Sales Order Overall Delivery Fulfillment and Overall Invoicing Fulfillment Status

  cast( ''                        as salesordovrldelivflfmtsts )  as SalesOrdOvrlDelivFlfmtSts,
 
  cast( ''                        as salesordovrlinvcgflfmtsts )  as SalesOrdOvrlInvcgFlfmtSts, 
    
  //Sales Document Fulfillment Status 

  cast( ''                        as salesdocfulfillmentstatus )  as SalesDocFulfillmentStatus, 
  
  //Outbound Delivery Fulfillment Status

  cast( ''                        as outbdelivfulfillmentstatus ) as OutbDelivFulfillmentStatus, 
    
  //Accounting Transfer Status

  cast( ''                        as rfbsk )                      as AccountingTransferStatus,  
   
  //Purchasing Document Status

  PurchasingDocumentStatus,  
   
  //Sales Order Related Purchase Process Fulfillment Status

  SlsOrdReltdPurProcFlfmtSts,
  
  //Sales Order Related Manfacturing Process Fulfillment Status

  SlsOrdReltdMfgProcFlfmtSts,
  
  //Associations

  _SalesOrganization,
  _DistributionChannel,
  _OrganizationDivision,
  
  _RootNodeDocumentSalesDocType,
  _SalesDocumentType,
  
  _TransactionCurrency,
  
  _DeliveryDocumentType,
  _BillingDocumentType,
  _PurchaseOrderType,
  _MfgOrderType,
    
  _OverallSDProcessStatus,
  _SalesOrdOvrlDelivFlfmtSts,
  _SalesOrdOvrlInvcgFlfmtSts,
  _SalesDocFulfillmentStatus,
  _OutbDelivFulfillmentStatus,
  _AccountingTransferStatus,
  _PurchasingDocumentStatus,
  _SlsOrdReltdPurProcFlfmtSts,
  _SlsOrdReltdMfgProcFlfmtSts  
}           
  
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
  // Nodes for Sales and Distribution Processes Level 2 

union all
 select from           P_SlsOrdFlfmt2ndLvlSDProcSqnc1 as Lvl2 

 association [0..1] to I_Currency                     as _TransactionCurrency          on $projection.TransactionCurrency               =          _TransactionCurrency.Currency                  
 association [0..1] to I_SalesDocumentType            as _RootNodeDocumentSalesDocType on $projection.RootNodeDocumentSalesDocType      = _RootNodeDocumentSalesDocType.SalesDocumentType
 association [0..1] to I_SalesDocumentType            as _SalesDocumentType            on $projection.SalesDocumentType                 =            _SalesDocumentType.SalesDocumentType
 association [0..1] to I_DeliveryDocumentType         as _DeliveryDocumentType         on $projection.DeliveryDocumentType              =         _DeliveryDocumentType.DeliveryDocumentType            
 association [0..1] to I_BillingDocumentType          as _BillingDocumentType          on $projection.BillingDocumentType               =          _BillingDocumentType.BillingDocumentType
 association [0..1] to I_PurchasingDocumentType       as _PurchaseOrderType            on _PurchaseOrderType.PurchasingDocumentCategory =                             'F'
                                                                                    and $projection.PurchaseOrderType                 =            _PurchaseOrderType.PurchasingDocumentType       
 association [0..1] to I_MfgOrderType                 as _MfgOrderType                 on $projection.ManufacturingOrderType            =                 _MfgOrderType.ManufacturingOrderType
 association [0..1] to I_OverallSDProcessStatus       as _OverallSDProcessStatus       on $projection.OverallSDProcessStatus            =       _OverallSDProcessStatus.OverallSDProcessStatus        
 association [0..1] to I_SalesOrdOvrlDelivFlfmtSts    as _SalesOrdOvrlDelivFlfmtSts    on $projection.SalesOrdOvrlDelivFlfmtSts         =    _SalesOrdOvrlDelivFlfmtSts.SalesOrdOvrlDelivFlfmtSts        
 association [0..1] to I_SalesOrdOvrlInvcgFlfmtSts    as _SalesOrdOvrlInvcgFlfmtSts    on $projection.SalesOrdOvrlInvcgFlfmtSts         =    _SalesOrdOvrlInvcgFlfmtSts.SalesOrdOvrlInvcgFlfmtSts  

 association [0..1] to I_SalesDocFulfillmentStatus    as _SalesDocFulfillmentStatus    on $projection.SalesDocFulfillmentStatus         =    _SalesDocFulfillmentStatus.SalesDocFulfillmentStatus                                          
 association [0..1] to I_OutbDelivFulfillmentStatus   as _OutbDelivFulfillmentStatus   on $projection.OutbDelivFulfillmentStatus        =   _OutbDelivFulfillmentStatus.OutbDelivFulfillmentStatus    
 association [0..1] to I_AccountingTransferStatus     as _AccountingTransferStatus     on $projection.AccountingTransferStatus          =     _AccountingTransferStatus.AccountingTransferStatus
 association [0..1] to I_PurchasingDocumentStatus     as _PurchasingDocumentStatus     on $projection.PurchasingDocumentStatus          =     _PurchasingDocumentStatus.PurchasingDocumentStatus  
 association [0..1] to I_SlsOrdReltdPurProcFlfmtSts   as _SlsOrdReltdPurProcFlfmtSts   on $projection.SlsOrdReltdPurProcFlfmtSts        =   _SlsOrdReltdPurProcFlfmtSts.SlsOrdReltdPurProcFlfmtSts
 association [0..1] to I_SlsOrdReltdMfgProcFlfmtSts   as _SlsOrdReltdMfgProcFlfmtSts   on $projection.SlsOrdReltdMfgProcFlfmtSts        =   _SlsOrdReltdMfgProcFlfmtSts.SlsOrdReltdMfgProcFlfmtSts
                    
{
  //key 

  key SalesDocument,
  key L2SubsequentDoc                                             as HierarchyNode, 
  key cast( 3                     as int2 )                       as HierarchyNodeLevel,  --L2Subsequent maps to ProcessFlowLevel '01' maps to Tree HierarchyNodeLevel 3
  key L1SubsequentDoc                                             as ParentNode,    
  key cast(
           case
            when L2SubsequentDocCat = 'M'  then 'BDOC'  // Invoice

            when L2SubsequentDocCat = 'O'  then 'BDOC'  // Credit memo

            when L2SubsequentDocCat = 'P'  then 'BDOC'  // Debit memo

            when L2SubsequentDocCat = 'U'  then 'BDOC'  // Pro forma invoice

           else  ''
            end                   as sls_ord_flfllmnt_node_type ) as NodeType,
  key L2SubsequentDocCat                                          as DocumentCategory,
  
  //Organization

  SalesOrganization,
  DistributionChannel,
  OrganizationDivision,
  
  //Category

  @ObjectModel.foreignKey.association: '_RootNodeDocumentSalesDocType'
  cast( Lvl2.SalesDocumentType    as auart )                      as RootNodeDocumentSalesDocType, 
  cast( ''                        as auart )                      as SalesDocumentType,
    
  //Sales

   @DefaultAggregation: #NONE
   @Semantics.amount.currencyCode: 'TransactionCurrency'
   cast( 0                        as netwr_ak )                   as TotalNetAmount,  
     
   @Semantics.currencyCode: true
   @ObjectModel.foreignKey.association: '_TransactionCurrency'
   cast( ''                       as waerk )                      as TransactionCurrency,  
     
  //Subsequent Category

  cast( ''                        as lfart )                      as DeliveryDocumentType,
    
  @ObjectModel.foreignKey.association: '_BillingDocumentType'
  cast(Lvl2.L2BillingDocumentType as fkart )                      as BillingDocumentType,  
    
  cast( ''                        as esart )                      as PurchaseOrderType,
   
  cast( ''                        as manufacturingordertype )     as ManufacturingOrderType,  
  
  //Status 

  @ObjectModel.foreignKey.association: '_OverallSDProcessStatus'
  Lvl2.L2OverallSDProcessStatus                                   as OverallSDProcessStatus,   
  
  //Sales Order Overall Delivery Fulfillment and Overall Invoicing Fulfillment Status

  cast( ''                        as salesordovrldelivflfmtsts )  as SalesOrdOvrlDelivFlfmtSts,
   
  cast( ''                        as salesordovrlinvcgflfmtsts )  as SalesOrdOvrlInvcgFlfmtSts,
    
  //Sales Document Fulfillment Status 

  cast( ''                        as salesdocfulfillmentstatus )  as SalesDocFulfillmentStatus,
   
  //Outbound Delivery Fulfillment Status

  cast( ''                        as outbdelivfulfillmentstatus ) as OutbDelivFulfillmentStatus,
  
  //Accounting Transfer Status

  @ObjectModel.foreignKey.association: '_AccountingTransferStatus'
  Lvl2.L2AccountingTransferStatus                                 as AccountingTransferStatus,  
   
  //Purchasing Document Status

  @ObjectModel.foreignKey.association: '_PurchasingDocumentStatus'
  cast( ''                        as mmpur_doc_status)            as PurchasingDocumentStatus,   
   
  //Sales Order Related Purchase Process Fulfillment Status

  cast( ''                        as slsordreltdpurprocflfmtsts ) as SlsOrdReltdPurProcFlfmtSts,
    
  //Sales Order Related Manfacturing Process Fulfillment Status

  cast( ''                        as slsordreltdmfgprocflfmtsts ) as SlsOrdReltdMfgProcFlfmtSts,
     
  //Associations

  _SalesOrganization,
  _DistributionChannel,
  _OrganizationDivision,
  
  _RootNodeDocumentSalesDocType,
  _SalesDocumentType,
  
  _TransactionCurrency,
  
  _DeliveryDocumentType,
  _BillingDocumentType,
  _PurchaseOrderType,
  _MfgOrderType,
    
  _OverallSDProcessStatus,  
  _SalesOrdOvrlDelivFlfmtSts,
  _SalesOrdOvrlInvcgFlfmtSts,
  _SalesDocFulfillmentStatus,
  _OutbDelivFulfillmentStatus,
  _AccountingTransferStatus,
  _PurchasingDocumentStatus,
  _SlsOrdReltdPurProcFlfmtSts,
  _SlsOrdReltdMfgProcFlfmtSts    
}
where (L2SubsequentDocCat = 'M'  // Invoice

   or  L2SubsequentDocCat = 'O'  // Credit memo

   or  L2SubsequentDocCat = 'P'  // Debit memo

   or  L2SubsequentDocCat = 'U'  // Pro forma invoice

       ) and Lvl2.L2BillgDocIsCancelled  != 'X'