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 I_ES_StRpWhldgTaxItem.
-- 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.
CREATE VIEW I_ES_StRpWhldgTaxItem AS
SELECT
doc.CompanyCode AS CompanyCode,
doc.AccountingDocument AS AccountingDocument,
doc.FiscalYear AS FiscalYear,
doc.AccountingDocumentItem AS AccountingDocumentItem,
doc.WithholdingTaxType AS WithholdingTaxType,
doc.StatryRptgEntity AS StatryRptgEntity,
doc.StatryRptCategory AS StatryRptCategory,
doc.StatryRptRunID AS StatryRptRunID,
wthkey.ES_WhldgReportType AS ES_WhldgReportType,
doc.WithholdingTaxCode AS WithholdingTaxCode,
doc._WithholdingTaxCode.ProvincialTaxCode AS ProvincialTaxCode,
doc.Country AS Country,
doc.Creditor AS Creditor,
doc.Debtor AS Debtor,
doc.BusinessPartnerNumber AS BusinessPartnerNumber,
doc.BusinessPlace AS BusinessPlace,
doc.FinancialAccountType AS FinancialAccountType,
case when ( doc.WhldgTaxDocumentType = '002' or doc.WhldgTaxDocumentType = '007' or doc.WhldgTaxDocumentType = '018' or doc.WhldgTaxDocumentType = '021' ) and doc.WhldgTaxRptgDateIsActive = 'X' and doc.WithholdingTaxReportingDate = '99991230' then doc.ClearingDate when ( doc.WhldgTaxDocumentType = '002' or doc.WhldgTaxDocumentType = '007' or doc.WhldgTaxDocumentType = '018' or doc.WhldgTaxDocumentType = '021' ) and doc.WhldgTaxRptgDateIsActive = 'X' and doc.WithholdingTaxReportingDate <> '99991230' then doc.WithholdingTaxReportingDate when ( doc.WhldgTaxDocumentType = '002' or doc.WhldgTaxDocumentType = '007' or doc.WhldgTaxDocumentType = '018' or doc.WhldgTaxDocumentType = '021' ) and ( doc.WhldgTaxRptgDateIsActive = '' or doc.WhldgTaxRptgDateIsActive is null ) then doc.ClearingDate when ( doc.WhldgTaxDocumentType = '005' or doc.WhldgTaxDocumentType = '010' or doc.WhldgTaxDocumentType = '006' or doc.WhldgTaxDocumentType = '019' ) then doc.PostingDate when ( doc.WhldgTaxDocumentType = '001' or doc.WhldgTaxDocumentType = '003' or doc.WhldgTaxDocumentType = '017' or doc.WhldgTaxDocumentType = '020' ) then doc.PostingDate else doc.ClearingDate end as PostingDate AS ClearingDateendasPostingDate,
doc.DocumentDate AS DocumentDate,
doc.SupplierRecipientType AS SupplierRecipientType,
doc.ClearingDate AS ClearingDate,
doc.ClearingAccountingDocument AS ClearingAccountingDocument,
wthkey.WhldgTaxReferenceText AS WhldgTaxReferenceText,
right( wthkey.WhldgTaxReferenceText, 2) AS EsIncTypeClassfctn,
doc.ReportingDate AS ReportingDate,
doc.ReportingCurrency AS ReportingCurrency,
doc.WhldgTaxExmptAmtInCoCodeCrcy AS WhldgTaxExmptAmtInCoCodeCrcy,
doc.WhldgTaxExmptAmtInTransacCrcy AS WhldgTaxExmptAmtInTransacCrcy,
doc.IsReversed AS IsReversed,
doc.IsReversal AS IsReversal,
doc.WhldgTaxBaseAmtInCoCodeCrcy AS WhldgTaxBaseAmtInCoCodeCrcy,
doc.WhldgTaxAmtInCoCodeCrcy AS WhldgTaxAmtInCoCodeCrcy,
doc.WithholdingTaxPercent AS WithholdingTaxPercent,
doc.ItemIsReportingRelevant AS ItemIsReportingRelevant,
cast( case doc.WhldgTaxDocumentType when '001' then '0' when '003' then '0' when '017' then '0' else '2' end as abap.char( 1 ) ) as OpenInvoiceSelection AS char1asOpenInvoiceSelection,
doc.WhldgTaxDocumentType AS WhldgTaxDocumentType,
doc._Supplier.AuthorizationGroup AS AuthorizationGroup,
doc._Supplier.SupplierAccountGroup AS SupplierAccountGroup,
doc._Supplier.Supplier AS Supplier,
doc._Supplier._SupplierToBusinessPartner._BusinessPartner.BusinessPartner AS BusinessPartner,
coalesce( doc._Onetime.CityName, doc.CityName ) AS CustomerSupplierCityName,
case when doc._Onetime._Address._Region._RegionText[1:Language = $session.system_language].RegionName is not initial then doc._Onetime._Address._Region._RegionText[1:Language = $session.system_language].RegionName else doc._Supplier._StandardAddress._Region._RegionText[1:Language = $session.system_language].RegionName end as RegionName AS RegionNameendasRegionName,
case when doc._Onetime.Region is not initial then doc._Onetime.Region else doc._Supplier._StandardAddress.Region end as Region AS RegionendasRegion,
coalesce( doc._Onetime.PostalCode, doc._Supplier._StandardAddress.PostalCode ) AS CustomerSupplierPostalCode,
case when doc.Region is initial then substring( doc._Supplier._StandardAddress.PostalCode, 1, 2 ) else doc._Supplier._StandardAddress.Region end as PostalCode AS RegionendasPostalCode,
coalesce( doc._Onetime.Country, doc._Supplier.Country ) AS BusinessPartnerCountry,
doc.VATRegistration AS SupplierVATRegistration,
cast( doc.TaxNumber1 as stcd1 ) AS TaxNumber1,
doc.TaxNumber2 AS TaxNumber2,
doc.TaxNumber3 AS TaxNumber3,
doc.TaxNumber4 AS TaxNumber4,
doc.TaxNumber5 AS TaxNumber5,
doc._Supplier.BirthDate AS BirthDate,
doc._Supplier._SupplierToBusinessPartner._BusinessPartner.BusinessPartnerBirthplaceName AS BusinessPartnerBirthplaceName,
doc._Supplier._SupplierToBusinessPartner._BusinessPartner.NonResidentCompanyOriginCntry AS NonResidentCompanyOriginCntry,
doc._Supplier._SupplierToBusinessPartner._BusinessPartner.BusinessPartnerCategory AS BusinessPartnerCategory,
doc._Supplier.FiscalAddress AS FiscalAddress,
cast( 'S' as spras ) AS Language,
doc._Supplier.TaxNumberResponsible AS TaxNumberResponsible,
cast( substring( doc._CompanyCode.VATRegistration, 3, 11 ) as farp_stceg ) AS VATRegistration,
concat_with_space (doc._CompanyCode._Address.BusinessPartnerName1 , doc._CompanyCode._Address.BusinessPartnerName2 , 1) AS CompanyCodeName,
doc._CompanyCode._Address.CityName AS CityName,
case when ( doc.WhldgTaxDocumentType = '005' and _DownpaymentReference.InvoiceReference <> _DownpaymentReference.AccountingDocument ) then _DownpaymentReference.InvoiceReference when doc.WhldgTaxDocumentType = '010' then _DPCReference.InvoiceReference else doc.InvoiceReference end as InvoiceReference AS InvoiceReferenceendasInvoiceReference,
cast ( doc._JournalEntry.JrnlEntryCntrySpecificRef3 as fiwtes_servicerenderedregion ) AS ES_ServiceRenderedRegion,
doc._Supplier AS _Supplier,
doc._CompanyCode AS _CompanyCode,
doc._Customer AS _Customer,
doc._JournalEntry AS _JournalEntry,
doc._Onetime AS _Onetime,
doc._Branch AS _Branch,
doc.SpecialGLCode AS SpecialGLCode
FROM I_StRpWhldgTaxItem AS doc
INNER JOIN I_ES_WithholdingKey AS wthkey ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN P_ES_CreditMemoCube AS CreditMemoDoc ON doc.CompanyCode = CreditMemoDoc.CompanyCode AND doc.AccountingDocument = CreditMemoDoc.InvoiceReference AND doc.FiscalYear = CreditMemoDoc.FiscalYear AND doc.WithholdingTaxType = CreditMemoDoc.WithholdingTaxType AND doc.StatryRptgEntity = CreditMemoDoc.StatryRptgEntity AND doc.StatryRptCategory = CreditMemoDoc.StatryRptCategory AND doc.StatryRptRunID = CreditMemoDoc.StatryRptRunID -- association [0..1]
LEFT OUTER JOIN I_StRpWhldgTaxItem AS DownpaymentClearingDoc ON doc.CompanyCode = DownpaymentClearingDoc.CompanyCode AND doc.ClearingAccountingDocument = DownpaymentClearingDoc.AccountingDocument AND doc.ClearingAccountingDocument is not initial AND doc.ClearingJournalEntryFiscalYear is not initial AND doc.ClearingJournalEntryFiscalYear = DownpaymentClearingDoc.FiscalYear AND doc.WithholdingTaxType = DownpaymentClearingDoc.WithholdingTaxType AND doc.WhldgTaxDocumentType = '005' AND DownpaymentClearingDoc.WhldgTaxDocumentType = '010' AND doc.StatryRptgEntity = DownpaymentClearingDoc.StatryRptgEntity AND doc.StatryRptCategory = DownpaymentClearingDoc.StatryRptCategory AND doc.StatryRptRunID = DownpaymentClearingDoc.StatryRptRunID -- association [0..1]
LEFT OUTER JOIN I_Currency AS _ReportingCurrency ON ReportingCurrency = _ReportingCurrency.Currency -- association [0..1]
LEFT OUTER JOIN I_OperationalAcctgDocItem AS _DownpaymentReference ON CompanyCode = _DownpaymentReference.CompanyCode AND ClearingAccountingDocument = _DownpaymentReference.AccountingDocument AND doc.ClearingJournalEntryFiscalYear = _DownpaymentReference.FiscalYear AND ClearingAccountingDocument <> AccountingDocument AND _DownpaymentReference.SpecialGLCode is initial AND doc.WhldgTaxDocumentType = '005' -- association [0..1]
LEFT OUTER JOIN I_OperationalAcctgDocItem AS _DPCReference ON CompanyCode = _DPCReference.CompanyCode AND AccountingDocument = _DPCReference.AccountingDocument AND FiscalYear = _DPCReference.FiscalYear AND _DPCReference.SpecialGLCode is initial AND doc.WhldgTaxDocumentType = '010' -- association [0..1]
;