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 C_TH_StRpWhldgTaxItemCube.
-- 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 C_TH_StRpWhldgTaxItemCube 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,
doc.WithholdingTaxCode AS WithholdingTaxCode,
cast('' as abap.char(40) ) AS WhldgTaxCodeName,
doc.PostingDate AS PostingDate,
doc.DocumentDate AS DocumentDate,
doc.InvoiceReference AS InvoiceReference,
doc._CompanyCode.VATRegistration AS VATRegistration,
doc.BusinessPlace AS BusinessPlace,
case when doc._Branch.BranchLongCode is initial then lpad( doc.BusinessPlace, 5 , '0' ) else doc._Branch.BranchLongCode end as BranchLongCode AS BranchLongCodeendasBranchLongCode,
doc._Customer.Customer AS Customer,
doc._Customer.CustomerName AS CustomerName,
doc._Customer.CustomerFullName AS CustomerFullName,
doc.BusinessPartner AS BusinessPartner,
case when doc.BranchCode <> 'NVAT' and doc.BranchCode <> 'NOVAT' then doc.BranchCode end as TH_DefaultBranch AS BranchCodeendasTH_DefaultBranch,
doc._Supplier.Supplier AS Supplier,
case when doc._Onetime.AccountingDocument is null then case when bpbranchadr.AddressID is not initial then bpbranchadr.AddressID when custbranchadr.AddressID is not initial then custbranchadr.AddressID else case when doc._Supplier.AddressID is not initial then doc._Supplier.AddressID when doc._Customer.AddressID is not initial then doc._Customer.AddressID end end else '' end as AddressID AS AddressIDendendelseendasAddressID,
doc._CompanyCode.Country AS CompanyCodeCountry,
case when doc._Supplier.Supplier is not null then doc._Supplier.TaxNumber1 when doc._Customer.Customer is not null then doc._Customer.TaxNumber1 end as TaxNumber1 AS TaxNumber1endasTaxNumber1,
case when doc._Onetime.AccountingDocument is not null then case when doc._Supplier.Supplier is not null then case when doc._Supplier._SupplierToBusinessPartner._BusinessPartner.BusinessPartnerCategory = '1' then doc._Onetime.TaxID1 else doc._Onetime.TaxID3 end when doc._Customer.Customer is not null then case when doc._Customer._CustomerToBusinessPartner._BusinessPartner.BusinessPartnerCategory = '1' then doc._Onetime.TaxID1 else doc._Onetime.TaxID3 end end else case when doc._Supplier.Supplier is not null then case when doc._Supplier._SupplierToBusinessPartner._BusinessPartner.BusinessPartnerCategory = '1' then doc._Supplier.TaxNumber1 else doc._Supplier.TaxNumber3 end when doc._Customer.Customer is not null then case when doc._Customer._CustomerToBusinessPartner._BusinessPartner.BusinessPartnerCategory = '1' then doc._Customer.TaxNumber1 else doc._Customer.TaxNumber3 end end end as TaxNumber3 AS TaxNumber3endendendasTaxNumber3,
doc._Supplier.SupplierFullName AS SupplierFullName,
cast('' as char40) AS MiddleName,
cast('' as char50) AS CountryName,
case when doc._Onetime.AccountingDocument is null then cast('' as char40) else doc._Onetime.CityName end as CityName AS CityNameendasCityName,
case when doc._Onetime.AccountingDocument is null then cast('' as char3) else doc._Onetime.Country end as Country AS CountryendasCountry,
case when doc._Onetime.AccountingDocument is null then cast('' as ad_street) else doc._Onetime.StreetAddressName end as StreetName AS StreetAddressNameendasStreetName,
case when doc._Onetime.AccountingDocument is null then cast('' as ad_pstcd1) else doc._Onetime.PostalCode end as PostalCode AS PostalCodeendasPostalCode,
case when doc._Onetime.AccountingDocument is null then cast('' as ad_namtext) else concat_with_space(doc._Onetime.StreetAddressName, concat_with_space(doc._Onetime.CityName, doc._Onetime.PostalCode, 1), 1) end as FullName AS PostalCode11endasFullName,
$session.system_language AS Language,
case when ( _TaxType.wt_postm = '1') then doc.PostingDate when ( _TaxType.wt_postm = '2' and wht.ClearingDate is not initial) then wht.ClearingDate else doc.PostingDate end as ClearingDate AS PostingDateendasClearingDate,
doc._WithholdingTaxCode.WithholdingTaxIncomeType AS WithholdingTaxIncomeType,
wht.CustomerSupplierAccount AS CustomerSupplierAccount,
cast(doc._WithholdingTaxCode.WithholdingTaxPercent as qsatz ) AS WithholdingTaxPercent,
cast(doc._WithholdingTaxCode.WhldgTaxRelevantPercent as qproz) AS WhldgTaxRelevantPercent,
doc._CompanyCode.Currency AS CompanyCodeCurrency,
( wht.WhldgTaxBaseAmtInTransacCrcy ) AS WhldgTaxBaseAmtInTransacCrcy,
( wht.WhldgTaxAmtInTransacCrcy ) AS WhldgTaxAmtInTransacCrcy,
doc.TransactionCurrency AS TransactionCurrency,
wht.DocumentCurrency AS DocumentCurrency,
wht._WithholdingTaxCode.WithholdingTaxPostingRule AS WithholdingTaxPostingRule,
wht.SupplierRecipientType AS SupplierRecipientType,
wht.WithholdingTaxCertificate AS WithholdingTaxCertificate,
doc.WhldgTaxDocumentType AS WhldgTaxDocumentType,
doc.DocumentReferenceID AS DocumentReferenceID,
wht._WithholdingTaxCode.OfficialWhldgTaxCode AS OfficialWhldgTaxCode,
doc.FinancialAccountType AS FinancialAccountType,
doc.IsReversal AS IsReversal,
doc.IsReversed AS IsReversed,
doc.ItemIsReportingRelevant AS ItemIsReportingRelevant,
case left(doc._WithholdingTaxCode.WithholdingTaxIncomeType,3) when '14A' then case when doc._Onetime.AccountingDocument is not null then '' else doc._OperationalAcctgDocItem._SupplierBankDetails.BankAccount end else '' end as BankAccount AS BankAccountendelseendasBankAccount,
cast( doc.FiscalYear as int4 ) + 543 AS TH_FiscalYear
FROM P_TH_StRpWhldgTaxItem AS doc
INNER JOIN I_Withholdingtaxitem AS wht ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN C_TH_CreditMemoCube AS CreditMemoDoc ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN I_TH_BranchCode AS bpbranchadr ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN P_TH_CustomerBranchCode AS custbranchadr ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN P_Withholdingtxtype AS _TaxType ON _TaxType.land1 = doc.Country AND _TaxType.witht = doc.WithholdingTaxType -- association [0..1]
;