P_APLineItemForCorrespondence

DDL: P_APLINEITEMFORCORRESPONDENCE SQL: PAPLIITFORCOR Type: view COMPOSITE

P_APLineItemForCorrespondence is a Composite CDS View in SAP S/4HANA. It reads from 6 data sources and exposes 173 fields with key fields CompanyCode, AccountingDocument, FiscalYear, AccountingDocumentItem, AccountingDocument. It has 1 association to related views.

Data Sources (6)

SourceAliasJoin Type
I_OperationalAcctgDocItem I_OperationalAcctgDocItem from
I_OperationalAcctgDocItem I_OperationalAcctgDocItem union_all
I_ParkedPayablesItem I_ParkedPayablesItem union_all
I_ParkedReceivablesItem I_ParkedReceivablesItem union_all
P_SupplierAsCustomer P_SupplierAsCustomer inner
P_SupplierAsCustomer P_SupplierAsCustomer inner

Parameters (2)

NameTypeDefault
P_KeyDate vdm_v_key_date
P_TodayDate abap.dats

Associations (1)

CardinalityTargetAliasCondition
[1..1] I_ParkedAccountingDocument _ParkedAccountingDocument $projection.AccountingDocument = _ParkedAccountingDocument.AccountingDocument and $projection.FiscalYear = _ParkedAccountingDocument.FiscalYear and $projection.CompanyCode = _ParkedAccountingDocument.CompanyCode

Annotations (10)

NameValueLevelField
AbapCatalog.sqlViewName PAPLIITFORCOR view
AbapCatalog.compiler.compareFilter true view
AbapCatalog.preserveKey true view
VDM.viewType #COMPOSITE view
VDM.private true view
ObjectModel.usageType.dataClass #MIXED view
ObjectModel.usageType.serviceQuality #D view
ObjectModel.usageType.sizeCategory #M view
AccessControl.authorizationCheck #NOT_REQUIRED view
ClientHandling.algorithm #SESSION_VARIABLE view

Fields (173)

KeyFieldSource TableSource FieldDescription
KEY CompanyCode CompanyCode
KEY AccountingDocument AccountingDocument
KEY FiscalYear FiscalYear
KEY AccountingDocumentItem AccountingDocumentItem
FinancialAccountType FinancialAccountType
CustomerSupplierAccount Supplier
PostingDate PostingDate
DocumentDate DocumentDate
AccountingDocumentCreationDate
TransactionCurrency TransactionCurrency
CompanyCodeCurrency CompanyCodeCurrency
DocumentReferenceID
AccountingDocumentType AccountingDocumentType
AccountingDocumentCategory AccountingDocumentCategory
BranchAccount BranchAccount
FiscalPeriod FiscalPeriod
PostingKey PostingKey
SpecialGLCode SpecialGLCode
Customer Customer
Supplier Supplier
ClearingDate ClearingDate
ClearingAccountingDocument ClearingJournalEntry
AssignmentReference AssignmentReference
DebitCreditCode DebitCreditCode
AmountInTransactionCurrency AmountInTransactionCurrency
AmountInCompanyCodeCurrency AmountInCompanyCodeCurrency
BalanceTransactionCurrency BalanceTransactionCurrency
AmountInBalanceTransacCrcy AmountInBalanceTransacCrcy
NetDueDate NetDueDate
DocumentItemText DocumentItemText
ItemTypeBranch
DueCalculationBaseDate DueCalculationBaseDate
CashDiscount1Days CashDiscount1Days
CashDiscount2Days CashDiscount2Days
CashDiscount1DueDate CashDiscount1DueDate
CashDiscount2DueDate CashDiscount2DueDate
BillingDocument BillingDocument
Reference1IDByBusinessPartner Reference1IDByBusinessPartner
Reference2IDByBusinessPartner Reference2IDByBusinessPartner
Reference3IDByBusinessPartner Reference3IDByBusinessPartner
BPBankAccountInternalID BPBankAccountInternalID
PaymentReference PaymentReference
ReferenceDocumentType ReferenceDocumentType
CustomerkeyCompanyCode
KEY AccountingDocument AccountingDocument
KEY FiscalYear FiscalYear
KEY AccountingDocumentItem AccountingDocumentItem
FinancialAccountType FinancialAccountType
CustomerSupplierAccount I_OperationalAcctgDocItem Customer
PostingDate PostingDate
DocumentDate DocumentDate
AccountingDocumentCreationDate
TransactionCurrency TransactionCurrency
CompanyCodeCurrency CompanyCodeCurrency
DocumentReferenceID
AccountingDocumentType AccountingDocumentType
AccountingDocumentCategory AccountingDocumentCategory
BranchAccount BranchAccount
FiscalPeriod FiscalPeriod
PostingKey PostingKey
SpecialGLCode SpecialGLCode
Customer P_SupplierAsCustomer Customer
Supplier P_SupplierAsCustomer Supplier
ClearingDate ClearingDate
ClearingAccountingDocument ClearingJournalEntry
AssignmentReference AssignmentReference
DebitCreditCode DebitCreditCode
AmountInTransactionCurrency AmountInTransactionCurrency
AmountInCompanyCodeCurrency AmountInCompanyCodeCurrency
BalanceTransactionCurrency BalanceTransactionCurrency
AmountInBalanceTransacCrcy AmountInBalanceTransacCrcy
NetDueDate NetDueDate
DocumentItemText DocumentItemText
ItemTypeBranch
DueCalculationBaseDate DueCalculationBaseDate
CashDiscount1Days CashDiscount1Days
CashDiscount2Days CashDiscount2Days
CashDiscount1DueDate CashDiscount1DueDate
CashDiscount2DueDate CashDiscount2DueDate
BillingDocument BillingDocument
Reference1IDByBusinessPartner Reference1IDByBusinessPartner
Reference2IDByBusinessPartner Reference2IDByBusinessPartner
Reference3IDByBusinessPartner Reference3IDByBusinessPartner
BPBankAccountInternalID BPBankAccountInternalID
PaymentReference PaymentReference
ReferenceDocumentType ReferenceDocumentType
CompanyCodekeyCompanyCode
KEY AccountingDocument AccountingDocument
KEY FiscalYear FiscalYear
KEY AccountingDocumentItem AccountingDocumentItem
FinancialAccountType
CustomerSupplierAccount I_ParkedPayablesItem Creditor
PostingDate _ParkedAccountingDocument PostingDate
DocumentDate _ParkedAccountingDocument DocumentDate
AccountingDocumentCreationDate _ParkedAccountingDocument AccountingDocumentCreationDate
TransactionCurrency TransactionCurrency
CompanyCodeCurrency CompanyCodeCurrency
DocumentReferenceID _ParkedAccountingDocument DocumentReferenceID
AccountingDocumentType _ParkedAccountingDocument AccountingDocumentType
AccountingDocumentCategory _ParkedAccountingDocument AccountingDocumentCategory
BranchAccount I_ParkedPayablesItem BranchAccount
FiscalPeriod _ParkedAccountingDocument FiscalPeriod
PostingKey PostingKey
SpecialGLCode SpecialGLCode
Customer
Supplier I_ParkedPayablesItem Creditor
ClearingDate
ClearingAccountingDocument
AssignmentReference AssignmentReference
DebitCreditCode DebitCreditCode
AmountInTransactionCurrency AmountInTransactionCurrency
AmountInCompanyCodeCurrency AmountInCompanyCodeCurrency
BalanceTransactionCurrency
AmountInBalanceTransacCrcy 0
NetDueDate NetDueDate
DocumentItemText DocumentItemText
ItemTypeBranch
DueCalculationBaseDate DueCalculationBaseDate
CashDiscount1Days CashDiscount1Days
CashDiscount2Days CashDiscount2Days
CashDiscount1DueDate CashDiscount1DueDate
CashDiscount2DueDate CashDiscount2DueDate
BillingDocument
Reference1IDByBusinessPartner Reference1IDByBusinessPartner
Reference2IDByBusinessPartner Reference2IDByBusinessPartner
Reference3IDByBusinessPartner Reference3IDByBusinessPartner
BPBankAccountInternalID BPBankAccountInternalID
PaymentReference PaymentReference
ReferenceDocumentType ReferenceDocumentType
CompanyCodekeyCompanyCode
KEY AccountingDocument AccountingDocument
KEY FiscalYear FiscalYear
KEY AccountingDocumentItem AccountingDocumentItem
FinancialAccountType
CustomerSupplierAccount I_ParkedReceivablesItem Debtor
PostingDate _ParkedAccountingDocument PostingDate
DocumentDate _ParkedAccountingDocument DocumentDate
AccountingDocumentCreationDate _ParkedAccountingDocument AccountingDocumentCreationDate
TransactionCurrency TransactionCurrency
CompanyCodeCurrency CompanyCodeCurrency
DocumentReferenceID _ParkedAccountingDocument DocumentReferenceID
AccountingDocumentType _ParkedAccountingDocument AccountingDocumentType
AccountingDocumentCategory _ParkedAccountingDocument AccountingDocumentCategory
BranchAccount I_ParkedReceivablesItem BranchAccount
FiscalPeriod _ParkedAccountingDocument FiscalPeriod
PostingKey PostingKey
SpecialGLCode SpecialGLCode
Customer P_SupplierAsCustomer Customer
Supplier P_SupplierAsCustomer Supplier
ClearingDate
ClearingAccountingDocument
AssignmentReference AssignmentReference
DebitCreditCode DebitCreditCode
AmountInTransactionCurrency AmountInTransactionCurrency
AmountInCompanyCodeCurrency AmountInCompanyCodeCurrency
BalanceTransactionCurrency
AmountInBalanceTransacCrcy 0
NetDueDate NetDueDate
DocumentItemText DocumentItemText
ItemTypeBranch
DueCalculationBaseDate DueCalculationBaseDate
CashDiscount1Days CashDiscount1Days
CashDiscount2Days CashDiscount2Days
CashDiscount1DueDate CashDiscount1DueDate
CashDiscount2DueDate CashDiscount2DueDate
BillingDocument
Reference1IDByBusinessPartner Reference1IDByBusinessPartner
Reference2IDByBusinessPartner Reference2IDByBusinessPartner
Reference3IDByBusinessPartner Reference3IDByBusinessPartner
BPBankAccountInternalID BPBankAccountInternalID
PaymentReference PaymentReference
ReferenceDocumentType ReferenceDocumentType
OriginalReferenceDocument OriginalReferenceDocument
@AbapCatalog.sqlViewName: 'PAPLIITFORCOR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true

@VDM.viewType: #COMPOSITE
@VDM.private: true

@ObjectModel.usageType.dataClass:  #MIXED
@ObjectModel.usageType.serviceQuality: #D
@ObjectModel.usageType.sizeCategory: #M

@AccessControl.authorizationCheck: #NOT_REQUIRED

@ClientHandling.algorithm: #SESSION_VARIABLE

define view P_APLineItemForCorrespondence
  with parameters
    P_KeyDate   : vdm_v_key_date,
    @Environment.systemField: #SYSTEM_DATE
    P_TodayDate : abap.dats
  //  posted credit items

  as select from I_OperationalAcctgDocItem
{
  key CompanyCode,
  key AccountingDocument,
  key FiscalYear,
  key AccountingDocumentItem,
      FinancialAccountType,
      Supplier                                                                                 as  CustomerSupplierAccount,
      case :P_KeyDate
        when '00000000' then
           cast( :P_TodayDate as farp_keydt )
        else
           cast( :P_KeyDate as farp_keydt )
        end                                                                                    as  KeyDate,
      PostingDate,
      DocumentDate,
      I_OperationalAcctgDocItem._JournalEntry.AccountingDocumentCreationDate                   as  AccountingDocumentCreationDate,
      TransactionCurrency,
      CompanyCodeCurrency,
      I_OperationalAcctgDocItem._JournalEntry.DocumentReferenceID                              as  DocumentReferenceID,
      AccountingDocumentType,
      AccountingDocumentCategory,
      case AccountingDocumentCategory
      when 'S' then //Noted items

        'M'
      when 'V' then //Parked document

        'P'
      when 'W' then //Parked document with change of document ID

        'P'
      else          //Normal Document

        case when SpecialGLCode = '' then
            'N'
        else
            'S'
        end
      end                                                                                      as  DueItemType,
      BranchAccount,
      FiscalPeriod,
      PostingKey,
      SpecialGLCode,
      Customer,
      Supplier,
      ClearingDate,
      ClearingJournalEntry                                                                     as ClearingAccountingDocument,
      AssignmentReference,
      DebitCreditCode,
      AmountInTransactionCurrency,
      AmountInCompanyCodeCurrency,
      BalanceTransactionCurrency,
      AmountInBalanceTransacCrcy,
      NetDueDate,
      DocumentItemText,
      //      Do not use the auxiliary field ITEM_TYPE_BRANCH. It is only for SAP internal usage. It might be removed in the future.

      //      The field is needed for performance optimization. It specifies the branch of the Union per which a line item was selected.

      cast ( 'BSEG_CREDIT_SIDE_BRANCH' as char30 )                                             as  ItemTypeBranch,
      //      BELEGNUM,

      //      blart_desc,

      //      bschl_desc,

      //      umskz_desc

      DueCalculationBaseDate,
      CashDiscount1Days,
      CashDiscount2Days,
      CashDiscount1DueDate,
      CashDiscount2DueDate,
      BillingDocument,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then AccountingDocument
          else InvoiceReference
      end
        as InvoiceReference,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then FiscalYear
          else InvoiceReferenceFiscalYear
      end
        as InvoiceReferenceFiscalYear,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then cast('000' as fis_rebzz)
          else InvoiceItemReference
      end
        as InvoiceItemReference,
      Reference1IDByBusinessPartner,
      Reference2IDByBusinessPartner,
      Reference3IDByBusinessPartner,
      BPBankAccountInternalID,
      PaymentReference,
      ReferenceDocumentType,
      OriginalReferenceDocument
}
where
  (
      FinancialAccountType     = 'K'
  )
  and not(
    AccountingDocumentCategory = 'D'
  )
  and not(
    AccountingDocumentCategory = 'M'
  )

union all
//  posted debit items of mixed accounts

select from  I_OperationalAcctgDocItem
  inner join P_SupplierAsCustomer on I_OperationalAcctgDocItem.Customer = P_SupplierAsCustomer.Customer
{
  key CompanyCode,
  key AccountingDocument,
  key FiscalYear,
  key AccountingDocumentItem,
      FinancialAccountType,
      //      case when FinancialAccountType = 'D'

      //        then Customer

      //        else Supplier

      //        end as CustomerSupplierAccount,

      I_OperationalAcctgDocItem.Customer                                                       as  CustomerSupplierAccount,
      case :P_KeyDate
        when '00000000' then
           cast( :P_TodayDate as farp_keydt )
        else
           cast( :P_KeyDate as farp_keydt )
        end                                                                                    as  KeyDate,
      PostingDate,
      DocumentDate,
      I_OperationalAcctgDocItem._JournalEntry.AccountingDocumentCreationDate                   as  AccountingDocumentCreationDate,
      TransactionCurrency,
      CompanyCodeCurrency,
      I_OperationalAcctgDocItem._JournalEntry.DocumentReferenceID                              as  DocumentReferenceID,
      AccountingDocumentType,
      AccountingDocumentCategory,
      case AccountingDocumentCategory
      when 'S' then //Noted items

        'M'
      when 'V' then //Parked document

        'P'
      when 'W' then //Parked document with change of document ID

        'P'
      else          //Normal Document

        case when SpecialGLCode = '' then
            'N'
        else
            'S'
        end
      end                                                                                      as  DueItemType,
      BranchAccount,
      FiscalPeriod,
      PostingKey,
      SpecialGLCode,
      P_SupplierAsCustomer.Customer                                                            as  Customer,
      P_SupplierAsCustomer.Supplier                                                            as  Supplier,
      ClearingDate,
      ClearingJournalEntry                                                                     as ClearingAccountingDocument,
      AssignmentReference,
      DebitCreditCode,
      AmountInTransactionCurrency,
      AmountInCompanyCodeCurrency,
      BalanceTransactionCurrency,
      AmountInBalanceTransacCrcy,
      NetDueDate,
      DocumentItemText,
      //      Do not use the auxiliary field ITEM_TYPE_BRANCH. It is only for SAP internal usage. It might be removed in the future.

      //      The field is needed for performance optimization. It specifies the branch of the Union per which a line item was selected.

      cast ( 'BSEG_DEBIT_SIDE_BRANCH' as char30 )                                              as  ItemTypeBranch,
      DueCalculationBaseDate,
      CashDiscount1Days,
      CashDiscount2Days,
      CashDiscount1DueDate,
      CashDiscount2DueDate,
      BillingDocument,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then AccountingDocument
          else InvoiceReference
      end
        as InvoiceReference,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then FiscalYear
          else InvoiceReferenceFiscalYear
      end
        as InvoiceReferenceFiscalYear,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then cast('000' as fis_rebzz)
          else InvoiceItemReference
      end
        as InvoiceItemReference,
      Reference1IDByBusinessPartner,
      Reference2IDByBusinessPartner,
      Reference3IDByBusinessPartner,
      BPBankAccountInternalID,
      PaymentReference,
      ReferenceDocumentType,
      OriginalReferenceDocument
}
where
      FinancialAccountType     = 'D'
  and not(
    AccountingDocumentCategory = 'D'
  ) //D = Recurring entry document

  and not(
    AccountingDocumentCategory = 'M'
  ) //M = Sample document

  and P_SupplierAsCustomer.Customer != ''

union all
//  parked credit items

select from I_ParkedPayablesItem
association [1..1] to I_ParkedAccountingDocument as _ParkedAccountingDocument on  $projection.AccountingDocument = _ParkedAccountingDocument.AccountingDocument
                                                                              and $projection.FiscalYear         = _ParkedAccountingDocument.FiscalYear
                                                                              and $projection.CompanyCode        = _ParkedAccountingDocument.CompanyCode
{
  key CompanyCode,
  key AccountingDocument,
  key FiscalYear,
  key AccountingDocumentItem,
      'K'                                                                                      as  FinancialAccountType,
      //      case when FinancialAccountType = 'D'

      //        then Customer

      //        else Supplier

      //        end as CustomerSupplierAccount,

      I_ParkedPayablesItem.Creditor                                                            as  CustomerSupplierAccount,
      case :P_KeyDate
        when '00000000' then
           cast( :P_TodayDate as farp_keydt )
        else
           cast( :P_KeyDate as farp_keydt )
        end                                                                                    as  KeyDate,
      _ParkedAccountingDocument.PostingDate,
      _ParkedAccountingDocument.DocumentDate,
      _ParkedAccountingDocument.AccountingDocumentCreationDate                                 as  AccountingDocumentCreationDate,
      TransactionCurrency,
      CompanyCodeCurrency,
      _ParkedAccountingDocument.DocumentReferenceID                                            as  DocumentReferenceID,
      _ParkedAccountingDocument.AccountingDocumentType,
      _ParkedAccountingDocument.AccountingDocumentCategory,
      case _ParkedAccountingDocument.AccountingDocumentCategory
      when 'S' then //Noted items

        'M'
      when 'V' then //Parked document

        'P'
      when 'W' then //Parked document with change of document ID

        'P'
      else          //Normal Document

        case when SpecialGLCode = '' then
            'N'
        else
            'S'
        end
      end                                                                                      as  DueItemType,
      I_ParkedPayablesItem.BranchAccount                                                       as  BranchAccount,
      _ParkedAccountingDocument.FiscalPeriod,
      PostingKey,
      SpecialGLCode,
      ''                                                                                       as  Customer,
      I_ParkedPayablesItem.Creditor                                                            as  Supplier,
      '00000000'                                                                               as  ClearingDate,
      '          '                                                                             as  ClearingAccountingDocument,
      AssignmentReference,
      DebitCreditCode,
      AmountInTransactionCurrency,
      AmountInCompanyCodeCurrency,
      '     '                                                                                  as  BalanceTransactionCurrency,
      0                                                                                        as  AmountInBalanceTransacCrcy,
      NetDueDate,
      DocumentItemText,
      //      Do not use the auxiliary field ITEM_TYPE_BRANCH. It is only for SAP internal usage. It might be removed in the future.

      //      The field is needed for performance optimization. It specifies the branch of the Union per which a line item was selected.

      cast ( 'VBSEGK_BRANCH' as char30 )                                                       as  ItemTypeBranch,
      DueCalculationBaseDate,
      CashDiscount1Days,
      CashDiscount2Days,
      CashDiscount1DueDate,
      CashDiscount2DueDate,
      '          '                                                                             as  BillingDocument,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then AccountingDocument
          else InvoiceReference
      end
        as InvoiceReference,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then FiscalYear
          else InvoiceReferenceFiscalYear
      end
        as InvoiceReferenceFiscalYear,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then cast('000' as fis_rebzz)
          else InvoiceItemReference
      end
        as InvoiceItemReference,
      Reference1IDByBusinessPartner,
      Reference2IDByBusinessPartner,
      Reference3IDByBusinessPartner,
      BPBankAccountInternalID,
      PaymentReference,
      ReferenceDocumentType,
      OriginalReferenceDocument
}

union all
//  parked debit items of mixed accounts

select from  I_ParkedReceivablesItem
  inner join P_SupplierAsCustomer on I_ParkedReceivablesItem.Debtor = P_SupplierAsCustomer.Customer

association [1..1] to I_ParkedAccountingDocument as _ParkedAccountingDocument on  $projection.AccountingDocument = _ParkedAccountingDocument.AccountingDocument
                                                                              and $projection.FiscalYear         = _ParkedAccountingDocument.FiscalYear
                                                                              and $projection.CompanyCode        = _ParkedAccountingDocument.CompanyCode

{
  key CompanyCode,
  key AccountingDocument,
  key FiscalYear,
  key AccountingDocumentItem,
      'D'                                                                                                as  FinancialAccountType,
      //      case when FinancialAccountType = 'D'

      //        then Customer

      //        else Supplier

      //        end as CustomerSupplierAccount,

      I_ParkedReceivablesItem.Debtor                                                                     as  CustomerSupplierAccount,
      case :P_KeyDate
        when '00000000' then
           cast( :P_TodayDate as farp_keydt )
        else
           cast( :P_KeyDate as farp_keydt )
        end                                                                                              as  KeyDate,
      _ParkedAccountingDocument.PostingDate,
      _ParkedAccountingDocument.DocumentDate,
      _ParkedAccountingDocument.AccountingDocumentCreationDate                                           as  AccountingDocumentCreationDate,
      TransactionCurrency,
      CompanyCodeCurrency,
      _ParkedAccountingDocument.DocumentReferenceID                                                      as  DocumentReferenceID,
      _ParkedAccountingDocument.AccountingDocumentType,
      _ParkedAccountingDocument.AccountingDocumentCategory,
      case _ParkedAccountingDocument.AccountingDocumentCategory
      when 'S' then //Noted items

         'M'
      when 'V' then //Parked document

         'P'
      when 'W' then //Parked document with change of document ID

         'P'
      else          //Normal Document

         case when SpecialGLCode = '' then
             'N'
         else
             'S'
         end
      end                                                                                                as  DueItemType,
      I_ParkedReceivablesItem.BranchAccount                                                              as  BranchAccount,
      _ParkedAccountingDocument.FiscalPeriod,
      PostingKey,
      SpecialGLCode,
      P_SupplierAsCustomer.Customer                                                                      as  Customer,
      P_SupplierAsCustomer.Supplier                                                                      as  Supplier,
      '00000000'                                                                                         as  ClearingDate,
      '          '                                                                                       as  ClearingAccountingDocument,
      AssignmentReference,
      DebitCreditCode,
      AmountInTransactionCurrency,
      AmountInCompanyCodeCurrency,
      '     '                                                                                            as  BalanceTransactionCurrency,
      0                                                                                                  as  AmountInBalanceTransacCrcy,
      NetDueDate,
      DocumentItemText,
      //      Do not use the auxiliary field ITEM_TYPE_BRANCH. It is only for SAP internal usage. It might be removed in the future.

      //      The field is needed for performance optimization. It specifies the branch of the Union per which a line item was selected.

      cast ( 'VBSEGD_BRANCH' as char30 )                                                                 as  ItemTypeBranch,
      DueCalculationBaseDate,
      CashDiscount1Days,
      CashDiscount2Days,
      CashDiscount1DueDate,
      CashDiscount2DueDate,
      '          '                                                                                       as  BillingDocument,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then AccountingDocument
          else InvoiceReference
      end
        as InvoiceReference,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then FiscalYear
          else InvoiceReferenceFiscalYear
      end
        as InvoiceReferenceFiscalYear,
      case
        when InvoiceReference = '' and FollowOnDocumentType = ''
          then cast('000' as fis_rebzz)
          else InvoiceItemReference
      end
        as InvoiceItemReference,
      Reference1IDByBusinessPartner,
      Reference2IDByBusinessPartner,
      Reference3IDByBusinessPartner,
      BPBankAccountInternalID,
      PaymentReference,
      ReferenceDocumentType,
      OriginalReferenceDocument
}
where
  P_SupplierAsCustomer.Customer != ''
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_JOURNALENTRY",
"I_OPERATIONALACCTGDOCITEM",
"I_PARKEDACCOUNTINGDOCUMENT",
"I_PARKEDPAYABLESITEM",
"I_PARKEDRECEIVABLESITEM",
"P_SUPPLIERASCUSTOMER"
],
"ASSOCIATED":
[],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/