Sunday, 2 September 2018

How to check the user which posted GL Journal Batch - Oracle EBS R12

https://generalledger-gl.blogspot.com/2018/09/how-to-check-user-which-posted-gl.html

How to check the user which posted GL Journal Batch. 

Able to extract posted_date from gl_je_headers, but need to find also the user which posted the related journal.

SOLUTION


From GL_JE_HEADERS table, the LAST_UPDATED_BY field is the last person who made some changes.

From GL_JE_BATCHES table, the POSTED_BY field represents the user who posted the journal batch.

----------------------------------------------------------
select b.DOC_SEQUENCE_VALUE, d.user_je_category_name, c.USER_NAME Posted_by --264975
from gl_je_batches a, gl_je_headers b, fnd_user c, gl_je_categories d
where a.JE_BATCH_ID = b.JE_BATCH_ID
and a.POSTED_BY = c.USER_ID(+)
and b.JE_CATEGORY = d.je_category_name
--and d.user_je_category_name = 'Auto Reversal'
--and b.DOC_SEQUENCE_VALUE = 18000160
----------------------------------------------------------

Tuesday, 8 May 2018

Updating the Journal Template Layout Generates Error - NUMBERFORMATEXCEPTION - Oracle EBS R12

https://generalledger-gl.blogspot.com/2018/05/updating-journal-template-layout.html


While trying to update the Web ADI template layout for the General Leger Journal template the following error is received:


Error


The following error has occurred
Exception Name: java.lang.NumberFormatException
Log File Bookmark: 366432

Reference

Updating the Journal Template Layout Generates Error - NUMBERFORMATEXCEPTION (Doc ID 2181278.1)

Wednesday, 22 November 2017

Unable To Create New Legal Entities – ORA-06512: at “CTXSYS.DRVDML” , ORA-06512: at “HR.DR$HR_LOCATIONS_N1TC - Oracle EBS R12

https://generalledger-gl.blogspot.com/2017/11/unable-to-create-new-legal-entities-ora.html

ERROR

Unable To Create New Legal Entities – ORA-06512: at “CTXSYS.DRVDML” , ORA-06512: at “HR.DR$HR_LOCATIONS_N1TC

SOLUTION

Run The Following Query

SELECT TRIGGER_NAME, STATUS
FROM all_triggers
WHERE TABLE_NAME in (‘PER_ADDRESSES’, ‘HR_LOCATIONS_ALL’)
ORDER BY table_name;

If you see triggers with name DR$HR_LOCATIONS_N1TC or DR$PER_ADDRESSES_N4TC please drop these, then see if you can now create the Legal Entity.


Disable Trigger DR$HR_LOCATIONS_N1TC
Disable Trigger DR$PER_ADDRESSES_N4TC


Reference Note: Doc ID 1516486.1

Description for Journal Entry Line not Populated in GL_JE_LINES.REFERENCE10 - Oracle EBS R12

https://generalledger-gl.blogspot.com/2017/11/description-for-journal-entry-line-not.html

ERROR

Description for Journal Entry Line not Populated in GL_JE_LINES.REFERENCE10

SOLUTION

Run Journal Import in detail mode.

Step 1. Go to Responsibility General Ledger Super User

Step 2. Go to Navigation Path : Journal>Import>Run

Step 3. Make sure Create Summary Journals checkbox is blank.

Tuesday, 14 November 2017

FSG Last Used PLSQL Query - Oracle EBS R12

https://generalledger-gl.blogspot.com/2017/11/fsg-last-used.html

Query to Get FSG Last Used in Oracle EBS R12


select max(a.REQUEST_DATE) Last_Request_Date, c.REPORT_TITLE
  from FND_CONCURRENT_PROGRAMS_VL b,
       fnd_concurrent_requests    a,
       RG_REPORTS_V               c,
       fnd_user                   d --67156

 where a.CONCURRENT_PROGRAM_ID = b.CONCURRENT_PROGRAM_ID
     
   and a.PROGRAM_APPLICATION_ID = b.APPLICATION_ID
     
   and c.REPORT_ID = a.ARGUMENT7
     
   and d.USER_ID = a.REQUESTED_BY
     
      --and c.APPLICATION_ID=b.APPLICATION_ID
     
   and b.USER_CONCURRENT_PROGRAM_NAME like '%Program%Publish%FSG%'

 group by c.REPORT_TITLE

--order by a.REQUEST_DATE

Thursday, 19 October 2017

Date Wise Reconciliation of Subledger and GL PLSQL Query - Oracle EBS R12

https://generalledger-gl.blogspot.com/2017/10/date-wise-reconciliation-of-subledger.html

PLSQL Query to Get Date Wise Reconciliation of Subledger and GL 


Subledger

select gcc.SEGMENT4,
     
       --H.JE_CATEGORY,H.JE_SOURCE,
     
       --h.je_header_id, h.name,
     
       L.ACCOUNTING_DATE,
     
       ----------------------------------------
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from xla_ae_headers hh, xla_ae_lines ll, gl_code_combinations gccc --, gl_import_references v
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
              -- and v.GL_SL_LINK_ID = ll.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) < trunc(L.ACCOUNTING_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) OPENING_BALANCE_XLA,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from xla_ae_headers       hh,
               xla_ae_lines         ll,
               gl_code_combinations gccc,
               gl_import_references p
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and p.GL_SL_LINK_ID = ll.GL_SL_LINK_ID
             
              --and p.GL_SL_LINK_ID = v.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) < trunc(L.ACCOUNTING_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) OPENING_BALANCE_IMPORT_REF,
     
       -----------------------------------------------
     
       --L.ENTERED_DR, L.ENTERED_CR, (nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL
     
       SUM(NVL(L.ACCOUNTED_DR, 0)) DATE_DR_XLA,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(NVL(LL.ACCOUNTED_DR, 0))
       
          from xla_ae_headers       hh,
               xla_ae_lines         ll,
               gl_code_combinations gccc,
               gl_import_references q
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and q.GL_SL_LINK_ID = ll.GL_SL_LINK_ID
             
              -- and q.GL_SL_LINK_ID=v.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) = L.ACCOUNTING_DATE
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) DATE_DR_IMPORT_REF,
     
       SUM(NVL(L.ACCOUNTED_CR, 0)) DATE_CR_XLA
     
      ,
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(NVL(LL.ACCOUNTED_CR, 0))
       
          from xla_ae_headers       hh,
               xla_ae_lines         ll,
               gl_code_combinations gccc,
               gl_import_references j
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and j.GL_SL_LINK_ID = ll.GL_SL_LINK_ID
             
              --   and j.GL_SL_LINK_ID=v.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) = L.ACCOUNTING_DATE
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) DATE_CR_IMPORT_REF
     
       /*,SUM(nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL*/
     
      ,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from xla_ae_headers hh, xla_ae_lines ll, gl_code_combinations gccc
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
              --  and k.GL_SL_LINK_ID=v.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) < trunc(L.ACCOUNTING_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) + SUM(NVL(L.ACCOUNTED_DR, 0)) - SUM(NVL(L.ACCOUNTED_CR, 0)) ENDING_BALANCE_XLA
     
      ,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from xla_ae_headers       hh,
               xla_ae_lines         ll,
               gl_code_combinations gccc,
               gl_import_references k
       
         where 1 = 1
             
           and hh.AE_HEADER_ID = LL.AE_HEADER_ID
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and k.GL_SL_LINK_ID = ll.GL_SL_LINK_ID
             
              --  and k.GL_SL_LINK_ID=v.GL_SL_LINK_ID
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.ACCOUNTING_DATE) < trunc(L.ACCOUNTING_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
       
        --  and hh.STATUS = 'P'
       
        --  and ll.STATUS = 'P'
       
        --  and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) + SUM(NVL(L.ACCOUNTED_DR, 0)) - SUM(NVL(L.ACCOUNTED_CR, 0)) ENDING_BALANCE_IMPORT_REF

  from xla_ae_headers       h,
       xla_ae_lines         l,
       gl_code_combinations gcc,
       gl_import_references v

 where 1 = 1
     
   and h.AE_HEADER_ID = l.AE_HEADER_ID
     
   and l.code_combination_id = gcc.code_combination_id
     
   and v.GL_SL_LINK_ID = l.GL_SL_LINK_ID
     
      --and h.default_effective_date<='31-OCT-15'
     
      --and h.period_name='OCT-15'
     
   AND trunc(L.ACCOUNTING_DATE) BETWEEN &FROM_DATE AND &TO_DATE
     
      --and h.je_category='Purchase Invoices'
     
   and gcc.segment4 = &ACCOUNT
     
      --AND H.CURRENCY_CODE='PKR'
     
   AND H.LEDGER_ID = &LEDGER

--and H.STATUS = 'P'

-- and l.STATUS = 'P'

-- and H.Actual_flag = 'A'

--AND H.JE_SOURCE='Payables'

--AND H.JE_CATEGORY='Purchase Invoices'

 GROUP BY L.ACCOUNTING_DATE, gcc.SEGMENT4

--GROUP BY H.JE_CATEGORY,H.JE_SOURCE


 ORDER BY L.ACCOUNTING_DATE

#############################################################################

GL

select gcc.SEGMENT4,
     
       --H.JE_CATEGORY,H.JE_SOURCE,
     
       --h.je_header_id, h.name,
     
       L.EFFECTIVE_DATE,
     
       ----------------------------------------
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from gl_je_headers hh, gl_je_lines ll, gl_code_combinations gccc
       
         where 1 = 1
             
           and hh.je_header_id = LL.je_header_id
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.EFFECTIVE_DATE) < trunc(L.EFFECTIVE_DATE)
             
              /*                    and hh.JE_CATEGORY not in ('1',
                             
                             
                             
              '3',
                             
                             
                             
                             
                             
              'Revaluation',
                             
              '2'
                             
              )*/
             
           and hh.JE_FROM_SLA_FLAG = 'Y'
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
             
           and hh.STATUS = 'P'
             
           and ll.STATUS = 'P'
             
           and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) OPENING_BALANCE,
     
       -----------------------------------------------
     
       --L.ENTERED_DR, L.ENTERED_CR, (nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL
     
       SUM(NVL(L.ACCOUNTED_DR, 0)) DATE_DR,
     
       SUM(NVL(L.ACCOUNTED_CR, 0)) DATE_CR
     
       /*,SUM(nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL*/
     
      ,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0))
       
          from gl_je_headers hh, gl_je_lines ll, gl_code_combinations gccc
       
         where 1 = 1
             
           and hh.je_header_id = LL.je_header_id
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
              /*                     and hh.JE_CATEGORY not in ('1',
                             
                             
                             
              '3',
                             
                             
                             
                             
                             
              'Revaluation',
                             
              '2'
                             
              )
                             
              */
           and hh.JE_FROM_SLA_FLAG = 'Y'
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.EFFECTIVE_DATE) < trunc(L.EFFECTIVE_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
             
           and hh.STATUS = 'P'
             
           and ll.STATUS = 'P'
             
           and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) + SUM(NVL(L.ACCOUNTED_DR, 0)) - SUM(NVL(L.ACCOUNTED_CR, 0)) ENDING_BALANCE

  from gl_je_headers h, gl_je_lines l, gl_code_combinations gcc

 where 1 = 1
     
   and h.je_header_id = l.je_header_id
     
   and l.code_combination_id = gcc.code_combination_id
     
   and h.LEDGER_ID = l.LEDGER_ID
     
      --and h.default_effective_date<='31-OCT-15'
     
      --and h.period_name='OCT-15'
     
   AND trunc(L.EFFECTIVE_DATE) BETWEEN &FROM_DATE AND &TO_DATE
     
      /*            and h.JE_CATEGORY not in ('1',
             
             
             
      '3',
             
             
             
             
             
      'Revaluation',
             
      '2'
             
      )*/
     
   and h.JE_FROM_SLA_FLAG = 'Y'
     
      --and h.je_category='Purchase Invoices'
     
   and gcc.segment4 = &ACCOUNT
     
      --AND H.CURRENCY_CODE='PKR'
     
   AND H.LEDGER_ID = &LEDGER
     
   and H.STATUS = 'P'
     
   and l.STATUS = 'P'
     
   and H.Actual_flag = 'A'

--AND H.JE_SOURCE='Payables'

--AND H.JE_CATEGORY='Purchase Invoices'

 GROUP BY L.EFFECTIVE_DATE, gcc.SEGMENT4

--GROUP BY H.JE_CATEGORY,H.JE_SOURCE

 ORDER BY L.EFFECTIVE_DATE

Wednesday, 18 October 2017

Date wise Trial Balance on Particular Account - Oracle EBS R12

https://generalledger-gl.blogspot.com/2017/10/date-wise-trial-balance-on-particular.html

PLSQL Query to Get Date wise Trial Balance on Particular Account


select gcc.SEGMENT4,
     
       --H.JE_CATEGORY,H.JE_SOURCE,
     
       --h.je_header_id, h.name,
     
       L.EFFECTIVE_DATE,
     
       ----------------------------------------
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         nvl(SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0)), 0)
       
          from gl_je_headers hh, gl_je_lines ll, gl_code_combinations gccc
       
         where 1 = 1
             
           and hh.je_header_id = LL.je_header_id
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.EFFECTIVE_DATE) < trunc(L.EFFECTIVE_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
             
           and hh.STATUS = 'P'
             
           and ll.STATUS = 'P'
             
           and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) OPENING_BALANCE_XLA,
     
       -----------------------------------------------
     
       --L.ENTERED_DR, L.ENTERED_CR, (nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL
     
       SUM(NVL(L.ACCOUNTED_DR, 0)) DATE_DR,
     
       SUM(NVL(L.ACCOUNTED_CR, 0)) DATE_CR
     
       /*,SUM(nvl(L.ENTERED_DR,0) - nvl(L.ENTERED_CR,0)) BAL*/
     
      ,
     
       (select
       
        --hh.JE_CATEGORY,hh.JE_SOURCE,
       
        --hh.je_header_id, hh.name,
       
        --LL.ENTERED_DR, LL.ENTERED_CR, (nvl(LL.ENTERED_DR,0) - nvl(LL.ENTERED_CR,0)) BAL
       
         nvl(SUM(nvl(LL.ACCOUNTED_DR, 0) - nvl(LL.ACCOUNTED_CR, 0)), 0)
       
          from gl_je_headers hh, gl_je_lines ll, gl_code_combinations gccc
       
         where 1 = 1
             
           and hh.je_header_id = LL.je_header_id
             
           and LL.code_combination_id = gccc.code_combination_id
             
           and hh.LEDGER_ID = ll.LEDGER_ID
             
           and gccc.SEGMENT4 = gcc.SEGMENT4
             
              --and hh.default_effective_date<='31-OCT-15'
             
              --and hh.period_name='OCT-15'
             
           AND trunc(LL.EFFECTIVE_DATE) < trunc(L.EFFECTIVE_DATE)
             
              --and hh.je_category='Purchase Invoices'
             
           and gccc.segment4 = &ACCOUNT
             
              --AND hh.CURRENCY_CODE='PKR'
             
           AND hh.LEDGER_ID = &LEDGER
             
           and hh.STATUS = 'P'
             
           and ll.STATUS = 'P'
             
           and hh.Actual_flag = 'A'
       
        --AND hh.JE_SOURCE='Payables'
       
        --AND hh.JE_CATEGORY='Purchase Invoices'
       
        --GROUP BY LL.EFFECTIVE_DATE
       
        --group by ll.EFFECTIVE_DATE
       
        ) + SUM(NVL(L.ACCOUNTED_DR, 0)) - SUM(NVL(L.ACCOUNTED_CR, 0)) ENDING_BALANCE

  from gl_je_headers h, gl_je_lines l, gl_code_combinations gcc

 where 1 = 1
     
   and h.je_header_id = l.je_header_id
     
   and l.code_combination_id = gcc.code_combination_id
     
   and h.LEDGER_ID = l.LEDGER_ID
     
      --and h.default_effective_date<='31-OCT-15'
     
      --and h.period_name='OCT-15'
     
   AND trunc(L.EFFECTIVE_DATE) BETWEEN &FROM_DATE AND &TO_DATE
     
      --and h.je_category='Purchase Invoices'
     
   and gcc.segment4 = &ACCOUNT
     
      --AND H.CURRENCY_CODE='PKR'
     
   AND H.LEDGER_ID = &LEDGER
     
   and H.STATUS = 'P'
     
   and l.STATUS = 'P'
     
   and H.Actual_flag = 'A'

--AND H.JE_SOURCE='Payables'

--AND H.JE_CATEGORY='Purchase Invoices'

 GROUP BY L.EFFECTIVE_DATE, gcc.SEGMENT4

--GROUP BY H.JE_CATEGORY,H.JE_SOURCE

 ORDER BY L.EFFECTIVE_DATE