Derived SQL interpretation, reconstructed from the parsed view metadata (data sources, associations, and field mappings). SAP annotations are omitted and the structure is reformulated as SQL — this is a functional approximation, not the verbatim SAP source.
-- Derived SQL interpretation of CDS view P_PL_SAFTTaxItemBasic.
-- Reconstructed from parsed metadata (data sources, associations, fields).
-- SAP annotations are omitted and the structure is reformulated as SQL;
-- this is a functional approximation, not the verbatim SAP source. Some join
-- conditions may be unavailable and a few CDS constructs are kept as-is.
-- SQL view name: PPLSAFTTAXITMBSC
CREATE VIEW P_PL_SAFTTaxItemBasic AS
SELECT
TaxItemAgg.TaxType AS TaxType,
TaxItemAgg.CompanyCode AS CompanyCode,
TaxItemAgg.AccountingDocument AS AccountingDocument,
TaxItemAgg.FiscalYear AS FiscalYear,
TaxItemAgg.PL_SAFTTaxAmountBox AS PL_SAFTTaxAmountBox,
TaxItemAgg.PL_SAFTBaseAmountBoxMultiple AS PL_SAFTBaseAmountBoxMultiple,
TaxItemAgg.PL_SAFTDocumentType AS PL_SAFTDocumentType,
TaxItemAgg.PL_SAFTTaxItemHasMarginAmount AS PL_SAFTTaxItemHasMarginAmount,
TaxItemAgg.PL_SAFTAddlClassification AS PL_SAFTAddlClassification,
TaxItemAgg.PL_SAFTInvcExclRsnFromTotals AS PL_SAFTInvcExclRsnFromTotals,
TaxItemAgg.TaxReportingDate AS TaxReportingDate,
TaxItemAgg.TaxReturnCountry AS TaxReturnCountry,
TaxItemAgg.TaxCalculationProcedure AS TaxCalculationProcedure,
TaxItemAgg.Customer AS Customer,
TaxItemAgg.Supplier AS Supplier,
TaxItemAgg.ReferenceDocumentType AS ReferenceDocumentType,
TaxItemAgg.OriginalReferenceDocument AS OriginalReferenceDocument,
TaxItemAgg.DocumentItemText AS DocumentItemText,
case substring(_DocItemVat.VATRegistration,1,1) when '1' then _DocItemVat.SupplyingCountry when '2' then _DocItemVat.SupplyingCountry when '3' then _DocItemVat.SupplyingCountry when '4' then _DocItemVat.SupplyingCountry when '5' then _DocItemVat.SupplyingCountry when '6' then _DocItemVat.SupplyingCountry when '7' then _DocItemVat.SupplyingCountry when '8' then _DocItemVat.SupplyingCountry when '9' then _DocItemVat.SupplyingCountry when '0' then _DocItemVat.SupplyingCountry else case when _DocItemVat.VATRegistration <> '' and _DocItemVat.VatCountry <> 'UN' then substring(_DocItemVat.VATRegistration,1,2) when TaxItemAgg.BusinessPartnerCountry = 'GR' then 'EL' when _DocItemVat.VatCountry = 'UN' then 'BY' when TaxItemAgg.VATRegistration <> '' then TaxItemAgg.BusinessPartnerCountry else _SAFTBPTaxNumber.Country end end as BusinessPartnerCountry AS CountryendendasBusinessPartnerCountry,
case substring(_DocItemVat.VATRegistration,1,1) when '1' then _DocItemVat.VATRegistration when '2' then _DocItemVat.VATRegistration when '3' then _DocItemVat.VATRegistration when '4' then _DocItemVat.VATRegistration when '5' then _DocItemVat.VATRegistration when '6' then _DocItemVat.VATRegistration when '7' then _DocItemVat.VATRegistration when '8' then _DocItemVat.VATRegistration when '9' then _DocItemVat.VATRegistration when '0' then _DocItemVat.VATRegistration else case when _DocItemVat.VatCountry = 'EL' then substring(_DocItemVat.VATRegistration,3,18) when _DocItemVat.VATRegistration <> '' and TaxItemAgg.VATCountry <> 'UN' then substring(_DocItemVat.VATRegistration,3,18) when _DocItemVat.VATRegistration <> '' then _DocItemVat.VATRegistration else case substring(TaxItemAgg.VATRegistration,1,1) when '1' then TaxItemAgg.VATRegistration when '2' then TaxItemAgg.VATRegistration when '3' then TaxItemAgg.VATRegistration when '4' then TaxItemAgg.VATRegistration when '5' then TaxItemAgg.VATRegistration when '6' then TaxItemAgg.VATRegistration when '7' then TaxItemAgg.VATRegistration when '8' then TaxItemAgg.VATRegistration when '9' then TaxItemAgg.VATRegistration when '0' then TaxItemAgg.VATRegistration else case when TaxItemAgg.VATCountry = 'EL' then substring(TaxItemAgg.VATRegistration,3,18) when TaxItemAgg.VATRegistration <> '' and TaxItemAgg.VATCountry = _Country.Country then substring(TaxItemAgg.VATRegistration,3,18) else _SAFTBPTaxNumber.BPTaxNumber end end end end as VATRegistration AS BPTaxNumberendendendendasVATRegistration,
TaxItemAgg.BusinessPartnerName AS BusinessPartnerName,
TaxItemAgg.CustomerSupplierAddress AS CustomerSupplierAddress,
TaxItemAgg.DocumentReferenceID AS DocumentReferenceID,
TaxItemAgg.DocumentDate AS DocumentDate,
TaxItemAgg.CompanyCodeCurrency AS CompanyCodeCurrency,
TaxItemAgg.TaxAmountInCoCodeCrcy AS TaxAmountInCoCodeCrcy,
TaxItemAgg.TaxBaseAmountInCoCodeCrcy AS TaxBaseAmountInCoCodeCrcy,
TaxItemAgg.DocumentCurrency AS DocumentCurrency,
TaxItemAgg.TaxBaseAmountInCountryCrcy AS TaxBaseAmountInCountryCrcy,
TaxItemAgg.TaxAmountInCountryCrcy AS TaxAmountInCountryCrcy
FROM P_PL_SAFTTaxItemAgg AS TaxItemAgg
LEFT OUTER JOIN P_PL_SAFTDocItemVat AS _DocItemVat ON TaxItemAgg.TaxType = _DocItemVat.TaxType AND TaxItemAgg.CompanyCode = _DocItemVat.CompanyCode AND TaxItemAgg.AccountingDocument = _DocItemVat.AccountingDocument AND TaxItemAgg.FiscalYear = _DocItemVat.FiscalYear -- association [0..1]
LEFT OUTER JOIN P_PL_SAFTBPTaxNumber AS _SAFTBPTaxNumber ON TaxItemAgg.TaxType = _SAFTBPTaxNumber.TaxType AND TaxItemAgg.CompanyCode = _SAFTBPTaxNumber.CompanyCode AND TaxItemAgg.AccountingDocument = _SAFTBPTaxNumber.AccountingDocument AND TaxItemAgg.FiscalYear = _SAFTBPTaxNumber.FiscalYear -- association [0..1]
;