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_GenLedgerBPMasterData.
-- 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_GenLedgerBPMasterData AS
SELECT
Document.CompanyCode AS CompanyCode,
Document.FiscalYear AS FiscalYear,
Document.AccountingDocument AS AccountingDocument,
Document.AccountingDocumentItem AS AccountingDocumentItem,
cast (case when Document.Customer is not initial then case Document._Customer.IsOneTimeAccount when 'X' then case when Document._JournalEntryItemOneTimeData.TaxID1 is not initial then concat(Document.Customer, concat('/', Document._JournalEntryItemOneTimeData.TaxID1 )) else case when Document.VATRegistration is initial or Document.VATRegistration is null then concat(Document.Customer, concat('/', '999999990')) else concat(Document.Customer, concat('/', substring(Document.VATRegistration ,3,18))) end end else case when _CustHist.PortugueseCustomerWithVersion is not initial then case when CustInfo.DelivOfGoodsDestCountry is not initial then case when CustInfo.DelivOfGoodsDestCountry != Document._Customer.Country then concat(_CustHist.PortugueseCustomerWithVersion,concat('/',CustInfo.DelivOfGoodsDestCountry)) else _CustHist.PortugueseCustomerWithVersion end else _CustHist.PortugueseCustomerWithVersion end when Document.Customer is not initial then case when CustInfo.DelivOfGoodsDestCountry is not initial then case when CustInfo.DelivOfGoodsDestCountry != Document._Customer.Country then concat(Document.Customer,concat('/',CustInfo.DelivOfGoodsDestCountry)) else Document.Customer end else Document.Customer end end end end as abap.char(32) ) as BusinessPartnerCustomer AS char32asBusinessPartnerCustomer,
Document.Customer AS Customer,
Document.Supplier AS Supplier,
cast( case when Document.Supplier is not initial then case Document._Supplier.IsOneTimeAccount when 'X' then case when Document.VATRegistration is initial or Document.VATRegistration is null then case when Document._JournalEntryItemOneTimeData.TaxID1 is not initial then concat(Document.Supplier,concat('/', Document._JournalEntryItemOneTimeData.TaxID1)) else concat(Document.Supplier, concat('/','999999990')) end else concat(Document.Supplier,concat('/',substring(Document.VATRegistration ,3,18))) end else case when CustInfo.DelivOfGoodsDestCountry is not initial then case when CustInfo.DelivOfGoodsDestCountry != Document._Supplier.Country then concat(Document.Supplier,concat('/',CustInfo.DelivOfGoodsDestCountry)) else Document.Supplier end else Document.Supplier end end end as abap.char(32) ) as SupplierToPartner AS char32asSupplierToPartner,
CustInfo.DelivOfGoodsDestCountry AS DelivOfGoodsDestCountry,
case when Document.Customer is not initial then Document._Customer.IsOneTimeAccount else Document._Supplier.IsOneTimeAccount end as IsOneTimeAccount AS IsOneTimeAccountendasIsOneTimeAccount,
case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.AddressID else case when Document.Customer is not initial then Document._Customer.AddressID else Document._Supplier.AddressID end end as AddressID AS AddressIDendendasAddressID,
case when Document.Customer is not initial then case IsOneTimeAccount when 'X' then concat_with_space(Document._JournalEntryItemOneTimeData.BusinessPartnerName1, Document._JournalEntryItemOneTimeData.BusinessPartnerName2, 1) else case when _CustHist.Customer is not initial then _CustHist.CompanyName else concat_with_space(Document._Customer.BusinessPartnerName1, Document._Customer.BusinessPartnerName2, 1) end end else case IsOneTimeAccount when 'X' then concat_with_space(Document._JournalEntryItemOneTimeData.BusinessPartnerName1, Document._JournalEntryItemOneTimeData.BusinessPartnerName2, 1) else Document._Supplier.BPSupplierName end end as CompanyName AS BPSupplierNameendendasCompanyName,
cast(' ' as adrnr) AS CustomerSupplierAddress,
case when Document.Customer is not initial then case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.CityName else case when _CustHist.Customer is not initial then _CustHist.CityName else Document._Customer.CityName end end else case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.CityName else Document._Supplier.CityName end end as CityName AS CityNameendendasCityName,
case when Document.Customer is not initial then case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.PostalCode else case when _CustHist.Customer is not initial then _CustHist.PostalCode else Document._Customer.PostalCode end end else case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.PostalCode else Document._Supplier.PostalCode end end as PostalCode AS PostalCodeendendasPostalCode,
case when Document.Customer is not initial then case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.Country else case when _CustHist.Customer is not initial then _CustHist.Country else Document._Customer.Country end end else case IsOneTimeAccount when 'X' then Document._JournalEntryItemOneTimeData.Country else Document._Supplier.Country end end as Country AS CountryendendasCountry,
Document._CompanyCode AS _CompanyCode,
Document._FiscalYear AS _FiscalYear,
Document._JournalEntry AS _JournalEntry,
Document._Supplier AS _Supplier,
Document._Customer AS _Customer,
Document._JournalEntryItemOneTimeData AS _JournalEntryItemOneTimeData
FROM I_OperationalAcctgDocItem AS Document
INNER JOIN I_PT_SAFTGenericSettings AS GenericSettings ON /* join condition not captured in parsed metadata */
INNER JOIN P_PT_BusinessPartner_Delivery AS CustInfo ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN I_PT_SAFTAcctgDocCustAddrHist AS _CustHist ON _CustHist.AccountingDocument = Document.AccountingDocument AND _CustHist.CompanyCode = Document.CompanyCode AND _CustHist.FiscalYear = Document.FiscalYear AND _CustHist.Customer = Document.Customer -- association [0..1]
;