P_GLAcctLineItemEnrcd

DDL: P_GLACCTLINEITEMENRCD SQL: PGLACCTLINEITEME Type: view COMPOSITE

P_GLAcctLineItemEnrcd is a Composite CDS View in SAP S/4HANA. It reads from 5 data sources (I_FiscalYearForCompanyCode, I_Ledger, I_Ledger, I_GLAccountLineItem, I_GLAccountLineItem) and exposes 147 fields with key fields CompanyCode, FiscalYear, AccountingDocument, LedgerGLLineItem, FiscalYear. It has 2 associations to related views.

Data Sources (5)

SourceAliasJoin Type
I_FiscalYearForCompanyCode fiscalyear inner
I_Ledger ledger inner
I_Ledger ledger inner
I_GLAccountLineItem lineitem from
I_GLAccountLineItem lineitem union_all

Parameters (2)

NameTypeDefault
P_CompanyCode bukrs
P_FiscalYear gjahr

Associations (2)

CardinalityTargetAliasCondition
[1..1] I_GLAccountInCompanyCode _GLAccountInCompanyCode $projection.CompanyCode = _GLAccountInCompanyCode.CompanyCode and $projection.GLAccount = _GLAccountInCompanyCode.GLAccount
[1..1] I_AccountingDocument _AccountingDocument $projection.CompanyCode = _AccountingDocument.CompanyCode and $projection.FiscalYear = _AccountingDocument.FiscalYear and $projection.AccountingDocument = _AccountingDocument.AccountingDocument

Annotations (7)

NameValueLevelField
AbapCatalog.sqlViewName PGLACCTLINEITEME view
AbapCatalog.compiler.compareFilter true view
AbapCatalog.preserveKey true view
AccessControl.authorizationCheck #NOT_REQUIRED view
VDM.private true view
VDM.viewType #COMPOSITE view
ClientHandling.algorithm #SESSION_VARIABLE view

Fields (147)

KeyFieldSource TableSource FieldDescription
KEY CompanyCode I_GLAccountLineItem CompanyCode
KEY FiscalYear I_GLAccountLineItem FiscalYear
KEY AccountingDocument I_GLAccountLineItem AccountingDocument
KEY LedgerGLLineItem I_GLAccountLineItem LedgerGLLineItem
FiscalPeriod I_GLAccountLineItem FiscalPeriod
GLAccount I_GLAccountLineItem GLAccount
AlternativeGLAccount _GLAccountInCompanyCode AlternativeGLAccount
Supplier I_GLAccountLineItem Supplier
Customer I_GLAccountLineItem Customer
SpecialGLCode I_GLAccountLineItem SpecialGLCode
ProfitCenter I_GLAccountLineItem ProfitCenter
Segment I_GLAccountLineItem Segment
BusinessArea I_GLAccountLineItem BusinessArea
AssignmentReference I_GLAccountLineItem AssignmentReference
PostingDate I_GLAccountLineItem PostingDate
Ledger I_GLAccountLineItem Ledger
DebitCreditCode I_GLAccountLineItem DebitCreditCode
SalesOrganization I_GLAccountLineItem SalesOrganization
DistributionChannel I_GLAccountLineItem DistributionChannel
OrganizationDivision I_GLAccountLineItem OrganizationDivision
PartnerProfitCenter I_GLAccountLineItem PartnerProfitCenter
FinancialAccountType I_GLAccountLineItem FinancialAccountType
AccountingDocumentType I_GLAccountLineItem AccountingDocumentType
DocumentDate I_GLAccountLineItem DocumentDate
AccountingDocCreatedByUser I_GLAccountLineItem AccountingDocCreatedByUser
DocumentItemText I_GLAccountLineItem DocumentItemText
ClearingDate I_GLAccountLineItem ClearingDate
ClearingJournalEntry I_GLAccountLineItem ClearingJournalEntry
AlternativeReferenceDocument _AccountingDocument AlternativeReferenceDocument
AccountingDocumentHeaderText _AccountingDocument AccountingDocumentHeaderText
CompanyCodeCurrency I_GLAccountLineItem CompanyCodeCurrency
GlobalCurrency I_GLAccountLineItem GlobalCurrency
FreeDefinedCurrency1 I_GLAccountLineItem FreeDefinedCurrency1
FreeDefinedCurrency2 I_GLAccountLineItem FreeDefinedCurrency2
FreeDefinedCurrency3 I_GLAccountLineItem FreeDefinedCurrency3
FreeDefinedCurrency4 I_GLAccountLineItem FreeDefinedCurrency4
FreeDefinedCurrency5 I_GLAccountLineItem FreeDefinedCurrency5
FreeDefinedCurrency6 I_GLAccountLineItem FreeDefinedCurrency6
FreeDefinedCurrency7 I_GLAccountLineItem FreeDefinedCurrency7
FreeDefinedCurrency8 I_GLAccountLineItem FreeDefinedCurrency8
TransactionCurrency I_GLAccountLineItem TransactionCurrency
AmountInTransactionCurrency I_GLAccountLineItem AmountInTransactionCurrency
DebitAmountInTransCrcy I_GLAccountLineItem DebitAmountInTransCrcy
CreditAmountInTransCrcy I_GLAccountLineItem CreditAmountInTransCrcy
AmountInCompanyCodeCurrency I_GLAccountLineItem AmountInCompanyCodeCurrency
AmountInGlobalCurrency I_GLAccountLineItem AmountInGlobalCurrency
AmountInFreeDefinedCurrency1 I_GLAccountLineItem AmountInFreeDefinedCurrency1
AmountInFreeDefinedCurrency2 I_GLAccountLineItem AmountInFreeDefinedCurrency2
AmountInFreeDefinedCurrency3 I_GLAccountLineItem AmountInFreeDefinedCurrency3
AmountInFreeDefinedCurrency4 I_GLAccountLineItem AmountInFreeDefinedCurrency4
AmountInFreeDefinedCurrency5 I_GLAccountLineItem AmountInFreeDefinedCurrency5
AmountInFreeDefinedCurrency6 I_GLAccountLineItem AmountInFreeDefinedCurrency6
AmountInFreeDefinedCurrency7 I_GLAccountLineItem AmountInFreeDefinedCurrency7
AmountInFreeDefinedCurrency8 I_GLAccountLineItem AmountInFreeDefinedCurrency8
DebitAmountInCoCodeCrcy I_GLAccountLineItem DebitAmountInCoCodeCrcy
DebitAmountInGlobalCrcy I_GLAccountLineItem DebitAmountInGlobalCrcy
DebitAmountInFreeDefinedCrcy1 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy1
DebitAmountInFreeDefinedCrcy2 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy2
DebitAmountInFreeDefinedCrcy3 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy3
DebitAmountInFreeDefinedCrcy4 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy4
DebitAmountInFreeDefinedCrcy5 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy5
DebitAmountInFreeDefinedCrcy6 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy6
DebitAmountInFreeDefinedCrcy7 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy7
DebitAmountInFreeDefinedCrcy8 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy8
CreditAmountInCoCodeCrcy I_GLAccountLineItem CreditAmountInCoCodeCrcy
CreditAmountInGlobalCrcy I_GLAccountLineItem CreditAmountInGlobalCrcy
CreditAmountInFreeDefinedCrcy1 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy1
CreditAmountInFreeDefinedCrcy2 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy2
CreditAmountInFreeDefinedCrcy3 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy3
CreditAmountInFreeDefinedCrcy4 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy4
CreditAmountInFreeDefinedCrcy5 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy5
CreditAmountInFreeDefinedCrcy6 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy6
CreditAmountInFreeDefinedCrcy7 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy7
CompanyCode
KEY FiscalYear
KEY AccountingDocument I_GLAccountLineItem AccountingDocument
KEY LedgerGLLineItem I_GLAccountLineItem LedgerGLLineItem
FiscalPeriod
GLAccount I_GLAccountLineItem GLAccount
AlternativeGLAccount _GLAccountInCompanyCode AlternativeGLAccount
Supplier I_GLAccountLineItem Supplier
Customer I_GLAccountLineItem Customer
SpecialGLCode I_GLAccountLineItem SpecialGLCode
ProfitCenter I_GLAccountLineItem ProfitCenter
Segment I_GLAccountLineItem Segment
BusinessArea I_GLAccountLineItem BusinessArea
AssignmentReference I_GLAccountLineItem AssignmentReference
PostingDate I_GLAccountLineItem PostingDate
Ledger I_GLAccountLineItem Ledger
DebitCreditCode I_GLAccountLineItem DebitCreditCode
SalesOrganization I_GLAccountLineItem SalesOrganization
DistributionChannel I_GLAccountLineItem DistributionChannel
OrganizationDivision I_GLAccountLineItem OrganizationDivision
PartnerProfitCenter I_GLAccountLineItem PartnerProfitCenter
FinancialAccountType I_GLAccountLineItem FinancialAccountType
AccountingDocumentType I_GLAccountLineItem AccountingDocumentType
DocumentDate I_GLAccountLineItem DocumentDate
AccountingDocCreatedByUser I_GLAccountLineItem AccountingDocCreatedByUser
DocumentItemText I_GLAccountLineItem DocumentItemText
ClearingDate I_GLAccountLineItem ClearingDate
ClearingJournalEntry I_GLAccountLineItem ClearingJournalEntry
AlternativeReferenceDocument _AccountingDocument AlternativeReferenceDocument
AccountingDocumentHeaderText _AccountingDocument AccountingDocumentHeaderText
CompanyCodeCurrency I_GLAccountLineItem CompanyCodeCurrency
GlobalCurrency I_GLAccountLineItem GlobalCurrency
FreeDefinedCurrency1 I_GLAccountLineItem FreeDefinedCurrency1
FreeDefinedCurrency2 I_GLAccountLineItem FreeDefinedCurrency2
FreeDefinedCurrency3 I_GLAccountLineItem FreeDefinedCurrency3
FreeDefinedCurrency4 I_GLAccountLineItem FreeDefinedCurrency4
FreeDefinedCurrency5 I_GLAccountLineItem FreeDefinedCurrency5
FreeDefinedCurrency6 I_GLAccountLineItem FreeDefinedCurrency6
FreeDefinedCurrency7 I_GLAccountLineItem FreeDefinedCurrency7
FreeDefinedCurrency8 I_GLAccountLineItem FreeDefinedCurrency8
TransactionCurrency I_GLAccountLineItem TransactionCurrency
AmountInTransactionCurrency I_GLAccountLineItem AmountInTransactionCurrency
DebitAmountInTransCrcy I_GLAccountLineItem DebitAmountInTransCrcy
CreditAmountInTransCrcy I_GLAccountLineItem CreditAmountInTransCrcy
AmountInCompanyCodeCurrency I_GLAccountLineItem AmountInCompanyCodeCurrency
AmountInGlobalCurrency I_GLAccountLineItem AmountInGlobalCurrency
AmountInFreeDefinedCurrency1 I_GLAccountLineItem AmountInFreeDefinedCurrency1
AmountInFreeDefinedCurrency2 I_GLAccountLineItem AmountInFreeDefinedCurrency2
AmountInFreeDefinedCurrency3 I_GLAccountLineItem AmountInFreeDefinedCurrency3
AmountInFreeDefinedCurrency4 I_GLAccountLineItem AmountInFreeDefinedCurrency4
AmountInFreeDefinedCurrency5 I_GLAccountLineItem AmountInFreeDefinedCurrency5
AmountInFreeDefinedCurrency6 I_GLAccountLineItem AmountInFreeDefinedCurrency6
AmountInFreeDefinedCurrency7 I_GLAccountLineItem AmountInFreeDefinedCurrency7
AmountInFreeDefinedCurrency8 I_GLAccountLineItem AmountInFreeDefinedCurrency8
DebitAmountInCoCodeCrcy I_GLAccountLineItem DebitAmountInCoCodeCrcy
DebitAmountInGlobalCrcy I_GLAccountLineItem DebitAmountInGlobalCrcy
DebitAmountInFreeDefinedCrcy1 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy1
DebitAmountInFreeDefinedCrcy2 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy2
DebitAmountInFreeDefinedCrcy3 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy3
DebitAmountInFreeDefinedCrcy4 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy4
DebitAmountInFreeDefinedCrcy5 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy5
DebitAmountInFreeDefinedCrcy6 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy6
DebitAmountInFreeDefinedCrcy7 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy7
DebitAmountInFreeDefinedCrcy8 I_GLAccountLineItem DebitAmountInFreeDefinedCrcy8
CreditAmountInCoCodeCrcy I_GLAccountLineItem CreditAmountInCoCodeCrcy
CreditAmountInGlobalCrcy I_GLAccountLineItem CreditAmountInGlobalCrcy
CreditAmountInFreeDefinedCrcy1 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy1
CreditAmountInFreeDefinedCrcy2 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy2
CreditAmountInFreeDefinedCrcy3 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy3
CreditAmountInFreeDefinedCrcy4 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy4
CreditAmountInFreeDefinedCrcy5 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy5
CreditAmountInFreeDefinedCrcy6 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy6
CreditAmountInFreeDefinedCrcy7 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy7
CreditAmountInFreeDefinedCrcy8 I_GLAccountLineItem CreditAmountInFreeDefinedCrcy8
@AbapCatalog.sqlViewName: 'PGLACCTLINEITEME'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #NOT_REQUIRED

@VDM.private:true
@VDM.viewType: #COMPOSITE
@ClientHandling.algorithm: #SESSION_VARIABLE
define view P_GLAcctLineItemEnrcd
  with parameters
    P_CompanyCode : bukrs,
    P_FiscalYear  : gjahr
  //normal line items

  as select from I_GLAccountLineItem as lineitem
    inner join I_Ledger as ledger on lineitem.Ledger = ledger.Ledger
    association [1..1] to I_GLAccountInCompanyCode   as _GLAccountInCompanyCode    on  $projection.CompanyCode        = _GLAccountInCompanyCode.CompanyCode
                                                                                   and $projection.GLAccount          = _GLAccountInCompanyCode.GLAccount
    association [1..1] to I_AccountingDocument       as _AccountingDocument        on  $projection.CompanyCode        = _AccountingDocument.CompanyCode
                                                                                   and $projection.FiscalYear         = _AccountingDocument.FiscalYear
                                                                                   and $projection.AccountingDocument = _AccountingDocument.AccountingDocument
{
  key lineitem.CompanyCode,
  key lineitem.FiscalYear,
  key lineitem.AccountingDocument,
  key lineitem.LedgerGLLineItem,
      lineitem.FiscalPeriod,
      lineitem.GLAccount,
      _GLAccountInCompanyCode.AlternativeGLAccount,
      lineitem.Supplier,
      lineitem.Customer,
      lineitem.SpecialGLCode,
      lineitem.ProfitCenter,
      lineitem.Segment,
      lineitem.BusinessArea,
      lineitem.AssignmentReference,
      lineitem.PostingDate,
      lineitem.Ledger,
      case when
      lineitem.ClearingJournalEntryFiscalYear != '0000'
      then
      '1'
      else
      '2'
      end as IsCleared,  // '1': Cleared item, '2':Open item

      lineitem.DebitCreditCode,
      lineitem.SalesOrganization,
      lineitem.DistributionChannel,
      lineitem.OrganizationDivision,
      lineitem.PartnerProfitCenter,
      lineitem.FinancialAccountType,
      lineitem.AccountingDocumentType,
      lineitem.DocumentDate,
      lineitem.AccountingDocCreatedByUser,
      lineitem.DocumentItemText,
      lineitem.ClearingDate,
      lineitem.ClearingJournalEntry,
      _AccountingDocument.AlternativeReferenceDocument,
      _AccountingDocument.AccountingDocumentHeaderText,
      @Semantics.currencyCode: true
      lineitem.CompanyCodeCurrency,
      @Semantics.currencyCode: true
      lineitem.GlobalCurrency,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency1,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency2,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency3,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency4,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency5,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency6,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency7,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency8,
      @Semantics.currencyCode: true
      lineitem.TransactionCurrency,

      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.AmountInTransactionCurrency,
      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.DebitAmountInTransCrcy,
      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.CreditAmountInTransCrcy,

      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.AmountInCompanyCodeCurrency,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.AmountInGlobalCurrency,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.AmountInFreeDefinedCurrency1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.AmountInFreeDefinedCurrency2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.AmountInFreeDefinedCurrency3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.AmountInFreeDefinedCurrency4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.AmountInFreeDefinedCurrency5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.AmountInFreeDefinedCurrency6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.AmountInFreeDefinedCurrency7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.AmountInFreeDefinedCurrency8,


      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.DebitAmountInCoCodeCrcy,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.DebitAmountInGlobalCrcy,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.DebitAmountInFreeDefinedCrcy1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.DebitAmountInFreeDefinedCrcy2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.DebitAmountInFreeDefinedCrcy3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.DebitAmountInFreeDefinedCrcy4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.DebitAmountInFreeDefinedCrcy5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.DebitAmountInFreeDefinedCrcy6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.DebitAmountInFreeDefinedCrcy7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.DebitAmountInFreeDefinedCrcy8,

      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.CreditAmountInCoCodeCrcy,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.CreditAmountInGlobalCrcy,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.CreditAmountInFreeDefinedCrcy1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.CreditAmountInFreeDefinedCrcy2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.CreditAmountInFreeDefinedCrcy3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.CreditAmountInFreeDefinedCrcy4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.CreditAmountInFreeDefinedCrcy5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.CreditAmountInFreeDefinedCrcy6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.CreditAmountInFreeDefinedCrcy7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.CreditAmountInFreeDefinedCrcy8

}
where ledger.IsLeadingLedger = 'X'
  and lineitem.CompanyCode   = $parameters.P_CompanyCode
  and lineitem.FiscalYear    = $parameters.P_FiscalYear
  and lineitem.FiscalPeriod  > '000'

union all
//carry forward line items

select from I_GLAccountLineItem as lineitem
  inner join I_Ledger                    as ledger     on  lineitem.Ledger         = ledger.Ledger
  inner join I_FiscalYearForCompanyCode  as fiscalyear on  fiscalyear.CompanyCode  = $parameters.P_CompanyCode
                                                       and fiscalyear.FiscalYear   = $parameters.P_FiscalYear
  association [1..1] to I_GLAccountInCompanyCode   as _GLAccountInCompanyCode  on  $projection.CompanyCode        = _GLAccountInCompanyCode.CompanyCode
                                                                               and $projection.GLAccount          = _GLAccountInCompanyCode.GLAccount
  association [1..1] to I_AccountingDocument       as _AccountingDocument      on  $projection.CompanyCode        = _AccountingDocument.CompanyCode
                                                                               and lineitem.FiscalYear            = _AccountingDocument.FiscalYear
                                                                               and $projection.AccountingDocument = _AccountingDocument.AccountingDocument
{
  key lineitem.CompanyCode,
  key $parameters.P_FiscalYear as FiscalYear,
  key lineitem.AccountingDocument,
  key lineitem.LedgerGLLineItem,
      '000' as FiscalPeriod,
      lineitem.GLAccount,
      _GLAccountInCompanyCode.AlternativeGLAccount,
      lineitem.Supplier,
      lineitem.Customer,
      lineitem.SpecialGLCode,
      lineitem.ProfitCenter,
      lineitem.Segment,
      lineitem.BusinessArea,
      lineitem.AssignmentReference,
      lineitem.PostingDate,
      lineitem.Ledger,
      case when
      lineitem.ClearingJournalEntryFiscalYear != '0000'
      then
      '1'
      else
      '2'
      end as IsCleared,  // '1': Cleared item, '2':Open item

      lineitem.DebitCreditCode,
      lineitem.SalesOrganization,
      lineitem.DistributionChannel,
      lineitem.OrganizationDivision,      
      lineitem.PartnerProfitCenter,
      lineitem.FinancialAccountType,
      lineitem.AccountingDocumentType,
      lineitem.DocumentDate,
      lineitem.AccountingDocCreatedByUser,
      lineitem.DocumentItemText,
      lineitem.ClearingDate,
      lineitem.ClearingJournalEntry,
      _AccountingDocument.AlternativeReferenceDocument,
      _AccountingDocument.AccountingDocumentHeaderText,
      @Semantics.currencyCode: true
      lineitem.CompanyCodeCurrency,
      @Semantics.currencyCode: true
      lineitem.GlobalCurrency,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency1,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency2,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency3,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency4,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency5,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency6,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency7,
      @Semantics.currencyCode: true
      lineitem.FreeDefinedCurrency8,
      @Semantics.currencyCode: true
      lineitem.TransactionCurrency,

      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.AmountInTransactionCurrency,
      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.DebitAmountInTransCrcy,
      @Semantics: { amount : {currencyCode: 'TransactionCurrency'} }
      lineitem.CreditAmountInTransCrcy,

      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.AmountInCompanyCodeCurrency,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.AmountInGlobalCurrency,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.AmountInFreeDefinedCurrency1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.AmountInFreeDefinedCurrency2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.AmountInFreeDefinedCurrency3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.AmountInFreeDefinedCurrency4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.AmountInFreeDefinedCurrency5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.AmountInFreeDefinedCurrency6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.AmountInFreeDefinedCurrency7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.AmountInFreeDefinedCurrency8,

      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.DebitAmountInCoCodeCrcy,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.DebitAmountInGlobalCrcy,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.DebitAmountInFreeDefinedCrcy1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.DebitAmountInFreeDefinedCrcy2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.DebitAmountInFreeDefinedCrcy3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.DebitAmountInFreeDefinedCrcy4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.DebitAmountInFreeDefinedCrcy5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.DebitAmountInFreeDefinedCrcy6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.DebitAmountInFreeDefinedCrcy7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.DebitAmountInFreeDefinedCrcy8,

      @Semantics: { amount : {currencyCode: 'CompanyCodeCurrency'} }
      lineitem.CreditAmountInCoCodeCrcy,
      @Semantics: { amount : {currencyCode: 'GlobalCurrency'} }
      lineitem.CreditAmountInGlobalCrcy,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency1'} }
      lineitem.CreditAmountInFreeDefinedCrcy1,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency2'} }
      lineitem.CreditAmountInFreeDefinedCrcy2,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency3'} }
      lineitem.CreditAmountInFreeDefinedCrcy3,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency4'} }
      lineitem.CreditAmountInFreeDefinedCrcy4,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency5'} }
      lineitem.CreditAmountInFreeDefinedCrcy5,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency6'} }
      lineitem.CreditAmountInFreeDefinedCrcy6,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency7'} }
      lineitem.CreditAmountInFreeDefinedCrcy7,
      @Semantics: { amount : {currencyCode: 'FreeDefinedCurrency8'} }
      lineitem.CreditAmountInFreeDefinedCrcy8
}
where  ledger.IsLeadingLedger              =  'X'
  and  lineitem.CompanyCode                = $parameters.P_CompanyCode
  and  lineitem.AccountingDocumentCategory =  ''
  and  fiscalyear.FiscalYearStartDate      >  lineitem.PostingDate
  and(
       fiscalyear.FiscalYearStartDate      <= lineitem.ClearingDate
    or lineitem.ClearingDate               =  '00000000'
    or lineitem.ClearingAccountingDocument =  'ALE-extern'
  )
/*+[internal] {
"BASEINFO":
{
"FROM":
[
"I_ACCOUNTINGDOCUMENT",
"I_FISCALYEARFORCOMPANYCODE",
"I_GLACCOUNTINCOMPANYCODE",
"I_GLACCOUNTLINEITEM",
"I_LEDGER"
],
"ASSOCIATED":
[
"I_ACCOUNTINGDOCUMENT",
"I_GLACCOUNTINCOMPANYCODE"
],
"BASE":
[],
"ANNO_REF":
[],
"SCALAR_FUNCTION":
[],
"VERSION":0,
"ANNOREF_EVALUATION_ERROR":""
}
}*/