P_RO_SAFTPurInvItem

DDL: P_RO_SAFTPURINVITEM SQL: PROSAFTPURINVI Type: view CONSUMPTION

P_RO_SAFTPurInvItem is a Consumption CDS View in SAP S/4HANA. It reads from 5 data sources (I_AccountingDocument, I_CompanyCode, I_RO_SAFTDocumentTypeMap, I_StRpJournalEntryHeaderLog, P_RO_SAFTOplAcctgDocItmExc) and exposes 28 fields with key fields StatryRptCategory, StatryRptgEntity, StatryRptRunID, CompanyCode, FiscalYear.

Data Sources (5)

SourceAliasJoin Type
I_AccountingDocument Bkpf inner
I_CompanyCode CompanyCode inner
I_RO_SAFTDocumentTypeMap DocType inner
I_StRpJournalEntryHeaderLog Log from
P_RO_SAFTOplAcctgDocItmExc P_RO_SAFTOplAcctgDocItmExc inner

Parameters (1)

NameTypeDefault
P_AlternativeGLAccountIsUsed saft_ro_alt_gl_account_flag

Annotations (11)

NameValueLevelField
AbapCatalog.sqlViewName PROSAFTPURINVI view
AbapCatalog.compiler.compareFilter true view
AbapCatalog.preserveKey true view
VDM.viewType #CONSUMPTION view
VDM.private true view
ObjectModel.usageType.serviceQuality #X view
ObjectModel.usageType.sizeCategory #XL view
ObjectModel.usageType.dataClass #MIXED view
ClientHandling.algorithm #SESSION_VARIABLE view
AccessControl.personalData.blocking #NOT_REQUIRED view
AccessControl.authorizationCheck #NOT_REQUIRED view

Fields (28)

KeyFieldSource TableSource FieldDescription
KEY StatryRptCategory I_StRpJournalEntryHeaderLog StatryRptCategory
KEY StatryRptgEntity I_StRpJournalEntryHeaderLog StatryRptgEntity
KEY StatryRptRunID I_StRpJournalEntryHeaderLog StatryRptRunID
KEY CompanyCode Bseg CompanyCode
KEY FiscalYear Bseg FiscalYear
KEY AccountingDocument Bseg AccountingDocument
KEY AccountingDocumentItem Bseg AccountingDocumentItem
AccountingDocumentType Bseg AccountingDocumentType
Product Bseg Product
BaseUnit Bseg BaseUnit
TransactionTypeDetermination Bseg TransactionTypeDetermination
PostingDate Bseg PostingDate
CompanyCodeCurrency Bseg CompanyCodeCurrency
TransactionCurrency Bseg TransactionCurrency
IsNegativePosting Bseg IsNegativePosting
RO_SAFTGoodsService GoodsService RO_SAFTGoodsService
ProductDescription ProductText ProductName
SourceUnitOfMeasureFactor UoM SourceUnitOfMeasureFactor
ConversionFactor 0
TaxReportingDateendasTaxReportingDate
QuantityendasQuantity
ChartOfAccounts Bseg ChartOfAccounts
GLAccount Bseg GLAccount
CountryChartOfAccounts Bseg CountryChartOfAccounts
AlternativeGLAccount Bseg AlternativeGLAccount
ActiveChartOfAccounts Bseg ActiveChartOfAccounts
ActiveGLAccount Bseg ActiveGLAccount
RO_SAFTStandardAccount
@AbapCatalog.sqlViewName: 'PROSAFTPURINVI'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@VDM.viewType: #CONSUMPTION
@VDM.private:true
@ObjectModel.usageType.serviceQuality: #X
@ObjectModel.usageType.sizeCategory: #XL
@ObjectModel.usageType.dataClass: #MIXED
@ClientHandling.algorithm: #SESSION_VARIABLE
@AccessControl.personalData.blocking: #NOT_REQUIRED
@AccessControl.authorizationCheck: #NOT_REQUIRED
define view P_RO_SAFTPurInvItem
  with parameters

    P_AlternativeGLAccountIsUsed : saft_ro_alt_gl_account_flag

  as select from           I_StRpJournalEntryHeaderLog                                                                        as Log

    inner join             I_AccountingDocument                                                                               as Bkpf               on  Bkpf.AccountingDocument = Log.AccountingDocument
                                                                                                                                                    and Bkpf.CompanyCode        = Log.CompanyCode
                                                                                                                                                    and Bkpf.FiscalYear         = Log.FiscalYear

    inner join             I_RO_SAFTDocumentTypeMap                                                                           as DocType            on  DocType.AccountingDocumentType = Bkpf.AccountingDocumentType
                                                                                                                                                    and DocType.CompanyCode            = Log.CompanyCode

    inner join             P_RO_SAFTOplAcctgDocItmExc(P_AlternativeGLAccountIsUsed: $parameters.P_AlternativeGLAccountIsUsed) as Bseg               on  Bseg.AccountingDocument = Log.AccountingDocument
                                                                                                                                                    and Bseg.CompanyCode        = Log.CompanyCode
                                                                                                                                                    and Bseg.FiscalYear         = Log.FiscalYear
    inner join             I_CompanyCode                                                                                      as CompanyCode        on CompanyCode.CompanyCode = Bkpf.CompanyCode

    left outer to one join I_Product                                                                                          as Product            on Product.Product = Bseg.Product

    left outer to one join I_RO_SAFTGoodsService                                                                              as GoodsService       on Product.ProductType = GoodsService.MaterialType

    left outer to one join I_RO_SAFTUnitOfMeasureMap                                                                          as UoM                on Bseg.BaseUnit = UoM.SourceUnitOfMeasure

    left outer to one join I_ProductText                                                                                      as ProductText        on  Bseg.Product         = ProductText.Product
                                                                                                                                                    and ProductText.Language = '4'

    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 I_RO_SAFTAccountMapping                                                                            as Account            on  Account.ChartOfAccounts = Bseg.ActiveChartOfAccounts
                                                                                                                                                    and Account.GLAccount       = Bseg.ActiveGLAccount
    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 Log.StatryRptCategory,
  key Log.StatryRptgEntity,
  key Log.StatryRptRunID,
  key Bseg.CompanyCode,
  key Bseg.FiscalYear,
  key Bseg.AccountingDocument,
  key Bseg.AccountingDocumentItem,
      Bseg.AccountingDocumentType,
      Bseg.Product,
      Bseg.BaseUnit,
      Bseg.TransactionTypeDetermination,
      Bseg.PostingDate,
      @Semantics.currencyCode:true
      Bseg.CompanyCodeCurrency,
      @Semantics.currencyCode:true
      Bseg.TransactionCurrency,
      Bseg.IsNegativePosting,
      GoodsService.RO_SAFTGoodsService,
      ProductText.ProductName   as ProductDescription,
      UoM.SourceUnitOfMeasureFactor,

      // Negative posting is already considered in P_BSEG_COM1 and the indicator

      // is also adjusted there accordingly thus there is no need to do it here

      case Bseg.DebitCreditCode
        when 'H' then 'C'
        else 'D'
      end                       as DebitCreditCode,

      0                         as ConversionFactor,

      @Semantics.amount.currencyCode: 'TransactionCurrency'
      case
        when Bseg.IsNegativePosting = 'X' then
          case
            when Bseg.OriginalTaxBaseAmount <> 0 then -1 * abs(Bseg.OriginalTaxBaseAmount)
            else -1 * abs(Bseg.AmountInTransactionCurrency)
          end
        else
          case
            when Bseg.OriginalTaxBaseAmount <> 0 then abs(Bseg.OriginalTaxBaseAmount)
            else abs(Bseg.AmountInTransactionCurrency)
          end
      end                       as AmountInTransactionCurrency,

      @Semantics.amount.currencyCode: 'CompanyCodeCurrency'
      case
        when Bseg.IsNegativePosting = 'X' then
          case
            when Bseg.OriglTaxBaseAmountInCoCodeCrcy <> 0 then -1 * abs(Bseg.OriglTaxBaseAmountInCoCodeCrcy)
            else -1 * abs(Bseg.AmountInCompanyCodeCurrency)
          end
        else
          case when Bseg.OriglTaxBaseAmountInCoCodeCrcy <> 0 then abs(Bseg.OriglTaxBaseAmountInCoCodeCrcy)
          else abs(Bseg.AmountInCompanyCodeCurrency)
        end
      end                       as AmountInCompanyCodeCurrency,

      @Semantics.amount.currencyCode: 'CompanyCodeCurrency'
      case
        when Bseg.Quantity <> 0
          then case when Bseg.OriglTaxBaseAmountInCoCodeCrcy <> 0 then abs(division(Bseg.OriglTaxBaseAmountInCoCodeCrcy, Bseg.Quantity, 2))
            else abs(division(Bseg.AmountInCompanyCodeCurrency, Bseg.Quantity, 2)) end
        when Account.RO_SAFTIsDefaultZeroQuantity = 'X' then 0
        else case when Bseg.OriglTaxBaseAmountInCoCodeCrcy <> 0 then abs(Bseg.OriglTaxBaseAmountInCoCodeCrcy) else abs(Bseg.AmountInCompanyCodeCurrency) end
      end                       as UnitPriceAmountInReportingCrcy,

      case
        when Bkpf.TaxReportingDate is initial then Bkpf.DocumentDate
        else Bkpf.TaxReportingDate
      end                       as TaxReportingDate,

      case
        when Bseg.DocumentItemText is not initial then Bseg.DocumentItemText
        when ProductText.ProductName is not initial then ProductText.ProductName
        else cast('NULL' as farp_sgtxt)
      end                       as DocumentItemText, // Description


      @Semantics.quantity.unitOfMeasure: 'BaseUnit'
      case
        when Bseg.Quantity = 0 then
          case Account.RO_SAFTIsDefaultZeroQuantity
            when 'X' then cast(0 as quan1_12)
            else cast(1 as quan1_12) end
        else abs(Bseg.Quantity)
      end                       as Quantity,         // Quantity


      cast(
        case
          when DocType.RO_SAFTIsExchHeaderTable = 'X' then Bkpf.ExchangeRate
          when Bseg.AmountInTransactionCurrency <> 0 then division(Bseg.AmountInCompanyCodeCurrency, Bseg.AmountInTransactionCurrency, 4)
          else 0
        end
      as saft_ro_exchange_rate) as RO_SAFTExchangeRate,
      Bseg.ChartOfAccounts,
      Bseg.GLAccount,
      Bseg.CountryChartOfAccounts,
      Bseg.AlternativeGLAccount,
      Bseg.ActiveChartOfAccounts,
      Bseg.ActiveGLAccount,
      coalesce(Account.RO_SAFTStandardAccount, Bseg.ActiveGLAccount) as RO_SAFTStandardAccount

}
/**
  The same WHERE condition is used in C_RO_SAFTSalesInvoiceItemC and P_RO_SAFTInvoiceItemCount.
  If you adjust it here keep in mind to update in other places as well.
**/
where
       DocType.RO_SAFTSourceDocumentType =  '03'
  and
  // 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 lines with non RO tax reporting country

  and TaxCountry.CompanyCodeCountry is null
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_ACCOUNTINGDOCUMENT",
"I_COMPANYCODE",
"I_PRODUCT",
"I_PRODUCTTEXT",
"I_RO_SAFTACCOUNTMAPPING",
"I_RO_SAFTDOCUMENTTYPEMAP",
"I_RO_SAFTGOODSSERVICE",
"I_RO_SAFTSPECIALGLINDICATOR",
"I_RO_SAFTUNITOFMEASUREMAP",
"I_STRPJOURNALENTRYHEADERLOG",
"P_RO_SAFTNONROTAXCODE",
"P_RO_SAFTOPLACCTGDOCITMEXC"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/