P_RO_SAFTInvoiceItemCount

DDL: P_RO_SAFTINVOICEITEMCOUNT SQL: PROSAFTINVITMCNT Type: view CONSUMPTION

P_RO_SAFTInvoiceItemCount is a Consumption CDS View in SAP S/4HANA. It reads from 2 data sources (I_CompanyCode, P_RO_SAFTOplAcctgDocItmExc) and exposes 4 fields with key fields CompanyCode, FiscalYear, AccountingDocument.

Data Sources (2)

SourceAliasJoin Type
I_CompanyCode CompanyCode inner
P_RO_SAFTOplAcctgDocItmExc P_RO_SAFTOplAcctgDocItmExc from

Parameters (1)

NameTypeDefault
P_AlternativeGLAccountIsUsed saft_ro_alt_gl_account_flag

Annotations (10)

NameValueLevelField
AbapCatalog.sqlViewName PROSAFTINVITMCNT view
AbapCatalog.compiler.compareFilter true view
AbapCatalog.preserveKey true view
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.viewType #CONSUMPTION view
VDM.private true view
ObjectModel.usageType.sizeCategory #XL view
ObjectModel.usageType.serviceQuality #A view
ObjectModel.usageType.dataClass #TRANSACTIONAL view
ClientHandling.algorithm #SESSION_VARIABLE view

Fields (4)

KeyFieldSource TableSource FieldDescription
KEY CompanyCode Bseg CompanyCode
KEY FiscalYear Bseg FiscalYear
KEY AccountingDocument Bseg AccountingDocument
InvoiceItemCount
@AbapCatalog.sqlViewName: 'PROSAFTINVITMCNT'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@VDM.viewType: #CONSUMPTION
@VDM.private:true
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.serviceQuality: #A
@ObjectModel.usageType.dataClass: #TRANSACTIONAL
@ClientHandling.algorithm: #SESSION_VARIABLE

// This view lists documents that have at least one line item which is not a tax line item nor customer/supplier line item.


define view P_RO_SAFTInvoiceItemCount
  with parameters
    P_AlternativeGLAccountIsUsed : saft_ro_alt_gl_account_flag

  as select from           P_RO_SAFTOplAcctgDocItmExc(P_AlternativeGLAccountIsUsed: $parameters.P_AlternativeGLAccountIsUsed) as Bseg

    inner join             I_CompanyCode                                                                                      as CompanyCode        on CompanyCode.CompanyCode = Bseg.CompanyCode

    left outer to one join I_RO_SAFTSpecialGLIndicator                                                                        as SpecialGLIndicator on  Bseg.CompanyCode          = SpecialGLIndicator.CompanyCode
                                                                                                                                                    and Bseg.FinancialAccountType = SpecialGLIndicator.AccountType
                                                                                                                                                    and Bseg.SpecialGLCode        = SpecialGLIndicator.SpecialGLCode
    left outer to one join P_RO_SAFTNonROTaxCode                                                                              as TaxCountry         on  TaxCountry.CompanyCodeCountry       =  CompanyCode.Country
                                                                                                                                                    and TaxCountry.TargetTaxCode            =  Bseg.TaxCode
                                                                                                                                                    and TaxCountry.TaxRateValidityEndDate   >= Bseg.PostingDate
                                                                                                                                                    and TaxCountry.TaxRateValidityStartDate <= Bseg.PostingDate

{
  key Bseg.CompanyCode,
  key Bseg.FiscalYear,
  key Bseg.AccountingDocument,
      count( distinct Bseg.AccountingDocumentItem ) as InvoiceItemCount
}
/**
  The same WHERE condition is used in C_RO_SAFTSalesInvoiceItemC and C_RO_SAFTPurInvoiceItemC.
  If you adjust it here keep in mind to update in other places as well.
**/
where
  // exclude customer vendor lines

  (
       Bseg.FinancialAccountType       <> 'D'
    or Bseg.SpecialGLCode              =  SpecialGLIndicator.SpecialGLCode
  )
  and(
       Bseg.FinancialAccountType       <> 'K'
    or Bseg.SpecialGLCode              =  SpecialGLIndicator.SpecialGLCode
  )
  and
  // exclude VAT lines

       Bseg.AccountingDocumentItemType <> 'T'
  //exclude non RO tax return countries

  and TaxCountry.CompanyCodeCountry is null
group by
  Bseg.CompanyCode,
  Bseg.FiscalYear,
  Bseg.AccountingDocument
having
  count( distinct Bseg.AccountingDocumentItem ) > 0
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_COMPANYCODE",
"I_RO_SAFTSPECIALGLINDICATOR",
"P_RO_SAFTNONROTAXCODE",
"P_RO_SAFTOPLACCTGDOCITMEXC"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/