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_PT_SAFTSlsInvcBillgCust.
-- 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_PT_SAFTSlsInvcBillgCust AS
SELECT
Sig.CompanyCode AS CompanyCode,
Sig.PortugueseInvoiceNumber AS PortugueseInvoiceNumber,
Doc.BillingDocumentDate AS DocumentDate,
cast(case when _CustLand.Country is not initial then case when Doc.VATRegistrationCountry is not initial then concat(Hist.PortugueseCustomerWithVersion, concat('/', Doc.VATRegistrationCountry )) else concat(Hist.PortugueseCustomerWithVersion, concat('/', Hist.Country)) end else case when Hist.Country != Cust.Country then concat(Hist.PortugueseCustomerWithVersion,concat('/',Hist.Country)) else Hist.PortugueseCustomerWithVersion end end as abap.char(30)) as BusinessPartnerCustomer AS char30asBusinessPartnerCustomer,
Doc.BillingDocument AS AccountingDocument,
Doc.PayerParty AS Customer,
cast( case when _CustLand.Country is not initial then case when _CustLand.Country = 'AE' then _CustLand.CustomerVATRegistration else substring(_CustLand.CustomerVATRegistration,3,18) end else case when Cust.VATRegistration is not initial then substring(Cust.VATRegistration,3,18) else case when Cust.TaxNumber1 is not initial then Cust.TaxNumber1 else case when Cust.TaxNumber2 is not initial then Cust.TaxNumber2 else case when Cust.TaxNumber3 is not initial then Cust.TaxNumber3 else case when Cust.TaxNumber4 is not initial then Cust.TaxNumber4 else case when Cust.TaxNumber5 is not initial then Cust.TaxNumber5 else case when Cust.TaxNumber6 is not initial then Cust.TaxNumber6 end end end end end end end end as abap.char(20)) as CustomerVATRegistration AS char20asCustomerVATRegistration,
cast (Hist.CompanyName as bu_name1tx) AS CompanyName,
case when Hist.CustomerSupplierAddress is initial then 'Desconhecido' else Hist.CustomerSupplierAddress end as StreetName AS CustomerSupplierAddressendasStreetName,
case when Hist.CityName is initial then 'Desconhecido' else Hist.CityName end as CityName AS CityNameendasCityName,
case when Hist.PostalCode is initial then '0000-000' else Hist.PostalCode end as PostalCode AS PostalCodeendasPostalCode,
case when Hist.Country is initial then 'Desconhecido' else Hist.Country end as PT_SAFTCountryText AS CountryendasPT_SAFTCountryText,
coalesce ( Hist.ContactPersonName, '' ) AS CompanyContactPersonFullName,
coalesce ( Hist.PhoneNumber, '' ) AS PhoneNumber,
cast(coalesce ( Hist.FaxNumber, '' ) as abap.char(31) ) AS FaxNumber,
coalesce ( Hist.EmailAddress, '' ) AS EmailAddress,
coalesce ( Hist.SearchURLAddress, '' ) AS WebsiteURL,
Doc.PayerParty AS PayerParty,
Doc.SDDocumentCategory AS SDDocumentCategory,
Cust.IsOneTimeAccount AS IsOneTimeAccount,
Hist.PortugueseCustomerWithVersion AS BusinessPartnerCustomer,
Doc._PayerParty AS _PayerParty
FROM I_PT_BillgDocDgtlSgntr AS Sig
INNER JOIN I_BillingDocument AS Doc ON /* join condition not captured in parsed metadata */
INNER JOIN I_Customer AS Cust ON /* join condition not captured in parsed metadata */
INNER JOIN I_CustomerCompany AS CustCompany ON /* join condition not captured in parsed metadata */
INNER JOIN I_PT_SAFTBillgDocCustAddrHist AS Hist ON /* join condition not captured in parsed metadata */
INNER JOIN I_PT_SAFTIsAlternateAccount AS AltAcct ON /* join condition not captured in parsed metadata */
INNER JOIN I_GLAccountInCompanyCode AS CompAcct ON /* join condition not captured in parsed metadata */
INNER JOIN I_InvoiceList AS Doc ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN I_SAFTCustTaxRegnNmbr AS _CustLand ON Doc.PayerParty = _CustLand.CustomerNum AND Doc.VATRegistrationCountry = _CustLand.Country -- association [0..1]
-- UNION with additional select branch(es): I_PT_BillgDocDgtlSgntr
;