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_BG_SAFTPURINVOICEHEADER.
-- 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.
-- Parameters: P_AlternativeGLAccountIsUsed : saft_bg_alt_gl_account_flag, P_UserSystemIdentifier : sysid, P_VATRegistration : stceg
CREATE VIEW P_BG_SAFTPURINVOICEHEADER AS
SELECT
Header.SourceLedger AS SourceLedger,
Header.CompanyCode AS CompanyCode,
Header.FiscalYear AS FiscalYear,
Header.AccountingDocument AS AccountingDocument,
Header.Ledger AS Ledger,
Header.AccountingDocumentItem AS AccountingDocumentItem,
Bkpf.FiscalPeriod AS FiscalPeriod,
Bkpf.PostingDate AS PostingDate,
Bkpf.DocumentDate AS InvoiceDate,
Bkpf.TaxReportingDate AS TaxReportingDate,
Bkpf.AccountingDocumentType AS AccountingDocumentType,
Bkpf.AccountingDocCreatedByUser AS AccountingDocCreatedByUser,
Supplier.Supplier AS Supplier,
case when TaxType.BPTaxLongNumber <> '0' then concat_with_space( Supplier.BPAddrStreetName, Supplier._AddressDefaultRepresentation.HouseNumber, 1 ) else coalesce(OTC.StreetName, concat_with_space( Supplier.BPAddrStreetName, Supplier._AddressDefaultRepresentation.HouseNumber, 1 )) end as StreetName AS HouseNumber1endasStreetName,
case when TaxType.BPTaxLongNumber <> '0' then Supplier.BPAddrCityName else coalesce(OTC.CityName, Supplier.BPAddrCityName) end as CityName AS BPAddrCityNameendasCityName,
case when TaxType.BPTaxLongNumber <> '0' then Supplier.PostalCode else coalesce(OTC.PostalCode, Supplier.PostalCode) end as PostalCode AS PostalCodeendasPostalCode,
case when TaxType.BPTaxLongNumber <> '0' then Supplier.Country else coalesce(OTC.Country, Supplier.Country) end as Country AS CountryendasCountry,
Header.BG_SAFTSourceDocumentType AS BG_SAFTInvoiceType,
case when Bseg.VATRegistration <> '' and BsegStcegCountry.IsEuropeanUnionMember = 'X' then case when BsegStcegCountry.Country = 'BG' then replace(Bseg.VATRegistration, 'BG', '10') else cast(concat('11', Bseg.VATRegistration) as bptaxnumxl) end when TaxType.BPTaxLongNumber = 'EXCLUDE' then cast($parameters.P_VATRegistration as bptaxnumxl) when TaxType.BPTaxLongNumber <> '0' then TaxType.BPTaxLongNumber else OTC.VATRegistration end as SupplierTaxID5 AS VATRegistrationendasSupplierTaxID5,
case $parameters.P_AlternativeGLAccountIsUsed when 'X' then Bseg._GLAccountInCompanyCode.AlternativeGLAccount else Bseg.GLAccount end as ActiveGLAccount AS GLAccountendasActiveGLAccount,
cast(concat( $parameters.P_UserSystemIdentifier, concat( concat( concat( '/', cast( $session.client as char3 )), '/' ) , Header.AccountingDocument ) ) as text18) AS BG_SAFTSystemID,
coalesce(PayTerms._Text[1: Language='W'].PaymentTermsName, PayTerms._Text[1: Language='E'].PaymentTermsName) AS PaymentTermsName,
'N' AS SelfBillingValueItemDesc
FROM P_BG_SAFTPURINVHDR AS Header
INNER JOIN I_JournalEntry AS Bkpf ON /* join condition not captured in parsed metadata */
INNER JOIN I_OperationalAcctgDocItem AS Bseg ON /* join condition not captured in parsed metadata */
INNER JOIN P_BG_SAFTINVOICEITEMCOUNT AS CountFilter ON /* join condition not captured in parsed metadata */
;