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_PT_SAFTPaymentDocumentC.
-- 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_PT_SAFTPaymentDocumentC AS
SELECT
Document.CompanyCode AS CompanyCode,
Document.AccountingDocument AS ClearingAccountingDocument,
Document.FiscalYear AS FiscalYear,
cast(concat( concat( concat_with_space(Document.AccountingDocumentType, NrRange.PortugueseDgtlSignatureSeries, 1), '/'), Document.AccountingDocument) as abap.char(30)) as PaymentReference AS char30asPaymentReference,
Document.ReverseDocument AS ReverseDocument,
Document.IsReversed AS IsReversed,
Document.IsReversal AS IsReversal,
Document.ReverseDocumentFiscalYear AS ReverseDocumentFiscalYear,
cast(concat_with_space(concat(substring(Document.DocumentDate,1,4), concat('-', concat(substring(Document.DocumentDate,5,2), concat('-', substring(Document.DocumentDate,7,2))))), concat_with_space(Document.AccountingDocumentType, Document.AccountingDocument, 1), 1) as abap.char(70)) as DocumentTransaction AS char70asDocumentTransaction,
Document.AccountingDocumentCreationDate AS AccountingDocumentCreationDate,
Document.CreationTime AS CreationTime,
Document.ReversalReason AS ReversalReason,
concat(substring(Document.AccountingDocumentCreationDate,1,4), concat('-', concat(substring(Document.AccountingDocumentCreationDate,5,2), concat('-', concat(substring(Document.AccountingDocumentCreationDate,7,2), concat('T', concat(substring(Document.CreationTime,1,2), concat(':', concat(substring(Document.CreationTime,3,2), concat(':', substring(Document.CreationTime,5,2))))))))))) as LastChangeDateTimeText AS CreationTime52asLastChangeDateTimeText,
case when Document.ReverseDocument is not initial and Document.IsReversed <> '' then concat(substring(Document.AccountingDocumentCreationDate,1,4), concat('-', concat(substring(_ReversalDocument.AccountingDocumentCreationDate,5,2), concat('-', concat(substring(_ReversalDocument.AccountingDocumentCreationDate,7,2), concat('T', concat(substring(_ReversalDocument.CreationTime,1,2), concat(':', concat(substring(_ReversalDocument.CreationTime,3,2), concat(':', substring(_ReversalDocument.CreationTime,5,2))))))))))) else concat(substring(Document.AccountingDocumentCreationDate,1,4), concat('-', concat(substring(Document.AccountingDocumentCreationDate,5,2), concat('-', concat(substring(Document.AccountingDocumentCreationDate,7,2), concat('T', concat(substring(Document.CreationTime,1,2), concat(':', concat(substring(Document.CreationTime,3,2), concat(':', substring(Document.CreationTime,5,2))))))))))) end as PaymentStatusDateText AS CreationTime52endasPaymentStatusDateText,
Document.AccountingDocumentCategory AS AccountingDocumentCategory,
Document.FiscalPeriod AS FiscalPeriod,
Document.DocumentDate AS DocumentDate,
Document.PostingDate AS PostingDate,
Document.AccountingDocumentType AS AccountingDocumentType,
Document.CompanyCodeCurrency AS CompanyCodeCurrency,
Document.AccountingDocCreatedByUser AS CreatedByUser,
cast(coalesce(DownPay.DownPaymentType, ' ') as char4) AS DownPaymentType,
Document.ReferenceDocumentType AS ReferenceDocumentType,
Document.OriginalReferenceDocument AS OriginalReferenceDocument,
Document._CompanyCodeCurrency AS _CompanyCodeCurrency,
Document._AccountingDocumentCategory AS _AccountingDocumentCategory,
Document._CompanyCode AS _CompanyCode,
Document._AccountingDocumentType AS _AccountingDocumentType,
Document._OperationalAcctgDocItem AS _OperationalAcctgDocItem,
Document._FiscalYear AS _FiscalYear
INNER JOIN I_ClrgInfoRelationForAcctgDoc AS Clear ON /* join condition not captured in parsed metadata */
INNER JOIN I_AccountingDocumentType AS AcctDoc ON /* join condition not captured in parsed metadata */
INNER JOIN I_PT_DgtlSgntrNmbrRngeAcctg AS NrRange ON /* join condition not captured in parsed metadata */
INNER JOIN I_PT_SAFTPaytSignatureCheck AS check ON /* join condition not captured in parsed metadata */
LEFT OUTER JOIN I_SAFTAccountingTaxCheck AS _TotalItems ON _TotalItems.AccountingDocument = Document.AccountingDocument AND _TotalItems.CompanyCode = Document.CompanyCode AND _TotalItems.FiscalYear = Document.FiscalYear -- association [0..1]
LEFT OUTER JOIN I_ReversalReason AS _RevReason ON _RevReason.ReversalReason = Document.ReversalReason -- association [0..1]
LEFT OUTER JOIN I_AccountingDocument AS _ReversalDocument ON _ReversalDocument.AccountingDocument = Document.ReverseDocument AND _ReversalDocument.FiscalYear = Document.ReverseDocumentFiscalYear AND _ReversalDocument.CompanyCode = Document.CompanyCode -- association [0..1]
LEFT OUTER JOIN I_ClrgInfoRelationForAcctgDoc AS _Clearing ON _Clearing.ClearingInfoCompanyCode = Document.CompanyCode AND _Clearing.ClearingAccountingDocument = Document.AccountingDocument AND _Clearing.ClearingFiscalYear = Document.FiscalYear AND _Clearing.AccountType = 'D' AND _Clearing.SpecialGLCode <> 'F' -- association [0..1]
;